Bug 1688925 - Move nsHTMLDNSPrefetch to the mozilla::dom namespace. r=smaug,edgar

Differential Revision: https://phabricator.services.mozilla.com/D103060
This commit is contained in:
Emilio Cobos Álvarez 2021-01-27 04:37:58 +00:00
Родитель a77cdd404d
Коммит 20752f9efd
9 изменённых файлов: 64 добавлений и 60 удалений

Просмотреть файл

@ -9,6 +9,7 @@
#include "mozilla/EventStates.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/HTMLDNSPrefetch.h"
#include "mozilla/IHistory.h"
#include "mozilla/StaticPrefs_layout.h"
#include "nsLayoutUtils.h"
@ -18,7 +19,6 @@
#include "nsEscape.h"
#include "nsGkAtoms.h"
#include "nsHTMLDNSPrefetch.h"
#include "nsString.h"
#include "mozAutoDocUpdate.h"
@ -52,7 +52,7 @@ Link::~Link() {
// !mElement is for mock_Link.
MOZ_ASSERT(!mElement || !mElement->IsInComposedDoc());
if (IsInDNSPrefetch()) {
nsHTMLDNSPrefetch::LinkDestroyed(this);
HTMLDNSPrefetch::LinkDestroyed(this);
}
UnregisterFromHistory();
}
@ -65,8 +65,8 @@ bool Link::ElementHasHref() const {
void Link::TryDNSPrefetch() {
MOZ_ASSERT(mElement->IsInComposedDoc());
if (ElementHasHref() && nsHTMLDNSPrefetch::IsAllowed(mElement->OwnerDoc())) {
nsHTMLDNSPrefetch::Prefetch(this, nsHTMLDNSPrefetch::Priority::Low);
if (ElementHasHref() && HTMLDNSPrefetch::IsAllowed(mElement->OwnerDoc())) {
HTMLDNSPrefetch::Prefetch(this, HTMLDNSPrefetch::Priority::Low);
}
}
@ -80,8 +80,8 @@ void Link::CancelDNSPrefetch(nsWrapperCache::FlagsType aDeferredFlag,
mElement->UnsetFlags(aRequestedFlag);
// Possible that hostname could have changed since binding, but since this
// covers common cases, most DNS prefetch requests will be canceled
nsHTMLDNSPrefetch::CancelPrefetch(this, nsHTMLDNSPrefetch::Priority::Low,
NS_ERROR_ABORT);
HTMLDNSPrefetch::CancelPrefetch(this, HTMLDNSPrefetch::Priority::Low,
NS_ERROR_ABORT);
}
}

Просмотреть файл

@ -47,9 +47,9 @@
#include "mozAutoDocUpdate.h"
#include "nsIWebNavigation.h"
#include "nsGenericHTMLElement.h"
#include "nsHTMLDNSPrefetch.h"
#include "nsIObserverService.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/HTMLDNSPrefetch.h"
#include "mozilla/dom/ServiceWorkerDescriptor.h"
#include "mozilla/dom/ScriptLoader.h"
#include "nsParserConstants.h"
@ -799,13 +799,13 @@ void nsContentSink::PrefetchDNS(const nsAString& aHref) {
isHttps = uri->SchemeIs("https");
}
if (!hostname.IsEmpty() && nsHTMLDNSPrefetch::IsAllowed(mDocument)) {
if (!hostname.IsEmpty() && HTMLDNSPrefetch::IsAllowed(mDocument)) {
OriginAttributes oa;
StoragePrincipalHelper::GetOriginAttributesForNetworkState(mDocument, oa);
nsHTMLDNSPrefetch::Prefetch(hostname, isHttps, oa,
mDocument->GetChannel()->GetTRRMode(),
nsHTMLDNSPrefetch::Priority::Low);
HTMLDNSPrefetch::Prefetch(hostname, isHttps, oa,
mDocument->GetChannel()->GetTRRMode(),
HTMLDNSPrefetch::Priority::Low);
}
}

Просмотреть файл

@ -8,13 +8,13 @@
#include "mozilla/dom/BindContext.h"
#include "mozilla/dom/HTMLAnchorElementBinding.h"
#include "mozilla/dom/HTMLDNSPrefetch.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/EventStates.h"
#include "mozilla/MemoryReporting.h"
#include "nsCOMPtr.h"
#include "nsContentUtils.h"
#include "nsGkAtoms.h"
#include "nsHTMLDNSPrefetch.h"
#include "nsAttrValueOrString.h"
#include "mozilla/dom/Document.h"
#include "nsPresContext.h"

Просмотреть файл

@ -4,7 +4,7 @@
* 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 "nsHTMLDNSPrefetch.h"
#include "HTMLDNSPrefetch.h"
#include "base/basictypes.h"
#include "mozilla/dom/Element.h"
@ -38,10 +38,11 @@
#include "mozilla/Preferences.h"
#include "mozilla/StaticPrefs_network.h"
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::net;
namespace mozilla {
namespace dom {
class NoOpDNSListener final : public nsIDNSListener {
// This class exists to give a safe callback no-op DNSListener
public:
@ -107,7 +108,7 @@ static nsIDNSService* sDNSService = nullptr;
static DeferredDNSPrefetches* sPrefetches = nullptr;
static NoOpDNSListener* sDNSListener = nullptr;
nsresult nsHTMLDNSPrefetch::Initialize() {
nsresult HTMLDNSPrefetch::Initialize() {
if (sInitialized) {
NS_WARNING("Initialize() called twice");
return NS_OK;
@ -127,7 +128,7 @@ nsresult nsHTMLDNSPrefetch::Initialize() {
return NS_OK;
}
nsresult nsHTMLDNSPrefetch::Shutdown() {
nsresult HTMLDNSPrefetch::Shutdown() {
if (!sInitialized) {
NS_WARNING("Not Initialized");
return NS_OK;
@ -155,7 +156,7 @@ static bool EnsureDNSService() {
return !!sDNSService;
}
bool nsHTMLDNSPrefetch::IsAllowed(Document* aDocument) {
bool HTMLDNSPrefetch::IsAllowed(Document* aDocument) {
// There is no need to do prefetch on non UI scenarios such as XMLHttpRequest.
return aDocument->IsDNSPrefetchAllowed() && aDocument->GetWindow();
}
@ -170,7 +171,7 @@ static uint32_t GetDNSFlagsFromLink(Link* aElement) {
return nsIDNSService::GetFlagsFromTRRMode(mode);
}
uint32_t nsHTMLDNSPrefetch::PriorityToDNSServiceFlags(Priority aPriority) {
uint32_t HTMLDNSPrefetch::PriorityToDNSServiceFlags(Priority aPriority) {
switch (aPriority) {
case Priority::Low:
return uint32_t(nsIDNSService::RESOLVE_PRIORITY_LOW);
@ -183,7 +184,7 @@ uint32_t nsHTMLDNSPrefetch::PriorityToDNSServiceFlags(Priority aPriority) {
return 0u;
}
nsresult nsHTMLDNSPrefetch::Prefetch(Link* aElement, Priority aPriority) {
nsresult HTMLDNSPrefetch::Prefetch(Link* aElement, Priority aPriority) {
if (!(sInitialized && sPrefetches && sDNSListener) || !EnsureDNSService()) {
return NS_ERROR_NOT_AVAILABLE;
}
@ -192,7 +193,7 @@ nsresult nsHTMLDNSPrefetch::Prefetch(Link* aElement, Priority aPriority) {
aElement);
}
nsresult nsHTMLDNSPrefetch::Prefetch(
nsresult HTMLDNSPrefetch::Prefetch(
const nsAString& hostname, bool isHttps,
const OriginAttributes& aPartitionedPrincipalOriginAttributes,
uint32_t flags) {
@ -235,7 +236,7 @@ nsresult nsHTMLDNSPrefetch::Prefetch(
return NS_OK;
}
nsresult nsHTMLDNSPrefetch::Prefetch(
nsresult HTMLDNSPrefetch::Prefetch(
const nsAString& hostname, bool isHttps,
const OriginAttributes& aPartitionedPrincipalOriginAttributes,
nsIRequest::TRRMode aMode, Priority aPriority) {
@ -244,8 +245,8 @@ nsresult nsHTMLDNSPrefetch::Prefetch(
PriorityToDNSServiceFlags(aPriority));
}
nsresult nsHTMLDNSPrefetch::CancelPrefetch(Link* aElement, Priority aPriority,
nsresult aReason) {
nsresult HTMLDNSPrefetch::CancelPrefetch(Link* aElement, Priority aPriority,
nsresult aReason) {
if (!(sInitialized && sPrefetches && sDNSListener) || !EnsureDNSService()) {
return NS_ERROR_NOT_AVAILABLE;
}
@ -273,7 +274,7 @@ nsresult nsHTMLDNSPrefetch::CancelPrefetch(Link* aElement, Priority aPriority,
return CancelPrefetch(hostname, isHttps, oa, flags, aReason);
}
nsresult nsHTMLDNSPrefetch::CancelPrefetch(
nsresult HTMLDNSPrefetch::CancelPrefetch(
const nsAString& hostname, bool isHttps,
const OriginAttributes& aPartitionedPrincipalOriginAttributes,
uint32_t flags, nsresult aReason) {
@ -314,7 +315,7 @@ nsresult nsHTMLDNSPrefetch::CancelPrefetch(
return rv;
}
nsresult nsHTMLDNSPrefetch::CancelPrefetch(
nsresult HTMLDNSPrefetch::CancelPrefetch(
const nsAString& hostname, bool isHttps,
const OriginAttributes& aPartitionedPrincipalOriginAttributes,
nsIRequest::TRRMode aTRRMode, Priority aPriority, nsresult aReason) {
@ -325,7 +326,7 @@ nsresult nsHTMLDNSPrefetch::CancelPrefetch(
aReason);
}
void nsHTMLDNSPrefetch::LinkDestroyed(Link* aLink) {
void HTMLDNSPrefetch::LinkDestroyed(Link* aLink) {
MOZ_ASSERT(aLink->IsInDNSPrefetch());
if (sPrefetches) {
// Clean up all the possible links at once.
@ -379,7 +380,7 @@ nsresult DeferredDNSPrefetches::Add(uint32_t flags, Link* aElement) {
mTimerArmed = true;
mTimer->InitWithNamedFuncCallback(
Tick, this, 2000, nsITimer::TYPE_ONE_SHOT,
"nsHTMLDNSPrefetch::DeferredDNSPrefetches::Tick");
"HTMLDNSPrefetch::DeferredDNSPrefetches::Tick");
}
return NS_OK;
@ -577,3 +578,6 @@ DeferredDNSPrefetches::Observe(nsISupports* subject, const char* topic,
return NS_OK;
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -4,35 +4,32 @@
* 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 nsHTMLDNSPrefetch_h___
#define nsHTMLDNSPrefetch_h___
#ifndef mozilla_dom_HTMLDNSPrefetch_h___
#define mozilla_dom_HTMLDNSPrefetch_h___
#include "nsCOMPtr.h"
#include "nsIRequest.h"
#include "nsString.h"
#include "nsWeakReference.h"
class nsITimer;
namespace mozilla {
class OriginAttributes;
namespace dom {
class Document;
class Link;
} // namespace dom
namespace net {
class NeckoParent;
} // namespace net
} // namespace mozilla
class nsHTMLDNSPrefetch {
namespace dom {
class Document;
class Link;
class HTMLDNSPrefetch {
public:
// The required aDocument parameter is the context requesting the prefetch -
// under certain circumstances (e.g. headers, or security context) associated
// with the context the prefetch will not be performed.
static bool IsAllowed(mozilla::dom::Document* aDocument);
static bool IsAllowed(Document* aDocument);
static nsresult Initialize();
static nsresult Shutdown();
@ -54,33 +51,35 @@ class nsHTMLDNSPrefetch {
Medium,
High,
};
static nsresult Prefetch(mozilla::dom::Link* aElement, Priority);
static nsresult Prefetch(Link* aElement, Priority);
static nsresult Prefetch(
const nsAString& host, bool isHttps,
const mozilla::OriginAttributes& aPartitionedPrincipalOriginAttributes,
const OriginAttributes& aPartitionedPrincipalOriginAttributes,
nsIRequest::TRRMode aTRRMode, Priority);
static nsresult CancelPrefetch(
const nsAString& host, bool isHttps,
const mozilla::OriginAttributes& aPartitionedPrincipalOriginAttributes,
const OriginAttributes& aPartitionedPrincipalOriginAttributes,
nsIRequest::TRRMode aTRRMode, Priority, nsresult aReason);
static nsresult CancelPrefetch(mozilla::dom::Link* aElement,
Priority, nsresult aReason);
static nsresult CancelPrefetch(Link* aElement, Priority, nsresult aReason);
static void LinkDestroyed(mozilla::dom::Link* aLink);
static void LinkDestroyed(Link* aLink);
private:
static uint32_t PriorityToDNSServiceFlags(Priority);
static nsresult Prefetch(
const nsAString& host, bool isHttps,
const mozilla::OriginAttributes& aPartitionedPrincipalOriginAttributes,
const OriginAttributes& aPartitionedPrincipalOriginAttributes,
uint32_t flags);
static nsresult CancelPrefetch(
const nsAString& hostname, bool isHttps,
const mozilla::OriginAttributes& aPartitionedPrincipalOriginAttributes,
const OriginAttributes& aPartitionedPrincipalOriginAttributes,
uint32_t flags, nsresult aReason);
friend class mozilla::net::NeckoParent;
friend class net::NeckoParent;
};
} // namespace dom
} // namespace mozilla
#endif

Просмотреть файл

@ -13,15 +13,16 @@
#include "mozilla/EventStates.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/Preferences.h"
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/StaticPrefs_network.h"
#include "mozilla/dom/BindContext.h"
#include "mozilla/dom/DocumentInlines.h"
#include "mozilla/dom/HTMLLinkElementBinding.h"
#include "mozilla/dom/HTMLDNSPrefetch.h"
#include "nsContentUtils.h"
#include "nsDOMTokenList.h"
#include "nsGenericHTMLElement.h"
#include "nsGkAtoms.h"
#include "nsHTMLDNSPrefetch.h"
#include "nsIContentInlines.h"
#include "mozilla/dom/Document.h"
#include "nsINode.h"
@ -637,8 +638,8 @@ void HTMLLinkElement::
}
if (linkTypes & eDNS_PREFETCH) {
if (nsHTMLDNSPrefetch::IsAllowed(OwnerDoc())) {
nsHTMLDNSPrefetch::Prefetch(this, nsHTMLDNSPrefetch::Priority::Low);
if (HTMLDNSPrefetch::IsAllowed(OwnerDoc())) {
HTMLDNSPrefetch::Prefetch(this, HTMLDNSPrefetch::Priority::Low);
}
}
}

Просмотреть файл

@ -32,7 +32,6 @@ XPIDL_MODULE = "content_html"
EXPORTS += [
"nsGenericHTMLElement.h",
"nsGenericHTMLFrameElement.h",
"nsHTMLDNSPrefetch.h",
"nsHTMLDocument.h",
"nsIConstraintValidation.h",
"nsIForm.h",
@ -63,6 +62,7 @@ EXPORTS.mozilla.dom += [
"HTMLDetailsElement.h",
"HTMLDialogElement.h",
"HTMLDivElement.h",
"HTMLDNSPrefetch.h",
"HTMLEmbedElement.h",
"HTMLFieldSetElement.h",
"HTMLFontElement.h",
@ -144,6 +144,7 @@ UNIFIED_SOURCES += [
"HTMLDetailsElement.cpp",
"HTMLDialogElement.cpp",
"HTMLDivElement.cpp",
"HTMLDNSPrefetch.cpp",
"HTMLElement.cpp",
"HTMLEmbedElement.cpp",
"HTMLFieldSetElement.cpp",
@ -209,7 +210,6 @@ UNIFIED_SOURCES += [
"nsGenericHTMLElement.cpp",
"nsGenericHTMLFrameElement.cpp",
"nsHTMLContentSink.cpp",
"nsHTMLDNSPrefetch.cpp",
"nsHTMLDocument.cpp",
"nsIConstraintValidation.cpp",
"nsRadioVisitor.cpp",

Просмотреть файл

@ -45,11 +45,11 @@
#include "nsTextFragment.h"
#include "nsMediaFeatures.h"
#include "nsCORSListenerProxy.h"
#include "nsHTMLDNSPrefetch.h"
#include "nsHtml5Module.h"
#include "nsHTMLTags.h"
#include "nsFocusManager.h"
#include "nsListControlFrame.h"
#include "mozilla/dom/HTMLDNSPrefetch.h"
#include "mozilla/dom/HTMLInputElement.h"
#include "mozilla/dom/SVGElementFactory.h"
#include "nsMathMLAtoms.h"
@ -181,7 +181,7 @@ nsresult nsLayoutStatics::Initialize() {
nsCSSRendering::Init();
css::ImageLoader::Init();
rv = nsHTMLDNSPrefetch::Initialize();
rv = HTMLDNSPrefetch::Initialize();
if (NS_FAILED(rv)) {
NS_ERROR("Could not initialize HTML DNS prefetch");
return rv;
@ -319,7 +319,7 @@ void nsLayoutStatics::Shutdown() {
EditorController::Shutdown();
HTMLEditorController::Shutdown();
nsMediaFeatures::Shutdown();
nsHTMLDNSPrefetch::Shutdown();
HTMLDNSPrefetch::Shutdown();
nsCSSRendering::Shutdown();
StaticPresData::Shutdown();
#ifdef DEBUG

Просмотреть файл

@ -44,7 +44,7 @@
#include "mozilla/LoadContext.h"
#include "mozilla/MozPromise.h"
#include "nsPrintfCString.h"
#include "nsHTMLDNSPrefetch.h"
#include "mozilla/dom/HTMLDNSPrefetch.h"
#include "nsEscape.h"
#include "SerializedLoadContext.h"
#include "nsAuthInformationHolder.h"
@ -540,7 +540,7 @@ mozilla::ipc::IPCResult NeckoParent::RecvSpeculativeConnect(
mozilla::ipc::IPCResult NeckoParent::RecvHTMLDNSPrefetch(
const nsString& hostname, const bool& isHttps,
const OriginAttributes& aOriginAttributes, const uint32_t& flags) {
nsHTMLDNSPrefetch::Prefetch(hostname, isHttps, aOriginAttributes, flags);
HTMLDNSPrefetch::Prefetch(hostname, isHttps, aOriginAttributes, flags);
return IPC_OK();
}
@ -548,8 +548,8 @@ mozilla::ipc::IPCResult NeckoParent::RecvCancelHTMLDNSPrefetch(
const nsString& hostname, const bool& isHttps,
const OriginAttributes& aOriginAttributes, const uint32_t& flags,
const nsresult& reason) {
nsHTMLDNSPrefetch::CancelPrefetch(hostname, isHttps, aOriginAttributes, flags,
reason);
HTMLDNSPrefetch::CancelPrefetch(hostname, isHttps, aOriginAttributes, flags,
reason);
return IPC_OK();
}