Commit 2546ba44 authored by fs's avatar fs Committed by Commit bot

Look for favicon URLs (and similar <link>s) in SVG documents

Previously we were only looking for <link>s with icons within <head>,
and since SVG document don't have those, no icons would be found.
Instead, for SVG documents (with a root/document element of <svg>), just
collect all <link> (HTMLLinkElement) elements, regardless of position in
the document, using a pre-order traversal. This appears to match the
behavior of Gecko.

BUG=385466

Review-Url: https://codereview.chromium.org/2628873003
Cr-Commit-Position: refs/heads/master@{#443336}
parent 480d7fbc
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:html="http://www.w3.org/1999/xhtml">
<defs>
<html:link rel="shortcut icon" href="icon1.png"/>
<html:link rel="shortcut icon" href="icon2.png"/>
<html:link rel="shortcut icon" href="icon3.png"/>
</defs>
<text y="20"></text>
<defs>
<html:link rel="shortcut icon" href="icon4.png"/>
<html:link rel="shortcut icon" href="icon5.png"/>
</defs>
<html:link rel="shortcut icon" href="icon6.png"/>
<script>
<![CDATA[
if (window.testRunner)
testRunner.dumpAsText();
let icons = internals.shortcutIconURLs(document);
let passed = icons.length === 6 &&
icons[0].endsWith('icon6.png') &&
icons[1].endsWith('icon5.png') &&
icons[2].endsWith('icon4.png') &&
icons[3].endsWith('icon3.png') &&
icons[4].endsWith('icon2.png') &&
icons[5].endsWith('icon1.png');
let resultNode = document.querySelector('text');
resultNode.textContent = passed ? "PASS" : "FAIL";
]]>
</script>
</svg>
......@@ -5248,12 +5248,22 @@ Vector<IconURL> Document::iconURLs(int iconTypesMask) {
IconURL firstTouchPrecomposedIcon;
Vector<IconURL> secondaryIcons;
// Start from the last child node so that icons seen later take precedence as
using TraversalFunction = HTMLLinkElement* (*)(const Node&);
TraversalFunction findNextCandidate =
&Traversal<HTMLLinkElement>::nextSibling;
HTMLLinkElement* firstElement = nullptr;
if (head()) {
firstElement = Traversal<HTMLLinkElement>::firstChild(*head());
} else if (isSVGDocument() && isSVGSVGElement(documentElement())) {
firstElement = Traversal<HTMLLinkElement>::firstWithin(*documentElement());
findNextCandidate = &Traversal<HTMLLinkElement>::next;
}
// Start from the first child node so that icons seen later take precedence as
// required by the spec.
for (HTMLLinkElement* linkElement =
head() ? Traversal<HTMLLinkElement>::firstChild(*head()) : 0;
linkElement;
linkElement = Traversal<HTMLLinkElement>::nextSibling(*linkElement)) {
for (HTMLLinkElement* linkElement = firstElement; linkElement;
linkElement = findNextCandidate(*linkElement)) {
if (!(linkElement->getIconType() & iconTypesMask))
continue;
if (linkElement->href().isEmpty())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment