Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Unified Diff: third_party/WebKit/Source/core/dom/custom/CustomElementUpgradeSorter.cpp

Issue 2242743002: Make custom elements work in HTML imports (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses tkent's comments. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..808bb32341f405895a89f3db763913a2346ca8e8 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,29 @@ CustomElementUpgradeSorter::CustomElementUpgradeSorter()
{
}
+static HTMLLinkElement* getLinkElementForImport(const Document& import)
+{
+ if (HTMLImportLoader* loader = import.importLoader())
+ return loader->firstImport()->link();
+ return nullptr;
+}
+
+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 =
+ 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 +50,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 = getLinkElementForImport(*toDocument(parent));
+ if (!link || addToParentChildMap(link, parent) == kParentAlreadyExistsInMap)
+ break;
+ parent = link;
}
}
}

Powered by Google App Engine
This is Rietveld 408576698