Skip to content

Commit

Permalink
Look for favicon URLs (and similar <link>s) in SVG documents
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
fs authored and Commit bot committed Jan 12, 2017
1 parent 480d7fb commit 2546ba4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PASS

30 changes: 30 additions & 0 deletions third_party/WebKit/LayoutTests/svg/custom/favicon-link.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 15 additions & 5 deletions third_party/WebKit/Source/core/dom/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 2546ba4

Please sign in to comment.