Index: third_party/WebKit/Source/core/dom/custom/CustomElementUpgradeSorter.cpp |
diff --git a/third_party/WebKit/Source/core/dom/custom/CustomElementUpgradeSorter.cpp b/third_party/WebKit/Source/core/dom/custom/CustomElementUpgradeSorter.cpp |
index 34f9e28e5ea741d3eb6a526ae982debb3d29d0fa..3cc71eec74b54b7f7b248f4da7db9b49dff0bfd2 100644 |
--- a/third_party/WebKit/Source/core/dom/custom/CustomElementUpgradeSorter.cpp |
+++ b/third_party/WebKit/Source/core/dom/custom/CustomElementUpgradeSorter.cpp |
@@ -8,6 +8,9 @@ |
#include "core/dom/ElementTraversal.h" |
#include "core/dom/Node.h" |
#include "core/dom/shadow/ShadowRoot.h" |
+#include "core/html/HTMLLinkElement.h" |
+#include "core/html/imports/HTMLImportChild.h" |
+#include "core/html/imports/HTMLImportLoader.h" |
namespace blink { |
@@ -17,6 +20,31 @@ CustomElementUpgradeSorter::CustomElementUpgradeSorter() |
{ |
} |
+static HTMLLinkElement* getLinkElement(const Document& document) |
tkent
2016/08/24 12:07:20
* Chromium coding style prefers anonymous namespac
kochi
2016/08/24 15:36:52
The static function follows the convention used in
|
+{ |
+ HTMLImportLoader* loader = document.importLoader(); |
tkent
2016/08/24 12:07:20
I prefer shorter code like:
if (HTMLImportLoad
kochi
2016/08/24 15:36:52
Neat. Done.
|
+ if (!loader) |
+ return nullptr; |
+ |
+ return loader->firstImport()->link(); |
+} |
+ |
+CustomElementUpgradeSorter::AddResult CustomElementUpgradeSorter::addToParentChildMap( |
+ Node* parent, |
+ Node* child) |
+{ |
+ ParentChildMap::iterator it = m_parentChildMap->find(parent); |
+ if (it != m_parentChildMap->end()) { |
+ it->value.add(child); |
+ // The entry for the parent exists; so must its parents. |
+ return kParentAlreadyExistsInMap; |
+ } |
+ ParentChildMap::AddResult result = |
tkent
2016/08/24 12:07:20
This function contains two hash lookups and avoida
kochi
2016/08/24 15:36:51
Will do in a separate CL.
|
+ m_parentChildMap->add(parent, HeapHashSet<Member<Node>>()); |
+ result.storedValue->value.add(child); |
+ return kParentAddedToMap; |
+} |
+ |
void CustomElementUpgradeSorter::add(Element* element) |
{ |
m_elements->add(element); |
@@ -24,16 +52,17 @@ void CustomElementUpgradeSorter::add(Element* element) |
for (Node* n = element, *parent = n->parentOrShadowHostNode(); |
parent; |
n = parent, parent = parent->parentOrShadowHostNode()) { |
- |
- ParentChildMap::iterator it = m_parentChildMap->find(parent); |
- if (it == m_parentChildMap->end()) { |
- ParentChildMap::AddResult result = |
- m_parentChildMap->add(parent, HeapHashSet<Member<Node>>()); |
- result.storedValue->value.add(n); |
- } else { |
- it->value.add(n); |
- // The entry for the parent exists; so must its parents. |
+ if (addToParentChildMap(parent, n) == kParentAlreadyExistsInMap) |
break; |
+ |
+ // Create parent-child link between <link rel="import"> and its imported |
+ // document so that the content of the imported document be visited as if |
+ // the imported document were inserted in the link element. |
+ if (parent->isDocumentNode()) { |
+ Element* link = getLinkElement(*toDocument(parent)); |
+ if (!link || addToParentChildMap(link, parent) == kParentAlreadyExistsInMap) |
+ break; |
+ parent = link; |
} |
} |
} |