From 40a355a42d4a9444dc753c04c6608dade2f06a23 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:27 +0200 Subject: Adding upstream version 125.0.1. Signed-off-by: Daniel Baumann --- dom/fetch/FetchDriver.cpp | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'dom/fetch/FetchDriver.cpp') 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 p = do_QueryInterface(chan); - if (p) { + if (nsCOMPtr 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 (, 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 uri; - channel->GetURI(getter_AddRefs(uri)); - if (IsBlobURI(uri)) { - nsBaseChannel* bchan = static_cast(channel.get()); - MOZ_ASSERT(bchan); - Maybe range = bchan->GetContentRange(); - if (range.isSome()) { + nsCOMPtr baseChan = do_QueryInterface(mChannel); + if (baseChan) { + RefPtr 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(channel.get()); - MOZ_ASSERT(dchan); - contentType.Assign(dchan->MimeType()); - } else { + if (baseChan) { + RefPtr fullMimeType(baseChan->FullMimeType()); + if (fullMimeType) { + fullMimeType->Serialize(contentType); + } + } + if (contentType.IsVoid()) { channel->GetContentType(contentType); if (!contentType.IsEmpty()) { nsAutoCString contentCharset; -- cgit v1.2.3