From f65b9265955df5b8e59b5864430c65a52285f72c Mon Sep 17 00:00:00 2001 From: Iulian Moraru Date: Tue, 3 May 2022 23:24:34 +0300 Subject: [PATCH] Backed out 3 changesets (bug 1753730) for causing bc failures on browser_103_preload.js. Backed out changeset 8f27dc8dbbe0 (bug 1753730) Backed out changeset 3c25877d2660 (bug 1753730) Backed out changeset 47787105e3ad (bug 1753730) --- docshell/base/CanonicalBrowsingContext.cpp | 4 - docshell/base/CanonicalBrowsingContext.h | 5 - modules/libpref/init/StaticPrefList.yaml | 6 - netwerk/ipc/DocumentLoadListener.cpp | 26 +- netwerk/ipc/DocumentLoadListener.h | 2 + netwerk/protocol/http/EarlyHintPreloader.cpp | 314 ------------ netwerk/protocol/http/EarlyHintPreloader.h | 96 ---- netwerk/protocol/http/EarlyHintsService.cpp | 46 +- netwerk/protocol/http/EarlyHintsService.h | 17 +- netwerk/protocol/http/moz.build | 2 - netwerk/protocol/http/nsHttpTransaction.cpp | 2 +- netwerk/test/browser/103_preload.html | 28 +- .../103_preload.html^informationalResponse^ | 2 +- ...reload_and_404.html^informationalResponse^ | 2 +- .../browser/103_preload_csp_imgsrc_none.html | 6 - .../103_preload_csp_imgsrc_none.html^headers^ | 2 - ...sp_imgsrc_none.html^informationalResponse^ | 2 - netwerk/test/browser/103_preload_iframe.html | 6 - .../browser/103_preload_iframe.html^headers^ | 1 - netwerk/test/browser/browser.ini | 16 +- netwerk/test/browser/browser_103_preload.js | 480 ------------------ netwerk/test/browser/early_hint_error.sjs | 37 -- netwerk/test/browser/early_hint_main_html.sjs | 62 --- netwerk/test/browser/early_hint_pixel.sjs | 30 -- .../test/browser/early_hint_pixel_count.sjs | 9 - netwerk/test/browser/early_hint_redirect.sjs | 21 - netwerk/test/browser/no_103_preload.html | 28 +- 27 files changed, 69 insertions(+), 1183 deletions(-) delete mode 100644 netwerk/protocol/http/EarlyHintPreloader.cpp delete mode 100644 netwerk/protocol/http/EarlyHintPreloader.h delete mode 100644 netwerk/test/browser/103_preload_csp_imgsrc_none.html delete mode 100644 netwerk/test/browser/103_preload_csp_imgsrc_none.html^headers^ delete mode 100644 netwerk/test/browser/103_preload_csp_imgsrc_none.html^informationalResponse^ delete mode 100644 netwerk/test/browser/103_preload_iframe.html delete mode 100644 netwerk/test/browser/103_preload_iframe.html^headers^ delete mode 100644 netwerk/test/browser/browser_103_preload.js delete mode 100644 netwerk/test/browser/early_hint_error.sjs delete mode 100644 netwerk/test/browser/early_hint_main_html.sjs delete mode 100644 netwerk/test/browser/early_hint_pixel.sjs delete mode 100644 netwerk/test/browser/early_hint_pixel_count.sjs delete mode 100644 netwerk/test/browser/early_hint_redirect.sjs diff --git a/docshell/base/CanonicalBrowsingContext.cpp b/docshell/base/CanonicalBrowsingContext.cpp index 39a680848ef4..2cb7146a5645 100644 --- a/docshell/base/CanonicalBrowsingContext.cpp +++ b/docshell/base/CanonicalBrowsingContext.cpp @@ -1264,10 +1264,6 @@ void CanonicalBrowsingContext::AddFinalDiscardListener( mFullyDiscardedListeners.AppendElement(std::move(aListener)); } -net::EarlyHintsService* CanonicalBrowsingContext::GetEarlyHintsService() { - return &mEarlyHintsService; -} - void CanonicalBrowsingContext::AdjustPrivateBrowsingCount( bool aPrivateBrowsing) { if (IsDiscarded() || !EverAttached() || IsChrome()) { diff --git a/docshell/base/CanonicalBrowsingContext.h b/docshell/base/CanonicalBrowsingContext.h index 3c0c33d63d61..8977e51c249a 100644 --- a/docshell/base/CanonicalBrowsingContext.h +++ b/docshell/base/CanonicalBrowsingContext.h @@ -7,7 +7,6 @@ #ifndef mozilla_dom_CanonicalBrowsingContext_h #define mozilla_dom_CanonicalBrowsingContext_h -#include "mozilla/net/EarlyHintsService.h" #include "mozilla/dom/BrowsingContext.h" #include "mozilla/dom/MediaControlKeySource.h" #include "mozilla/dom/BrowsingContextWebProgress.h" @@ -362,8 +361,6 @@ class CanonicalBrowsingContext final : public BrowsingContext { void AddFinalDiscardListener(std::function&& aListener); - net::EarlyHintsService* GetEarlyHintsService(); - protected: // Called when the browsing context is being discarded. void CanonicalDiscard(); @@ -567,8 +564,6 @@ class CanonicalBrowsingContext final : public BrowsingContext { bool mFullyDiscarded = false; nsTArray> mFullyDiscardedListeners; - - net::EarlyHintsService mEarlyHintsService; }; } // namespace dom diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index 662055b56203..304e7dddb3d0 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -10338,12 +10338,6 @@ value: true mirror: always -# Enable 103 Early Hint status code (RFC 8297) -- name: network.early-hints.enabled - type: RelaxedAtomicBool - value: false - mirror: always - # Whether to use the network process or not # Start a separate socket process. Performing networking on the socket process # is control by a sepparate pref diff --git a/netwerk/ipc/DocumentLoadListener.cpp b/netwerk/ipc/DocumentLoadListener.cpp index 3ab5d3e75e93..1c7301e960b9 100644 --- a/netwerk/ipc/DocumentLoadListener.cpp +++ b/netwerk/ipc/DocumentLoadListener.cpp @@ -1104,9 +1104,7 @@ void DocumentLoadListener::Disconnect(bool aContinueNavigating) { httpChannelImpl->SetEarlyHintObserver(nullptr); } - if (GetLoadingBrowsingContext()) { - GetLoadingBrowsingContext()->mEarlyHintsService.Cancel(); - } + mEarlyHintsService.Cancel(); if (auto* ctx = GetDocumentBrowsingContext()) { ctx->EndDocumentLoad(aContinueNavigating); @@ -2474,15 +2472,12 @@ DocumentLoadListener::OnStartRequest(nsIRequest* aRequest) { } } - if (GetLoadingBrowsingContext()) { - if (httpChannel) { - uint32_t responseStatus; - Unused << httpChannel->GetResponseStatus(&responseStatus); - GetLoadingBrowsingContext()->mEarlyHintsService.FinalResponse( - responseStatus); - } else { - GetLoadingBrowsingContext()->mEarlyHintsService.Cancel(); - } + if (httpChannel) { + uint32_t responseStatus; + Unused << httpChannel->GetResponseStatus(&responseStatus); + mEarlyHintsService.FinalResponse(responseStatus); + } else { + mEarlyHintsService.Cancel(); } // If we're going to be delivering this channel to a remote content @@ -2853,11 +2848,8 @@ NS_IMETHODIMP DocumentLoadListener::OnStatus(nsIRequest* aRequest, NS_IMETHODIMP DocumentLoadListener::EarlyHint(const nsACString& linkHeader) { LOG(("DocumentLoadListener::EarlyHint.\n")); - if (GetLoadingBrowsingContext()) { - nsCOMPtr loadInfo = mChannel->LoadInfo(); - GetLoadingBrowsingContext()->mEarlyHintsService.EarlyHint( - linkHeader, GetChannelCreationURI(), loadInfo); - } + + mEarlyHintsService.EarlyHint(linkHeader); return NS_OK; } diff --git a/netwerk/ipc/DocumentLoadListener.h b/netwerk/ipc/DocumentLoadListener.h index 0a3514d55ae2..32811aa20666 100644 --- a/netwerk/ipc/DocumentLoadListener.h +++ b/netwerk/ipc/DocumentLoadListener.h @@ -619,6 +619,8 @@ class DocumentLoadListener : public nsIInterfaceRequestor, bool mOpenPromiseResolved = false; const bool mIsDocumentLoad; + + EarlyHintsService mEarlyHintsService; }; NS_DEFINE_STATIC_IID_ACCESSOR(DocumentLoadListener, DOCUMENT_LOAD_LISTENER_IID) diff --git a/netwerk/protocol/http/EarlyHintPreloader.cpp b/netwerk/protocol/http/EarlyHintPreloader.cpp deleted file mode 100644 index 11e992bc3742..000000000000 --- a/netwerk/protocol/http/EarlyHintPreloader.cpp +++ /dev/null @@ -1,314 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "EarlyHintPreloader.h" - -#include "EarlyHintsService.h" -#include "ErrorList.h" -#include "mozilla/CORSMode.h" -#include "mozilla/dom/ReferrerInfo.h" -#include "mozilla/Logging.h" -#include "nsAttrValue.h" -#include "nsAttrValueInlines.h" -#include "nsContentUtils.h" -#include "nsDebug.h" -#include "nsIAsyncVerifyRedirectCallback.h" -#include "nsICacheInfoChannel.h" -#include "nsIChannel.h" -#include "nsIHttpChannel.h" -#include "nsIInputStream.h" -#include "nsIReferrerInfo.h" -#include "nsIURI.h" -#include "nsNetUtil.h" -#include "nsStreamUtils.h" - -// -// To enable logging (see mozilla/Logging.h for full details): -// -// set MOZ_LOG=EarlyHint:5 -// set MOZ_LOG_FILE=earlyhint.log -// -// this enables LogLevel::Debug level information and places all output in -// the file earlyhint.log -// -static mozilla::LazyLogModule gEarlyHintLog("EarlyHint"); - -#undef LOG -#define LOG(args) MOZ_LOG(gEarlyHintLog, mozilla::LogLevel::Debug, args) - -#undef LOG_ENABLED -#define LOG_ENABLED() MOZ_LOG_TEST(gEarlyHintLog, mozilla::LogLevel::Debug) - -namespace mozilla::net { - -//============================================================================= -// OngoingEarlyHints -//============================================================================= - -void OngoingEarlyHints::CancelAllOngoingPreloads() { - for (auto& el : mOngoingPreloads) { - el.GetData()->CancelChannel(nsresult::NS_ERROR_ABORT); - } -} - -bool OngoingEarlyHints::Contains(const PreloadHashKey& aKey) { - return mOngoingPreloads.Contains(aKey); -} - -bool OngoingEarlyHints::Add(const PreloadHashKey& aKey, - RefPtr aPreloader) { - return mOngoingPreloads.InsertOrUpdate(aKey, aPreloader); -} - -//============================================================================= -// EarlyHintPreloader -//============================================================================= - -EarlyHintPreloader::EarlyHintPreloader(nsIURI* aURI) : mURI(aURI) {} - -/* static */ -Maybe EarlyHintPreloader::GenerateHashKey( - ASDestination aAs, nsIURI* aURI, nsIPrincipal* aPrincipal) { - if (aAs == ASDestination::DESTINATION_IMAGE) { - return Some( - PreloadHashKey::CreateAsImage(aURI, aPrincipal, CORSMode::CORS_NONE)); - } - return Nothing(); -} - -// static -void EarlyHintPreloader::MaybeCreateAndInsertPreload( - OngoingEarlyHints* aOngoingEarlyHints, const LinkHeader& aHeader, - nsIURI* aBaseURI, nsIPrincipal* aTriggeringPrincipal, - nsICookieJarSettings* aCookieJarSettings) { - if (!aHeader.mRel.LowerCaseEqualsASCII("preload")) { - return; - } - - nsAttrValue as; - ParseAsValue(aHeader.mAs, as); - if (as.GetEnumValue() == ASDestination::DESTINATION_INVALID) { - // return early when it's definitly not an asset type we preload - // would be caught later as well, e.g. when creating the PreloadHashKey - return; - } - - nsCOMPtr uri; - // use the base uri - NS_ENSURE_SUCCESS_VOID( - NS_NewURI(getter_AddRefs(uri), aHeader.mHref, nullptr, aBaseURI)); - - // Only make same origin preloads, the fromPrivateWindow is only read when - // reportError is enabled, so setting both to false is safe. - if (NS_FAILED(nsContentUtils::GetSecurityManager()->CheckSameOriginURI( - aBaseURI, uri, /* reportError */ false, - /* fromPrivateWindow */ false))) { - return; - } - - Maybe hashKey = GenerateHashKey( - static_cast(as.GetEnumValue()), uri, aTriggeringPrincipal); - if (!hashKey) { - return; - } - - if (aOngoingEarlyHints->Contains(*hashKey)) { - return; - } - - nsContentPolicyType contentPolicyType = AsValueToContentPolicy(as); - if (contentPolicyType == nsContentPolicyType::TYPE_INVALID) { - return; - } - - dom::ReferrerPolicy referrerPolicy = - dom::ReferrerInfo::ReferrerPolicyAttributeFromString( - aHeader.mReferrerPolicy); - - nsCOMPtr referrerInfo = - new dom::ReferrerInfo(aBaseURI, referrerPolicy); - - RefPtr earlyHintPreloader = - RefPtr(new EarlyHintPreloader(uri)); - - nsSecurityFlags securityFlags = - nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_INHERITS_SEC_CONTEXT; - - NS_ENSURE_SUCCESS_VOID(earlyHintPreloader->OpenChannel( - aTriggeringPrincipal, securityFlags, contentPolicyType, referrerInfo, - aCookieJarSettings)); - - DebugOnly result = - aOngoingEarlyHints->Add(*hashKey, earlyHintPreloader); - MOZ_ASSERT(result); -} - -nsresult EarlyHintPreloader::OpenChannel( - nsIPrincipal* aTriggeringPrincipal, nsSecurityFlags aSecurityFlags, - nsContentPolicyType aContentPolicyType, nsIReferrerInfo* aReferrerInfo, - nsICookieJarSettings* aCookieJarSettings) { - MOZ_ASSERT(aContentPolicyType == nsContentPolicyType::TYPE_IMAGE); - nsresult rv = - NS_NewChannel(getter_AddRefs(mChannel), mURI, aTriggeringPrincipal, - aSecurityFlags, aContentPolicyType, aCookieJarSettings, - /* aPerformanceStorage */ nullptr, - /* aLoadGroup */ nullptr, - /* aCallbacks */ this, nsIRequest::LOAD_NORMAL); - - NS_ENSURE_SUCCESS(rv, rv); - - // configure HTTP specific stuff - nsCOMPtr httpChannel = do_QueryInterface(mChannel); - if (!httpChannel) { - mChannel = nullptr; - return NS_ERROR_ABORT; - } - DebugOnly success = httpChannel->SetReferrerInfo(aReferrerInfo); - MOZ_ASSERT(NS_SUCCEEDED(success)); - success = httpChannel->SetRequestHeader("X-Moz"_ns, "early hint"_ns, false); - MOZ_ASSERT(NS_SUCCEEDED(success)); - - return mChannel->AsyncOpen(this); -} - -nsresult EarlyHintPreloader::CancelChannel(nsresult aStatus) { - // clear redirect channel in case this channel is cleared between the call of - // EarlyHintPreloader::AsyncOnChannelRedirect and - // EarlyHintPreloader::OnRedirectResult - mRedirectChannel = nullptr; - if (mChannel) { - mChannel->Cancel(aStatus); - mChannel = nullptr; - } - return NS_OK; -} - -//----------------------------------------------------------------------------- -// EarlyHintPreloader::nsISupports -//----------------------------------------------------------------------------- - -NS_IMPL_ISUPPORTS(EarlyHintPreloader, nsIRequestObserver, nsIStreamListener, - nsIChannelEventSink, nsIInterfaceRequestor, - nsIRedirectResultListener) - -//----------------------------------------------------------------------------- -// EarlyHintPreloader::nsIStreamListener -//----------------------------------------------------------------------------- - -NS_IMETHODIMP -EarlyHintPreloader::OnStartRequest(nsIRequest* aRequest) { - LOG(("EarlyHintPreloader::OnStartRequest\n")); - - nsCOMPtr cacheInfoChannel = do_QueryInterface(aRequest); - if (!cacheInfoChannel) { - return NS_ERROR_ABORT; - } - - // no need to prefetch an asset that is already in the cache - bool fromCache; - if (NS_SUCCEEDED(cacheInfoChannel->IsFromCache(&fromCache)) && fromCache) { - LOG(("document is already in the cache; canceling prefetch\n")); - return NS_BINDING_ABORTED; - } - return NS_OK; -} - -NS_IMETHODIMP -EarlyHintPreloader::OnDataAvailable(nsIRequest* aRequest, - nsIInputStream* aStream, uint64_t aOffset, - uint32_t aCount) { - uint32_t bytesRead = 0; - nsresult rv = - aStream->ReadSegments(NS_DiscardSegment, nullptr, aCount, &bytesRead); - LOG(("prefetched %u bytes [offset=%" PRIu64 "]\n", bytesRead, aOffset)); - return rv; -} - -NS_IMETHODIMP -EarlyHintPreloader::OnStopRequest(nsIRequest* aRequest, nsresult aStatus) { - LOG(("EarlyHintPreloader::OnStopRequest\n")); - mChannel = nullptr; - return NS_OK; -} - -//----------------------------------------------------------------------------- -// EarlyHintPreloader::nsIChannelEventSink -//----------------------------------------------------------------------------- - -NS_IMETHODIMP -EarlyHintPreloader::AsyncOnChannelRedirect( - nsIChannel* aOldChannel, nsIChannel* aNewChannel, uint32_t aFlags, - nsIAsyncVerifyRedirectCallback* callback) { - nsCOMPtr newURI; - nsresult rv = NS_GetFinalChannelURI(aNewChannel, getter_AddRefs(newURI)); - NS_ENSURE_SUCCESS(rv, rv); - - rv = aNewChannel->GetURI(getter_AddRefs(newURI)); - if (NS_FAILED(rv)) { - callback->OnRedirectVerifyCallback(rv); - return NS_OK; - } - - // abort the request if redirecting to cross origin resource, the - // fromPrivateWindow is only read when reportError is enabled, so setting both - // to false is safe. - if (NS_FAILED(nsContentUtils::GetSecurityManager()->CheckSameOriginURI( - mURI, newURI, /* reportError */ false, - /* fromPrivateWindow */ false))) { - callback->OnRedirectVerifyCallback(NS_ERROR_ABORT); - return NS_OK; - } - - // HTTP request headers are not automatically forwarded to the new channel. - nsCOMPtr httpChannel = do_QueryInterface(aNewChannel); - NS_ENSURE_STATE(httpChannel); - - rv = httpChannel->SetRequestHeader("X-Moz"_ns, "early hint"_ns, false); - MOZ_ASSERT(NS_SUCCEEDED(rv)); - - // Assign to mChannel after we get notification about success of the - // redirect in OnRedirectResult. - mRedirectChannel = aNewChannel; - - callback->OnRedirectVerifyCallback(NS_OK); - return NS_OK; -} - -//----------------------------------------------------------------------------- -// EarlyHintPreloader::nsIRedirectResultListener -//----------------------------------------------------------------------------- - -NS_IMETHODIMP -EarlyHintPreloader::OnRedirectResult(bool aProceeding) { - if (aProceeding && mRedirectChannel) { - mChannel = mRedirectChannel; - } - - mRedirectChannel = nullptr; - - return NS_OK; -} - -//----------------------------------------------------------------------------- -// EarlyHintPreloader::nsIInterfaceRequestor -//----------------------------------------------------------------------------- - -NS_IMETHODIMP -EarlyHintPreloader::GetInterface(const nsIID& aIID, void** aResult) { - if (aIID.Equals(NS_GET_IID(nsIChannelEventSink))) { - NS_ADDREF_THIS(); - *aResult = static_cast(this); - return NS_OK; - } - - if (aIID.Equals(NS_GET_IID(nsIRedirectResultListener))) { - NS_ADDREF_THIS(); - *aResult = static_cast(this); - return NS_OK; - } - - return NS_ERROR_NO_INTERFACE; -} - -} // namespace mozilla::net diff --git a/netwerk/protocol/http/EarlyHintPreloader.h b/netwerk/protocol/http/EarlyHintPreloader.h deleted file mode 100644 index 301269d21199..000000000000 --- a/netwerk/protocol/http/EarlyHintPreloader.h +++ /dev/null @@ -1,96 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef mozilla_net_EarlyHintPreloader_h -#define mozilla_net_EarlyHintPreloader_h - -#include "mozilla/Maybe.h" -#include "mozilla/PreloadHashKey.h" -#include "nsIChannelEventSink.h" -#include "nsIInterfaceRequestor.h" -#include "nsIRedirectResultListener.h" -#include "nsIStreamListener.h" -#include "nsNetUtil.h" -#include "nsRefPtrHashtable.h" - -class nsAttrValue; -class nsICookieJarSettings; -class nsIPrincipal; -class nsIReferrerInfo; - -namespace mozilla::net { - -class EarlyHintPreloader; -struct LinkHeader; - -// class keeping track of all ongoing early hints -class OngoingEarlyHints final { - public: - NS_INLINE_DECL_REFCOUNTING(OngoingEarlyHints) - MOZ_DECLARE_REFCOUNTED_TYPENAME(OngoingEarlyHints) - - OngoingEarlyHints() = default; - - // returns whether a preload with that key already existed - bool Contains(const PreloadHashKey& aKey); - bool Add(const PreloadHashKey& aKey, RefPtr aPreloader); - - void CancelAllOngoingPreloads(); - - private: - ~OngoingEarlyHints() = default; - nsRefPtrHashtable mOngoingPreloads; -}; - -class EarlyHintPreloader final : public nsIStreamListener, - public nsIChannelEventSink, - public nsIRedirectResultListener, - public nsIInterfaceRequestor { - public: - NS_DECL_ISUPPORTS - NS_DECL_NSIREQUESTOBSERVER - NS_DECL_NSISTREAMLISTENER - NS_DECL_NSICHANNELEVENTSINK - NS_DECL_NSIREDIRECTRESULTLISTENER - NS_DECL_NSIINTERFACEREQUESTOR - - public: - // Create and insert a preload into OngoingEarlyHints if the same preload - // wasn't already issued and the LinkHeader can be parsed correctly. - static void MaybeCreateAndInsertPreload( - OngoingEarlyHints* aOngoingEarlyHints, const LinkHeader& aHeader, - nsIURI* aBaseURI, nsIPrincipal* aTriggeringPrincipal, - nsICookieJarSettings* aCookieJarSettings); - - // Should be called by the preloader service when the preload is not needed - // after all, because the final response returns a non-2xx status code. - nsresult CancelChannel(nsresult aStatus); - - private: - explicit EarlyHintPreloader(nsIURI* aURI); - ~EarlyHintPreloader() = default; - - static Maybe GenerateHashKey(ASDestination aAs, nsIURI* aURI, - nsIPrincipal* aPrincipal); - - // call to start the preload - nsresult OpenChannel(nsIPrincipal* aTriggeringPrincipal, - nsSecurityFlags aSecurityFlags, - nsContentPolicyType aContentPolicyType, - nsIReferrerInfo* aReferrerInfo, - nsICookieJarSettings* aCookieJarSettings); - - // keep opening uri to not preload cross origins on redirects for now - nsCOMPtr mURI; - nsCOMPtr mChannel; - nsCOMPtr mRedirectChannel; -}; - -inline nsISupports* ToSupports(EarlyHintPreloader* aObj) { - return static_cast(aObj); -} - -} // namespace mozilla::net - -#endif // mozilla_net_EarlyHintPreloader_h diff --git a/netwerk/protocol/http/EarlyHintsService.cpp b/netwerk/protocol/http/EarlyHintsService.cpp index 8e1f456c176d..235d76173fd0 100644 --- a/netwerk/protocol/http/EarlyHintsService.cpp +++ b/netwerk/protocol/http/EarlyHintsService.cpp @@ -6,70 +6,26 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "EarlyHintsService.h" -#include "EarlyHintPreloader.h" -#include "mozilla/PreloadHashKey.h" #include "mozilla/Telemetry.h" -#include "nsICookieJarSettings.h" -#include "nsNetUtil.h" -#include "nsString.h" -#include "mozilla/StaticPrefs_network.h" -#include "nsIPrincipal.h" -#include "nsILoadInfo.h" namespace mozilla::net { -EarlyHintsService::EarlyHintsService() - : mOngoingEarlyHints(new OngoingEarlyHints()) {} - -// implementing the destructor in the .cpp file to allow EarlyHintsService.h -// not to include EarlyHintPreloader.h, decoupling the two files and hopefully -// allow faster compile times -EarlyHintsService::~EarlyHintsService() = default; - -void EarlyHintsService::EarlyHint(const nsACString& aLinkHeader, - nsIURI* aBaseURI, nsILoadInfo* aLoadInfo) { +void EarlyHintsService::EarlyHint(const nsACString& linkHeader) { mEarlyHintsCount++; if (!mFirstEarlyHint) { mFirstEarlyHint.emplace(TimeStamp::NowLoRes()); } - - if (!StaticPrefs::network_early_hints_enabled()) { - return; - } - - nsCOMPtr triggeringPrincipal = aLoadInfo->TriggeringPrincipal(); - - nsCOMPtr cookieJarSettings; - if (NS_FAILED( - aLoadInfo->GetCookieJarSettings(getter_AddRefs(cookieJarSettings)))) { - return; - } - - // TODO: find out why LinkHeaderParser uses utf16 and check if it can be - // changed to utf8 - auto linkHeaders = ParseLinkHeader(NS_ConvertUTF8toUTF16(aLinkHeader)); - - for (auto& linkHeader : linkHeaders) { - EarlyHintPreloader::MaybeCreateAndInsertPreload( - mOngoingEarlyHints, linkHeader, aBaseURI, triggeringPrincipal, - cookieJarSettings); - } } void EarlyHintsService::FinalResponse(uint32_t aResponseStatus) { // We will collect telemetry mosly once for a document. // In case of a reddirect this will be called multiple times. CollectTelemetry(Some(aResponseStatus)); - if (aResponseStatus >= 300) { - mOngoingEarlyHints->CancelAllOngoingPreloads(); - mCanceled = true; - } } void EarlyHintsService::Cancel() { if (!mCanceled) { CollectTelemetry(Nothing()); - mOngoingEarlyHints->CancelAllOngoingPreloads(); mCanceled = true; } } diff --git a/netwerk/protocol/http/EarlyHintsService.h b/netwerk/protocol/http/EarlyHintsService.h index e0d9da9dfff5..df1093d1dd66 100644 --- a/netwerk/protocol/http/EarlyHintsService.h +++ b/netwerk/protocol/http/EarlyHintsService.h @@ -8,24 +8,17 @@ #ifndef mozilla_net_EarlyHintsService_h #define mozilla_net_EarlyHintsService_h +#include "nsStringFwd.h" #include "mozilla/Maybe.h" #include "mozilla/TimeStamp.h" -#include "nsStringFwd.h" -#include "mozilla/RefPtr.h" - -class nsILoadInfo; -class nsIURI; namespace mozilla::net { -class OngoingEarlyHints; - class EarlyHintsService { public: - EarlyHintsService(); - ~EarlyHintsService(); - void EarlyHint(const nsACString& aLinkHeader, nsIURI* aBaseURI, - nsILoadInfo* aLoadInfo); + EarlyHintsService() = default; + ~EarlyHintsService() = default; + void EarlyHint(const nsACString& linkHeader); void FinalResponse(uint32_t aResponseStatus); void Cancel(); @@ -35,8 +28,6 @@ class EarlyHintsService { Maybe mFirstEarlyHint; uint32_t mEarlyHintsCount{0}; bool mCanceled{false}; - - RefPtr mOngoingEarlyHints; }; } // namespace mozilla::net diff --git a/netwerk/protocol/http/moz.build b/netwerk/protocol/http/moz.build index 25592b3b39ac..efec3e34d09a 100644 --- a/netwerk/protocol/http/moz.build +++ b/netwerk/protocol/http/moz.build @@ -50,7 +50,6 @@ EXPORTS.mozilla.net += [ "ClassifierDummyChannelChild.h", "ClassifierDummyChannelParent.h", "ClassOfService.h", - "EarlyHintPreloader.h", "EarlyHintsService.h", "HttpAuthUtils.h", "HttpBackgroundChannelChild.h", @@ -102,7 +101,6 @@ UNIFIED_SOURCES += [ "ConnectionEntry.cpp", "ConnectionHandle.cpp", "DnsAndConnectSocket.cpp", - "EarlyHintPreloader.cpp", "EarlyHintsService.cpp", "Http2Compression.cpp", "Http2ConnectTransaction.cpp", diff --git a/netwerk/protocol/http/nsHttpTransaction.cpp b/netwerk/protocol/http/nsHttpTransaction.cpp index 67478142efb0..b913b9e6698b 100644 --- a/netwerk/protocol/http/nsHttpTransaction.cpp +++ b/netwerk/protocol/http/nsHttpTransaction.cpp @@ -1976,7 +1976,7 @@ nsresult nsHttpTransaction::ParseLineSegment(char* segment, uint32_t len) { mResponseHead->Reset(); return NS_OK; } - if (!mConnection->IsProxyConnectInProgress()) { + { MutexAutoLock lock(mLock); mEarlyHintObserver = nullptr; } diff --git a/netwerk/test/browser/103_preload.html b/netwerk/test/browser/103_preload.html index a81fbfa2bb89..13639cc263f7 100644 --- a/netwerk/test/browser/103_preload.html +++ b/netwerk/test/browser/103_preload.html @@ -1,6 +1,26 @@ - - + + - + - diff --git a/netwerk/test/browser/103_preload.html^informationalResponse^ b/netwerk/test/browser/103_preload.html^informationalResponse^ index 3254ef8d8d01..f81602830bbc 100644 --- a/netwerk/test/browser/103_preload.html^informationalResponse^ +++ b/netwerk/test/browser/103_preload.html^informationalResponse^ @@ -1,2 +1,2 @@ HTTP 103 Too Early -Link: ; rel=preload; as=image +Link: ; rel=preload; as=image diff --git a/netwerk/test/browser/103_preload_and_404.html^informationalResponse^ b/netwerk/test/browser/103_preload_and_404.html^informationalResponse^ index 2822f45a7510..51d9ddb8fd64 100644 --- a/netwerk/test/browser/103_preload_and_404.html^informationalResponse^ +++ b/netwerk/test/browser/103_preload_and_404.html^informationalResponse^ @@ -1,2 +1,2 @@ HTTP 103 Early Hints -Link: ; rel=preload; as=image +Link: ; rel=preload; as=image diff --git a/netwerk/test/browser/103_preload_csp_imgsrc_none.html b/netwerk/test/browser/103_preload_csp_imgsrc_none.html deleted file mode 100644 index 377f80f537fd..000000000000 --- a/netwerk/test/browser/103_preload_csp_imgsrc_none.html +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/netwerk/test/browser/103_preload_csp_imgsrc_none.html^headers^ b/netwerk/test/browser/103_preload_csp_imgsrc_none.html^headers^ deleted file mode 100644 index b4dedd081266..000000000000 --- a/netwerk/test/browser/103_preload_csp_imgsrc_none.html^headers^ +++ /dev/null @@ -1,2 +0,0 @@ -Cache-Control: no-cache -Content-Security-Policy: img-src 'none' diff --git a/netwerk/test/browser/103_preload_csp_imgsrc_none.html^informationalResponse^ b/netwerk/test/browser/103_preload_csp_imgsrc_none.html^informationalResponse^ deleted file mode 100644 index eaaec189a9df..000000000000 --- a/netwerk/test/browser/103_preload_csp_imgsrc_none.html^informationalResponse^ +++ /dev/null @@ -1,2 +0,0 @@ -HTTP 103 Too Early -Link: ; rel=preload; as=image diff --git a/netwerk/test/browser/103_preload_iframe.html b/netwerk/test/browser/103_preload_iframe.html deleted file mode 100644 index 815a14220f46..000000000000 --- a/netwerk/test/browser/103_preload_iframe.html +++ /dev/null @@ -1,6 +0,0 @@ - - - -