зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 0927366150b7 (bug 1687538) for failures on link.html. CLOSED TREE
This commit is contained in:
Родитель
fa906b07e7
Коммит
66d2fa9c1e
|
@ -475,11 +475,12 @@ void Link::ResetLinkState(bool aNotify, bool aHasHref) {
|
|||
}
|
||||
}
|
||||
|
||||
// If we have an href, we should register with the history.
|
||||
// If we have an href, and we're not a <link>, we should register with the
|
||||
// history.
|
||||
//
|
||||
// FIXME(emilio): Do we really want to allow all MathML elements to be
|
||||
// :visited? That seems not great.
|
||||
mNeedsRegistration = aHasHref;
|
||||
mNeedsRegistration = aHasHref && !mElement->IsHTMLElement(nsGkAtoms::link);
|
||||
|
||||
// If we've cached the URI, reset always invalidates it.
|
||||
UnregisterFromHistory();
|
||||
|
@ -538,8 +539,11 @@ void Link::SetHrefAttribute(nsIURI* aURI) {
|
|||
size_t Link::SizeOfExcludingThis(mozilla::SizeOfState& aState) const {
|
||||
size_t n = 0;
|
||||
|
||||
if (nsCOMPtr<nsISizeOf> iface = do_QueryInterface(mCachedURI)) {
|
||||
n += iface->SizeOfIncludingThis(aState.mMallocSizeOf);
|
||||
if (mCachedURI) {
|
||||
nsCOMPtr<nsISizeOf> iface = do_QueryInterface(mCachedURI);
|
||||
if (iface) {
|
||||
n += iface->SizeOfIncludingThis(aState.mMallocSizeOf);
|
||||
}
|
||||
}
|
||||
|
||||
// The following members don't need to be measured:
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include "mozilla/dom/Document.h"
|
||||
#include "nsINode.h"
|
||||
#include "nsIPrefetchService.h"
|
||||
#include "nsISizeOf.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsStyleConsts.h"
|
||||
|
@ -48,9 +47,11 @@ namespace mozilla::dom {
|
|||
|
||||
HTMLLinkElement::HTMLLinkElement(
|
||||
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
||||
: nsGenericHTMLElement(std::move(aNodeInfo)) {}
|
||||
: nsGenericHTMLElement(std::move(aNodeInfo)), Link(this) {}
|
||||
|
||||
HTMLLinkElement::~HTMLLinkElement() { SupportsDNSPrefetch::Destroyed(*this); }
|
||||
HTMLLinkElement::~HTMLLinkElement() {
|
||||
SupportsDNSPrefetch::Destroyed(*this);
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLLinkElement)
|
||||
|
||||
|
@ -68,8 +69,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_0(HTMLLinkElement,
|
||||
nsGenericHTMLElement)
|
||||
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(HTMLLinkElement,
|
||||
nsGenericHTMLElement, Link)
|
||||
|
||||
NS_IMPL_ELEMENT_CLONE(HTMLLinkElement)
|
||||
|
||||
|
@ -82,6 +83,8 @@ 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);
|
||||
|
||||
|
@ -114,9 +117,16 @@ void HTMLLinkElement::LinkRemoved() {
|
|||
}
|
||||
|
||||
void HTMLLinkElement::UnbindFromTree(bool aNullParent) {
|
||||
// Cancel any DNS prefetches
|
||||
// Note: Must come before ResetLinkState. If called after, it will recreate
|
||||
// mCachedURI based on data that is invalid - due to a call to GetHostname.
|
||||
CancelDNSPrefetch(*this);
|
||||
CancelPrefetchOrPreload();
|
||||
|
||||
// Without removing the link state we risk a dangling pointer
|
||||
// in the mStyledLinks hashtable
|
||||
Link::ResetLinkState(false, Link::ElementHasHref());
|
||||
|
||||
// If this is reinserted back into the document it will not be
|
||||
// from the parser.
|
||||
Document* oldDoc = GetUncomposedDoc();
|
||||
|
@ -211,28 +221,23 @@ nsresult HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
|||
const nsAttrValue* aOldValue,
|
||||
nsIPrincipal* aSubjectPrincipal,
|
||||
bool aNotify) {
|
||||
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::href) {
|
||||
mCachedURI = nullptr;
|
||||
// It's safe to call ResetLinkState here because our new attr value has
|
||||
// already been set or unset. ResetLinkState needs the updated attribute
|
||||
// value because notifying the document that content states have changed will
|
||||
// call IntrinsicState, which will try to get updated information about the
|
||||
// visitedness from Link.
|
||||
if (aName == nsGkAtoms::href && kNameSpaceID_None == aNameSpaceID) {
|
||||
bool hasHref = aValue;
|
||||
Link::ResetLinkState(!!aNotify, hasHref);
|
||||
if (IsInUncomposedDoc()) {
|
||||
CreateAndDispatchEvent(OwnerDoc(), u"DOMLinkChanged"_ns);
|
||||
}
|
||||
}
|
||||
|
||||
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::href) {
|
||||
mTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal(
|
||||
this, aValue ? aValue->GetStringValue() : EmptyString(),
|
||||
aSubjectPrincipal);
|
||||
|
||||
// If the link has `rel=localization` and its `href` attribute is changed,
|
||||
// update the list of localization links.
|
||||
if (AttrValueIs(kNameSpaceID_None, nsGkAtoms::rel, nsGkAtoms::localization,
|
||||
eIgnoreCase)) {
|
||||
if (Document* doc = GetUncomposedDoc()) {
|
||||
if (aOldValue) {
|
||||
doc->LocalizationLinkRemoved(this);
|
||||
}
|
||||
if (aValue) {
|
||||
doc->LocalizationLinkAdded(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If a link's `rel` attribute was changed from or to `localization`,
|
||||
|
@ -252,6 +257,21 @@ nsresult HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
|||
}
|
||||
}
|
||||
|
||||
// If the link has `rel=localization` and its `href` attribute is changed,
|
||||
// update the list of localization links.
|
||||
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 ||
|
||||
|
@ -310,6 +330,23 @@ 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[] = {
|
||||
// Keep this and the one below in sync with ToLinkMask in
|
||||
// LinkStyle.cpp.
|
||||
|
@ -343,6 +380,10 @@ 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);
|
||||
|
@ -369,14 +410,16 @@ Maybe<LinkStyle::SheetInfo> HTMLLinkElement::GetStyleSheetInfo() {
|
|||
return Nothing();
|
||||
}
|
||||
|
||||
if (!HasNonEmptyAttr(nsGkAtoms::href)) {
|
||||
nsAutoString href;
|
||||
GetAttr(kNameSpaceID_None, nsGkAtoms::href, href);
|
||||
if (href.IsEmpty()) {
|
||||
return Nothing();
|
||||
}
|
||||
|
||||
nsAutoString integrity;
|
||||
GetAttr(nsGkAtoms::integrity, integrity);
|
||||
GetAttr(kNameSpaceID_None, nsGkAtoms::integrity, integrity);
|
||||
|
||||
nsCOMPtr<nsIURI> uri = GetURI();
|
||||
nsCOMPtr<nsIURI> uri = Link::GetURI();
|
||||
nsCOMPtr<nsIPrincipal> prin = mTriggeringPrincipal;
|
||||
|
||||
nsAutoString nonce;
|
||||
|
@ -402,12 +445,14 @@ 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);
|
||||
if (nsCOMPtr<nsISizeOf> iface = do_QueryInterface(mCachedURI)) {
|
||||
*aNodeSize += iface->SizeOfExcludingThis(aSizes.mState.mMallocSizeOf);
|
||||
}
|
||||
*aNodeSize += Link::SizeOfExcludingThis(aSizes.mState);
|
||||
}
|
||||
|
||||
JSObject* HTMLLinkElement::WrapNode(JSContext* aCx,
|
||||
|
@ -504,7 +549,7 @@ void HTMLLinkElement::GetContentPolicyMimeTypeMedia(
|
|||
void HTMLLinkElement::
|
||||
TryDNSPrefetchOrPreconnectOrPrefetchOrPreloadOrPrerender() {
|
||||
MOZ_ASSERT(IsInComposedDoc());
|
||||
if (!HasAttr(nsGkAtoms::href)) {
|
||||
if (!ElementHasHref()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -523,7 +568,8 @@ void HTMLLinkElement::
|
|||
nsCOMPtr<nsIPrefetchService> prefetchService(
|
||||
components::Prefetch::Service());
|
||||
if (prefetchService) {
|
||||
if (nsCOMPtr<nsIURI> uri = GetURI()) {
|
||||
nsCOMPtr<nsIURI> uri(GetURI());
|
||||
if (uri) {
|
||||
auto referrerInfo = MakeRefPtr<ReferrerInfo>(*this);
|
||||
prefetchService->PrefetchURI(uri, referrerInfo, this,
|
||||
linkTypes & ePREFETCH);
|
||||
|
@ -570,7 +616,7 @@ void HTMLLinkElement::UpdatePreload(nsAtom* aName, const nsAttrValue* aValue,
|
|||
const nsAttrValue* aOldValue) {
|
||||
MOZ_ASSERT(IsInComposedDoc());
|
||||
|
||||
if (!HasAttr(nsGkAtoms::href)) {
|
||||
if (!ElementHasHref()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -589,7 +635,7 @@ void HTMLLinkElement::UpdatePreload(nsAtom* aName, const nsAttrValue* aValue,
|
|||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURI> uri = GetURI();
|
||||
nsCOMPtr<nsIURI> uri(GetURI());
|
||||
if (!uri) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -22,8 +22,11 @@ class PreloaderBase;
|
|||
|
||||
namespace dom {
|
||||
|
||||
// NOTE(emilio): If we stop inheriting from Link, we need to remove the
|
||||
// IsHTMLElement(nsGkAtoms::link) checks in Link.cpp.
|
||||
class HTMLLinkElement final : public nsGenericHTMLElement,
|
||||
public LinkStyle,
|
||||
public Link,
|
||||
public SupportsDNSPrefetch {
|
||||
public:
|
||||
explicit HTMLLinkElement(
|
||||
|
@ -42,6 +45,11 @@ class HTMLLinkElement final : public nsGenericHTMLElement,
|
|||
void LinkAdded();
|
||||
void LinkRemoved();
|
||||
|
||||
// EventTarget
|
||||
void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
|
||||
MOZ_CAN_RUN_SCRIPT
|
||||
nsresult PostHandleEvent(EventChainPostVisitor& aVisitor) override;
|
||||
|
||||
// nsINode
|
||||
nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
|
||||
JSObject* WrapNode(JSContext* aCx,
|
||||
|
@ -56,11 +64,16 @@ 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;
|
||||
|
||||
// Element
|
||||
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);
|
||||
|
||||
|
@ -68,13 +81,6 @@ class HTMLLinkElement final : public nsGenericHTMLElement,
|
|||
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);
|
||||
}
|
||||
|
@ -172,7 +178,7 @@ class HTMLLinkElement final : public nsGenericHTMLElement,
|
|||
}
|
||||
|
||||
void NodeInfoChanged(Document* aOldDoc) final {
|
||||
mCachedURI = nullptr;
|
||||
ClearHasPendingLinkUpdate();
|
||||
nsGenericHTMLElement::NodeInfoChanged(aOldDoc);
|
||||
}
|
||||
|
||||
|
@ -212,9 +218,6 @@ class HTMLLinkElement final : public nsGenericHTMLElement,
|
|||
// the preload is held alive by other means.
|
||||
WeakPtr<PreloaderBase> mPreload;
|
||||
|
||||
// The cached href attribute value.
|
||||
nsCOMPtr<nsIURI> mCachedURI;
|
||||
|
||||
// The "explicitly enabled" flag. This flag is set whenever the `disabled`
|
||||
// attribute is explicitly unset, and makes alternate stylesheets not be
|
||||
// disabled by default anymore.
|
||||
|
|
|
@ -15,6 +15,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=372098
|
|||
<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>
|
||||
|
@ -23,6 +24,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=372098
|
|||
<script class="testbody" type="text/javascript">
|
||||
|
||||
var a_passed = false;
|
||||
var link_passed = false;
|
||||
var area_passed = false;
|
||||
|
||||
/* Start the test */
|
||||
|
@ -40,6 +42,7 @@ function handle_load()
|
|||
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();
|
||||
}
|
||||
|
@ -51,6 +54,10 @@ function callback(tag)
|
|||
switch (tag) {
|
||||
case 'a':
|
||||
a_passed = true;
|
||||
sendMouseEvent({type:'click'}, 'link');
|
||||
return;
|
||||
case 'link':
|
||||
link_passed = true;
|
||||
sendMouseEvent({type:'click'}, 'area');
|
||||
return;
|
||||
case 'area':
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<!doctype html>
|
||||
<style>
|
||||
link { display: block; width: 100px; height: 100px; background: currentcolor; }
|
||||
link { color: fuchsia; }
|
||||
</style>
|
||||
<body>
|
||||
<link href="visited-page.html">
|
|
@ -0,0 +1,8 @@
|
|||
<!doctype html>
|
||||
<style>
|
||||
link { display: block; width: 100px; height: 100px; background: currentcolor; }
|
||||
:link { color: fuchsia; }
|
||||
:visited { color: purple; }
|
||||
</style>
|
||||
<body>
|
||||
<link href="visited-page.html">
|
|
@ -47,6 +47,8 @@ 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",
|
||||
|
|
|
@ -95,6 +95,8 @@ var gTests = [
|
|||
"== logical-box-border-color-visited-link-002.html logical-box-border-color-visited-link-ref.html",
|
||||
"== logical-box-border-color-visited-link-003.html logical-box-border-color-visited-link-ref.html",
|
||||
"== svg-paint-currentcolor-visited.svg svg-paint-currentcolor-visited-ref.svg",
|
||||
|
||||
"== color-on-htmllinkelement-1.html color-on-htmllinkelement-1-ref.html",
|
||||
];
|
||||
|
||||
// We record the maximum number of times we had to look at a test before
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
[ParentNode-querySelector-All-xht.xht]
|
||||
[Document.querySelectorAll: :link and :visited pseudo-class selectors, matching no elements: #head :link, #head :visited]
|
||||
expected: FAIL
|
||||
|
||||
[Document.querySelector: :link and :visited pseudo-class selectors, matching no elements: #head :link, #head :visited]
|
||||
expected: FAIL
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
[ParentNode-querySelector-All.html]
|
||||
[Document.querySelectorAll: :link and :visited pseudo-class selectors, matching no elements: #head :link, #head :visited]
|
||||
expected: FAIL
|
||||
|
||||
[Document.querySelector: :link and :visited pseudo-class selectors, matching no elements: #head :link, #head :visited]
|
||||
expected: FAIL
|
||||
|
|
@ -1 +1,15 @@
|
|||
prefs: [browser.send_pings:true]
|
||||
[navigation.sub.html?encoding=windows-1252]
|
||||
[don't follow hyperlink <link href>]
|
||||
expected: FAIL
|
||||
|
||||
|
||||
[navigation.sub.html?encoding=utf8]
|
||||
[don't follow hyperlink <link href>]
|
||||
expected: FAIL
|
||||
|
||||
|
||||
[navigation.sub.html?encoding=x-cp1251]
|
||||
[don't follow hyperlink <link href>]
|
||||
expected: FAIL
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче