From 60297f04a5b6e98de8b80b3d656c03ec5648a8b9 Mon Sep 17 00:00:00 2001 From: Valentin Gosu Date: Sun, 10 Nov 2019 17:12:19 +0000 Subject: [PATCH] Bug 1552176 - pass TRRMode into nsHTMLDNSPrefetch methods r=dragana Differential Revision: https://phabricator.services.mozilla.com/D49159 --HG-- extra : moz-landing-system : lando --- dom/base/nsContentSink.cpp | 3 ++- dom/html/nsHTMLDNSPrefetch.cpp | 48 ++++++++++++++++++++++++---------- dom/html/nsHTMLDNSPrefetch.h | 24 ++++++++++------- netwerk/ipc/NeckoParent.cpp | 4 +-- netwerk/ipc/NeckoParent.h | 4 +-- netwerk/ipc/PNecko.ipdl | 4 +-- 6 files changed, 56 insertions(+), 31 deletions(-) diff --git a/dom/base/nsContentSink.cpp b/dom/base/nsContentSink.cpp index e037d59f9754..3bb7423021bb 100644 --- a/dom/base/nsContentSink.cpp +++ b/dom/base/nsContentSink.cpp @@ -860,7 +860,8 @@ void nsContentSink::PrefetchDNS(const nsAString& aHref) { if (!hostname.IsEmpty() && nsHTMLDNSPrefetch::IsAllowed(mDocument)) { nsHTMLDNSPrefetch::PrefetchLow( - hostname, isHttps, mDocument->NodePrincipal()->OriginAttributesRef()); + hostname, isHttps, mDocument->NodePrincipal()->OriginAttributesRef(), + mDocument->GetChannel()->GetTRRMode()); } } diff --git a/dom/html/nsHTMLDNSPrefetch.cpp b/dom/html/nsHTMLDNSPrefetch.cpp index ef90e7efb25e..0a45efbddb16 100644 --- a/dom/html/nsHTMLDNSPrefetch.cpp +++ b/dom/html/nsHTMLDNSPrefetch.cpp @@ -91,10 +91,21 @@ bool nsHTMLDNSPrefetch::IsAllowed(Document* aDocument) { return aDocument->IsDNSPrefetchAllowed() && aDocument->GetWindow(); } -nsresult nsHTMLDNSPrefetch::Prefetch(Link* aElement, uint16_t flags) { +static uint32_t GetDNSFlagsFromLink(Link* aElement) { + if (!aElement || !aElement->GetElement() || + !aElement->GetElement()->OwnerDoc()->GetChannel()) { + return 0; + } + nsIRequest::TRRMode mode = + aElement->GetElement()->OwnerDoc()->GetChannel()->GetTRRMode(); + return nsIDNSService::GetFlagsFromTRRMode(mode); +} + +nsresult nsHTMLDNSPrefetch::Prefetch(Link* aElement, uint32_t flags) { if (!(sInitialized && sPrefetches && sDNSService && sDNSListener)) return NS_ERROR_NOT_AVAILABLE; + flags |= GetDNSFlagsFromLink(aElement); return sPrefetches->Add(flags, aElement); } @@ -112,7 +123,7 @@ nsresult nsHTMLDNSPrefetch::PrefetchHigh(Link* aElement) { nsresult nsHTMLDNSPrefetch::Prefetch(const nsAString& hostname, bool isHttps, const OriginAttributes& aOriginAttributes, - uint16_t flags) { + uint32_t flags) { if (IsNeckoChild()) { // We need to check IsEmpty() because net_IsValidHostName() // considers empty strings to be valid hostnames @@ -154,25 +165,28 @@ nsresult nsHTMLDNSPrefetch::Prefetch(const nsAString& hostname, bool isHttps, nsresult nsHTMLDNSPrefetch::PrefetchLow( const nsAString& hostname, bool isHttps, - const OriginAttributes& aOriginAttributes) { + const OriginAttributes& aOriginAttributes, nsIRequest::TRRMode aMode) { return Prefetch(hostname, isHttps, aOriginAttributes, - nsIDNSService::RESOLVE_PRIORITY_LOW); + nsIDNSService::GetFlagsFromTRRMode(aMode) | + nsIDNSService::RESOLVE_PRIORITY_LOW); } nsresult nsHTMLDNSPrefetch::PrefetchMedium( const nsAString& hostname, bool isHttps, - const OriginAttributes& aOriginAttributes) { + const OriginAttributes& aOriginAttributes, nsIRequest::TRRMode aMode) { return Prefetch(hostname, isHttps, aOriginAttributes, - nsIDNSService::RESOLVE_PRIORITY_MEDIUM); + nsIDNSService::GetFlagsFromTRRMode(aMode) | + nsIDNSService::RESOLVE_PRIORITY_MEDIUM); } nsresult nsHTMLDNSPrefetch::PrefetchHigh( const nsAString& hostname, bool isHttps, - const OriginAttributes& aOriginAttributes) { - return Prefetch(hostname, isHttps, aOriginAttributes, 0); + const OriginAttributes& aOriginAttributes, nsIRequest::TRRMode aMode) { + return Prefetch(hostname, isHttps, aOriginAttributes, + nsIDNSService::GetFlagsFromTRRMode(aMode)); } -nsresult nsHTMLDNSPrefetch::CancelPrefetch(Link* aElement, uint16_t flags, +nsresult nsHTMLDNSPrefetch::CancelPrefetch(Link* aElement, uint32_t flags, nsresult aReason) { if (!(sInitialized && sPrefetches && sDNSService && sDNSListener)) return NS_ERROR_NOT_AVAILABLE; @@ -196,7 +210,7 @@ nsresult nsHTMLDNSPrefetch::CancelPrefetch(Link* aElement, uint16_t flags, nsresult nsHTMLDNSPrefetch::CancelPrefetch( const nsAString& hostname, bool isHttps, - const OriginAttributes& aOriginAttributes, uint16_t flags, + const OriginAttributes& aOriginAttributes, uint32_t flags, nsresult aReason) { // Forward this request to Necko Parent if we're a child process if (IsNeckoChild()) { @@ -235,14 +249,20 @@ nsresult nsHTMLDNSPrefetch::CancelPrefetch( nsresult nsHTMLDNSPrefetch::CancelPrefetchLow(Link* aElement, nsresult aReason) { - return CancelPrefetch(aElement, nsIDNSService::RESOLVE_PRIORITY_LOW, aReason); + return CancelPrefetch( + aElement, + GetDNSFlagsFromLink(aElement) | nsIDNSService::RESOLVE_PRIORITY_LOW, + aReason); } nsresult nsHTMLDNSPrefetch::CancelPrefetchLow( const nsAString& hostname, bool isHttps, - const OriginAttributes& aOriginAttributes, nsresult aReason) { + const OriginAttributes& aOriginAttributes, nsIRequest::TRRMode aTRRMode, + nsresult aReason) { return CancelPrefetch(hostname, isHttps, aOriginAttributes, - nsIDNSService::RESOLVE_PRIORITY_LOW, aReason); + nsIDNSService::GetFlagsFromTRRMode(aTRRMode) | + nsIDNSService::RESOLVE_PRIORITY_LOW, + aReason); } void nsHTMLDNSPrefetch::LinkDestroyed(Link* aLink) { @@ -301,7 +321,7 @@ void nsHTMLDNSPrefetch::nsDeferrals::Flush() { } } -nsresult nsHTMLDNSPrefetch::nsDeferrals::Add(uint16_t flags, Link* aElement) { +nsresult nsHTMLDNSPrefetch::nsDeferrals::Add(uint32_t flags, Link* aElement) { // The FIFO has no lock, so it can only be accessed on main thread NS_ASSERTION(NS_IsMainThread(), "nsDeferrals::Add must be on main thread"); diff --git a/dom/html/nsHTMLDNSPrefetch.h b/dom/html/nsHTMLDNSPrefetch.h index 42f548046c94..3c20312565b5 100644 --- a/dom/html/nsHTMLDNSPrefetch.h +++ b/dom/html/nsHTMLDNSPrefetch.h @@ -52,16 +52,20 @@ class nsHTMLDNSPrefetch { static nsresult PrefetchLow(mozilla::dom::Link* aElement); static nsresult PrefetchHigh( const nsAString& host, bool isHttps, - const mozilla::OriginAttributes& aOriginAttributes); + const mozilla::OriginAttributes& aOriginAttributes, + nsIRequest::TRRMode aTRRMode); static nsresult PrefetchMedium( const nsAString& host, bool isHttps, - const mozilla::OriginAttributes& aOriginAttributes); + const mozilla::OriginAttributes& aOriginAttributes, + nsIRequest::TRRMode aTRRMode); static nsresult PrefetchLow( const nsAString& host, bool isHttps, - const mozilla::OriginAttributes& aOriginAttributes); + const mozilla::OriginAttributes& aOriginAttributes, + nsIRequest::TRRMode aTRRMode); static nsresult CancelPrefetchLow( const nsAString& host, bool isHttps, - const mozilla::OriginAttributes& aOriginAttributes, nsresult aReason); + const mozilla::OriginAttributes& aOriginAttributes, + nsIRequest::TRRMode aTRRMode, nsresult aReason); static nsresult CancelPrefetchLow(mozilla::dom::Link* aElement, nsresult aReason); @@ -70,13 +74,13 @@ class nsHTMLDNSPrefetch { private: static nsresult Prefetch(const nsAString& host, bool isHttps, const mozilla::OriginAttributes& aOriginAttributes, - uint16_t flags); - static nsresult Prefetch(mozilla::dom::Link* aElement, uint16_t flags); + uint32_t flags); + static nsresult Prefetch(mozilla::dom::Link* aElement, uint32_t flags); static nsresult CancelPrefetch( const nsAString& hostname, bool isHttps, - const mozilla::OriginAttributes& aOriginAttributes, uint16_t flags, + const mozilla::OriginAttributes& aOriginAttributes, uint32_t flags, nsresult aReason); - static nsresult CancelPrefetch(mozilla::dom::Link* aElement, uint16_t flags, + static nsresult CancelPrefetch(mozilla::dom::Link* aElement, uint32_t flags, nsresult aReason); public: @@ -103,7 +107,7 @@ class nsHTMLDNSPrefetch { nsDeferrals(); void Activate(); - nsresult Add(uint16_t flags, mozilla::dom::Link* aElement); + nsresult Add(uint32_t flags, mozilla::dom::Link* aElement); void RemoveUnboundLinks(); @@ -125,7 +129,7 @@ class nsHTMLDNSPrefetch { static const int sMaxDeferredMask = (sMaxDeferred - 1); struct deferred_entry { - uint16_t mFlags; + uint32_t mFlags; // Link implementation clears this raw pointer in its destructor. mozilla::dom::Link* mElement; } mEntries[sMaxDeferred]; diff --git a/netwerk/ipc/NeckoParent.cpp b/netwerk/ipc/NeckoParent.cpp index 82e6be898a8f..64672ede38af 100644 --- a/netwerk/ipc/NeckoParent.cpp +++ b/netwerk/ipc/NeckoParent.cpp @@ -637,14 +637,14 @@ mozilla::ipc::IPCResult NeckoParent::RecvSpeculativeConnect( mozilla::ipc::IPCResult NeckoParent::RecvHTMLDNSPrefetch( const nsString& hostname, const bool& isHttps, - const OriginAttributes& aOriginAttributes, const uint16_t& flags) { + const OriginAttributes& aOriginAttributes, const uint32_t& flags) { nsHTMLDNSPrefetch::Prefetch(hostname, isHttps, aOriginAttributes, flags); return IPC_OK(); } mozilla::ipc::IPCResult NeckoParent::RecvCancelHTMLDNSPrefetch( const nsString& hostname, const bool& isHttps, - const OriginAttributes& aOriginAttributes, const uint16_t& flags, + const OriginAttributes& aOriginAttributes, const uint32_t& flags, const nsresult& reason) { nsHTMLDNSPrefetch::CancelPrefetch(hostname, isHttps, aOriginAttributes, flags, reason); diff --git a/netwerk/ipc/NeckoParent.h b/netwerk/ipc/NeckoParent.h index 497ed517431d..08a66b4a92a1 100644 --- a/netwerk/ipc/NeckoParent.h +++ b/netwerk/ipc/NeckoParent.h @@ -163,10 +163,10 @@ class NeckoParent : public PNeckoParent { const bool& aAnonymous); mozilla::ipc::IPCResult RecvHTMLDNSPrefetch( const nsString& hostname, const bool& isHttps, - const OriginAttributes& aOriginAttributes, const uint16_t& flags); + const OriginAttributes& aOriginAttributes, const uint32_t& flags); mozilla::ipc::IPCResult RecvCancelHTMLDNSPrefetch( const nsString& hostname, const bool& isHttps, - const OriginAttributes& aOriginAttributes, const uint16_t& flags, + const OriginAttributes& aOriginAttributes, const uint32_t& flags, const nsresult& reason); PWebSocketEventListenerParent* AllocPWebSocketEventListenerParent( const uint64_t& aInnerWindowID); diff --git a/netwerk/ipc/PNecko.ipdl b/netwerk/ipc/PNecko.ipdl index d66231b4fd89..83fda76ce981 100644 --- a/netwerk/ipc/PNecko.ipdl +++ b/netwerk/ipc/PNecko.ipdl @@ -104,10 +104,10 @@ parent: async SpeculativeConnect(URIParams uri, nsIPrincipal principal, bool anonymous); async HTMLDNSPrefetch(nsString hostname, bool isHttps, - OriginAttributes originAttributes, uint16_t flags); + OriginAttributes originAttributes, uint32_t flags); async CancelHTMLDNSPrefetch(nsString hostname, bool isHttps, OriginAttributes originAttributes, - uint16_t flags, nsresult reason); + uint32_t flags, nsresult reason); /** * channelId is used to establish a connection between redirect channels in