Skip to content

Commit

Permalink
Bug 1687538 - Make HTMLLinkElement not inherit from Link. r=smaug
Browse files Browse the repository at this point in the history
As per whatwg/html#6269

Differential Revision: https://phabricator.services.mozilla.com/D103088

UltraBlame original commit: 51b5cadd3149b4cdd24206444c92996c80911891
  • Loading branch information
marco-c committed Feb 1, 2021
1 parent fbb1ae6 commit 4109c07
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 156 deletions.
10 changes: 3 additions & 7 deletions dom/base/Link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,7 @@ void Link::ResetLinkState(bool aNotify, bool aHasHref) {




mNeedsRegistration = aHasHref && !mElement->IsHTMLElement(nsGkAtoms::link);
mNeedsRegistration = aHasHref;


UnregisterFromHistory();
Expand Down Expand Up @@ -539,11 +538,8 @@ void Link::SetHrefAttribute(nsIURI* aURI) {
size_t Link::SizeOfExcludingThis(mozilla::SizeOfState& aState) const {
size_t n = 0;

if (mCachedURI) {
nsCOMPtr<nsISizeOf> iface = do_QueryInterface(mCachedURI);
if (iface) {
n += iface->SizeOfIncludingThis(aState.mMallocSizeOf);
}
if (nsCOMPtr<nsISizeOf> iface = do_QueryInterface(mCachedURI)) {
n += iface->SizeOfIncludingThis(aState.mMallocSizeOf);
}


Expand Down
108 changes: 31 additions & 77 deletions dom/html/HTMLLinkElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "mozilla/dom/Document.h"
#include "nsINode.h"
#include "nsIPrefetchService.h"
#include "nsISizeOf.h"
#include "nsPIDOMWindow.h"
#include "nsReadableUtils.h"
#include "nsStyleConsts.h"
Expand All @@ -47,11 +48,9 @@ namespace mozilla::dom {

HTMLLinkElement::HTMLLinkElement(
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
: nsGenericHTMLElement(std::move(aNodeInfo)), Link(this) {}
: nsGenericHTMLElement(std::move(aNodeInfo)) {}

HTMLLinkElement::~HTMLLinkElement() {
SupportsDNSPrefetch::Destroyed(*this);
}
HTMLLinkElement::~HTMLLinkElement() { SupportsDNSPrefetch::Destroyed(*this); }

NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLLinkElement)

Expand All @@ -69,8 +68,8 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLLinkElement,
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSizes)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END

NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(HTMLLinkElement,
nsGenericHTMLElement, Link)
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(HTMLLinkElement,
nsGenericHTMLElement)

NS_IMPL_ELEMENT_CLONE(HTMLLinkElement)

Expand All @@ -83,8 +82,6 @@ void HTMLLinkElement::SetDisabled(bool aDisabled, ErrorResult& aRv) {
}

nsresult HTMLLinkElement::BindToTree(BindContext& aContext, nsINode& aParent) {
Link::ResetLinkState(false, Link::ElementHasHref());

nsresult rv = nsGenericHTMLElement::BindToTree(aContext, aParent);
NS_ENSURE_SUCCESS(rv, rv);

Expand Down Expand Up @@ -117,18 +114,11 @@ void HTMLLinkElement::LinkRemoved() {
}

void HTMLLinkElement::UnbindFromTree(bool aNullParent) {



CancelDNSPrefetch(*this);
CancelPrefetchOrPreload();



Link::ResetLinkState(false, Link::ElementHasHref());



Document* oldDoc = GetUncomposedDoc();
ShadowRoot* oldShadowRoot = GetContainingShadow();

Expand Down Expand Up @@ -221,23 +211,28 @@ nsresult HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) {





if (aName == nsGkAtoms::href && kNameSpaceID_None == aNameSpaceID) {
bool hasHref = aValue;
Link::ResetLinkState(!!aNotify, hasHref);
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::href) {
mCachedURI = nullptr;
if (IsInUncomposedDoc()) {
CreateAndDispatchEvent(OwnerDoc(), u"DOMLinkChanged"_ns);
}
}

if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::href) {
mTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal(
this, aValue ? aValue->GetStringValue() : EmptyString(),
aSubjectPrincipal);



if (AttrValueIs(kNameSpaceID_None, nsGkAtoms::rel, nsGkAtoms::localization,
eIgnoreCase)) {
if (Document* doc = GetUncomposedDoc()) {
if (aOldValue) {
doc->LocalizationLinkRemoved(this);
}
if (aValue) {
doc->LocalizationLinkAdded(this);
}
}
}
}


Expand All @@ -257,21 +252,6 @@ nsresult HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
}
}



if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::href &&
AttrValueIs(kNameSpaceID_None, nsGkAtoms::rel, nsGkAtoms::localization,
eIgnoreCase)) {
if (Document* doc = GetUncomposedDoc()) {
if (aOldValue) {
doc->LocalizationLinkRemoved(this);
}
if (aValue) {
doc->LocalizationLinkAdded(this);
}
}
}

if (aValue) {
if (aNameSpaceID == kNameSpaceID_None &&
(aName == nsGkAtoms::href || aName == nsGkAtoms::rel ||
Expand Down Expand Up @@ -330,23 +310,6 @@ nsresult HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
aNameSpaceID, aName, aValue, aOldValue, aSubjectPrincipal, aNotify);
}

void HTMLLinkElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
GetEventTargetParentForAnchors(aVisitor);
}

nsresult HTMLLinkElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
return PostHandleEventForAnchors(aVisitor);
}

bool HTMLLinkElement::IsLink(nsIURI** aURI) const { return IsHTMLLink(aURI); }

void HTMLLinkElement::GetLinkTarget(nsAString& aTarget) {
GetAttr(kNameSpaceID_None, nsGkAtoms::target, aTarget);
if (aTarget.IsEmpty()) {
GetBaseTarget(aTarget);
}
}

static const DOMTokenListSupportedToken sSupportedRelValues[] = {


Expand Down Expand Up @@ -380,10 +343,6 @@ nsDOMTokenList* HTMLLinkElement::RelList() {
return mRelList;
}

already_AddRefed<nsIURI> HTMLLinkElement::GetHrefURI() const {
return GetHrefURIForAnchors();
}

Maybe<LinkStyle::SheetInfo> HTMLLinkElement::GetStyleSheetInfo() {
nsAutoString rel;
GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel);
Expand All @@ -410,16 +369,14 @@ Maybe<LinkStyle::SheetInfo> HTMLLinkElement::GetStyleSheetInfo() {
return Nothing();
}

nsAutoString href;
GetAttr(kNameSpaceID_None, nsGkAtoms::href, href);
if (href.IsEmpty()) {
if (!HasNonEmptyAttr(nsGkAtoms::href)) {
return Nothing();
}

nsAutoString integrity;
GetAttr(kNameSpaceID_None, nsGkAtoms::integrity, integrity);
GetAttr(nsGkAtoms::integrity, integrity);

nsCOMPtr<nsIURI> uri = Link::GetURI();
nsCOMPtr<nsIURI> uri = GetURI();
nsCOMPtr<nsIPrincipal> prin = mTriggeringPrincipal;

nsAutoString nonce;
Expand All @@ -445,14 +402,12 @@ Maybe<LinkStyle::SheetInfo> HTMLLinkElement::GetStyleSheetInfo() {
});
}

EventStates HTMLLinkElement::IntrinsicState() const {
return Link::LinkState() | nsGenericHTMLElement::IntrinsicState();
}

void HTMLLinkElement::AddSizeOfExcludingThis(nsWindowSizes& aSizes,
size_t* aNodeSize) const {
nsGenericHTMLElement::AddSizeOfExcludingThis(aSizes, aNodeSize);
*aNodeSize += Link::SizeOfExcludingThis(aSizes.mState);
if (nsCOMPtr<nsISizeOf> iface = do_QueryInterface(mCachedURI)) {
*aNodeSize += iface->SizeOfExcludingThis(aSizes.mState.mMallocSizeOf);
}
}

JSObject* HTMLLinkElement::WrapNode(JSContext* aCx,
Expand Down Expand Up @@ -549,7 +504,7 @@ void HTMLLinkElement::GetContentPolicyMimeTypeMedia(
void HTMLLinkElement::
TryDNSPrefetchOrPreconnectOrPrefetchOrPreloadOrPrerender() {
MOZ_ASSERT(IsInComposedDoc());
if (!ElementHasHref()) {
if (!HasAttr(nsGkAtoms::href)) {
return;
}

Expand All @@ -568,8 +523,7 @@ void HTMLLinkElement::
nsCOMPtr<nsIPrefetchService> prefetchService(
components::Prefetch::Service());
if (prefetchService) {
nsCOMPtr<nsIURI> uri(GetURI());
if (uri) {
if (nsCOMPtr<nsIURI> uri = GetURI()) {
auto referrerInfo = MakeRefPtr<ReferrerInfo>(*this);
prefetchService->PrefetchURI(uri, referrerInfo, this,
linkTypes & ePREFETCH);
Expand Down Expand Up @@ -616,7 +570,7 @@ void HTMLLinkElement::UpdatePreload(nsAtom* aName, const nsAttrValue* aValue,
const nsAttrValue* aOldValue) {
MOZ_ASSERT(IsInComposedDoc());

if (!ElementHasHref()) {
if (!HasAttr(nsGkAtoms::href)) {
return;
}

Expand All @@ -635,7 +589,7 @@ void HTMLLinkElement::UpdatePreload(nsAtom* aName, const nsAttrValue* aValue,
return;
}

nsCOMPtr<nsIURI> uri(GetURI());
nsCOMPtr<nsIURI> uri = GetURI();
if (!uri) {
return;
}
Expand Down
25 changes: 11 additions & 14 deletions dom/html/HTMLLinkElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ class PreloaderBase;

namespace dom {



class HTMLLinkElement final : public nsGenericHTMLElement,
public LinkStyle,
public Link,
public SupportsDNSPrefetch {
public:
explicit HTMLLinkElement(
Expand All @@ -46,11 +43,6 @@ class HTMLLinkElement final : public nsGenericHTMLElement,
void LinkRemoved();


void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
MOZ_CAN_RUN_SCRIPT
nsresult PostHandleEvent(EventChainPostVisitor& aVisitor) override;


nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
JSObject* WrapNode(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
Expand All @@ -64,23 +56,25 @@ class HTMLLinkElement final : public nsGenericHTMLElement,
nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
const nsAttrValue* aValue, const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal, bool aNotify) override;
bool IsLink(nsIURI** aURI) const override;
already_AddRefed<nsIURI> GetHrefURI() const override;


bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
const nsAString& aValue,
nsIPrincipal* aMaybeScriptedPrincipal,
nsAttrValue& aResult) override;
void GetLinkTarget(nsAString& aTarget) override;
EventStates IntrinsicState() const override;

void CreateAndDispatchEvent(Document* aDoc, const nsAString& aEventName);


bool Disabled() const;
void SetDisabled(bool aDisabled, ErrorResult& aRv);

nsIURI* GetURI() {
if (!mCachedURI) {
GetURIAttr(nsGkAtoms::href, nullptr, getter_AddRefs(mCachedURI));
}
return mCachedURI.get();
}

void GetHref(nsAString& aValue) {
GetURIAttr(nsGkAtoms::href, nullptr, aValue);
}
Expand Down Expand Up @@ -178,7 +172,7 @@ class HTMLLinkElement final : public nsGenericHTMLElement,
}

void NodeInfoChanged(Document* aOldDoc) final {
ClearHasPendingLinkUpdate();
mCachedURI = nullptr;
nsGenericHTMLElement::NodeInfoChanged(aOldDoc);
}

Expand Down Expand Up @@ -219,6 +213,9 @@ class HTMLLinkElement final : public nsGenericHTMLElement,
WeakPtr<PreloaderBase> mPreload;


nsCOMPtr<nsIURI> mCachedURI;





Expand Down
7 changes: 0 additions & 7 deletions dom/html/test/test_bug372098.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<div id="content" style="display:none;">
<iframe name="bug372098"></iframe>
<a id="a" href="bug372098-link-target.html?a" target="">link</a>
<link id="link" href="bug372098-link-target.html?link" target=""/>
<map>
<area id="area" shape="default" href="bug372098-link-target.html?area" target=""/>
</map>
Expand All @@ -24,7 +23,6 @@
<script class="testbody" type="text/javascript">

var a_passed = false;
var link_passed = false;
var area_passed = false;

/* Start the test */
Expand All @@ -42,7 +40,6 @@
function finish_test()
{
ok(a_passed, "The 'a' element used the correct target.");
ok(link_passed, "The 'link' element used the correct target.");
ok(area_passed, "The 'area' element used the correct target.");
SimpleTest.finish();
}
Expand All @@ -54,10 +51,6 @@
switch (tag) {
case 'a':
a_passed = true;
sendMouseEvent({type:'click'}, 'link');
return;
case 'link':
link_passed = true;
sendMouseEvent({type:'click'}, 'area');
return;
case 'area':
Expand Down

This file was deleted.

8 changes: 0 additions & 8 deletions layout/reftests/css-visited/color-on-htmllinkelement-1.html

This file was deleted.

2 changes: 0 additions & 2 deletions layout/style/test/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ TEST_HARNESS_FILES.testing.mochitest.tests.layout.style.test["css-visited"] += [
"/layout/reftests/css-visited/color-choice-1.html",
"/layout/reftests/css-visited/color-on-bullets-1-ref.html",
"/layout/reftests/css-visited/color-on-bullets-1.html",
"/layout/reftests/css-visited/color-on-htmllinkelement-1-ref.html",
"/layout/reftests/css-visited/color-on-htmllinkelement-1.html",
"/layout/reftests/css-visited/color-on-link-1-ref.html",
"/layout/reftests/css-visited/color-on-link-1.html",
"/layout/reftests/css-visited/color-on-link-before-1.html",
Expand Down
Loading

0 comments on commit 4109c07

Please sign in to comment.