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

Side by Side Diff: third_party/WebKit/Source/core/dom/custom/CustomElement.cpp

Issue 2132343002: Make Custom Elements V1 work in HTML imports documents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: imports Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/dom/custom/CustomElement.h" 5 #include "core/dom/custom/CustomElement.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/dom/QualifiedName.h" 8 #include "core/dom/QualifiedName.h"
9 #include "core/dom/custom/CEReactionsScope.h" 9 #include "core/dom/custom/CEReactionsScope.h"
10 #include "core/dom/custom/CustomElementDefinition.h" 10 #include "core/dom/custom/CustomElementDefinition.h"
11 #include "core/dom/custom/CustomElementReactionStack.h" 11 #include "core/dom/custom/CustomElementReactionStack.h"
12 #include "core/dom/custom/CustomElementsRegistry.h" 12 #include "core/dom/custom/CustomElementsRegistry.h"
13 #include "core/dom/custom/V0CustomElement.h" 13 #include "core/dom/custom/V0CustomElement.h"
14 #include "core/dom/custom/V0CustomElementRegistrationContext.h" 14 #include "core/dom/custom/V0CustomElementRegistrationContext.h"
15 #include "core/frame/FrameHost.h" 15 #include "core/frame/FrameHost.h"
16 #include "core/frame/LocalDOMWindow.h" 16 #include "core/frame/LocalDOMWindow.h"
17 #include "core/html/HTMLElement.h" 17 #include "core/html/HTMLElement.h"
18 #include "platform/text/Character.h" 18 #include "platform/text/Character.h"
19 #include "wtf/text/AtomicStringHash.h" 19 #include "wtf/text/AtomicStringHash.h"
20 20
21 namespace blink { 21 namespace blink {
22 22
23 CustomElementsRegistry* CustomElement::registry(const Element& element) 23 CustomElementsRegistry* CustomElement::registry(const Element& element)
24 { 24 {
25 return registry(element.document()); 25 return registry(element.document());
26 } 26 }
27 27
28 CustomElementsRegistry* CustomElement::registry(const Document& document) 28 CustomElementsRegistry* CustomElement::registry(const Document& document)
29 { 29 {
30 if (LocalDOMWindow* window = document.domWindow()) 30 if (Document* contextDocument = const_cast<Document&>(document).contextDocum ent()) {
dominicc (has gone to gerrit) 2016/07/13 06:12:30 FYI haraken says in Q4 that Blink will be able to
31 return window->customElements(); 31 if (LocalDOMWindow* window = contextDocument->domWindow())
32 return window->customElements();
33 }
32 return nullptr; 34 return nullptr;
33 } 35 }
34 36
37 FrameHost* CustomElement::contextFrameHost(const Element& element)
38 {
39 if (Document* contextDocument = element.document().contextDocument())
40 return contextDocument->frameHost();
41 return nullptr;
42 }
43
35 CustomElementDefinition* CustomElement::definitionForElement(const Element& elem ent) 44 CustomElementDefinition* CustomElement::definitionForElement(const Element& elem ent)
36 { 45 {
37 if (CustomElementsRegistry* registry = CustomElement::registry(element)) 46 if (CustomElementsRegistry* registry = CustomElement::registry(element))
38 return registry->definitionForName(element.localName()); 47 return registry->definitionForName(element.localName());
39 return nullptr; 48 return nullptr;
40 } 49 }
41 50
42 bool CustomElement::isValidName(const AtomicString& name) 51 bool CustomElement::isValidName(const AtomicString& name)
43 { 52 {
44 if (!name.length() || name[0] < 'a' || name[0] > 'z') 53 if (!name.length() || name[0] < 'a' || name[0] > 'z')
(...skipping 26 matching lines...) Expand all
71 hyphenContainingElementNames.add("font-face-name"); 80 hyphenContainingElementNames.add("font-face-name");
72 hyphenContainingElementNames.add("missing-glyph"); 81 hyphenContainingElementNames.add("missing-glyph");
73 } 82 }
74 83
75 return !hyphenContainingElementNames.contains(name); 84 return !hyphenContainingElementNames.contains(name);
76 } 85 }
77 86
78 bool CustomElement::shouldCreateCustomElement(Document& document, const AtomicSt ring& localName) 87 bool CustomElement::shouldCreateCustomElement(Document& document, const AtomicSt ring& localName)
79 { 88 {
80 return RuntimeEnabledFeatures::customElementsV1Enabled() 89 return RuntimeEnabledFeatures::customElementsV1Enabled()
81 && document.frame() && isValidName(localName); 90 && document.contextDocument() && document.contextDocument()->frame()
91 && isValidName(localName);
82 } 92 }
83 93
84 bool CustomElement::shouldCreateCustomElement(Document& document, const Qualifie dName& tagName) 94 bool CustomElement::shouldCreateCustomElement(Document& document, const Qualifie dName& tagName)
85 { 95 {
86 return shouldCreateCustomElement(document, tagName.localName()) 96 return shouldCreateCustomElement(document, tagName.localName())
87 && tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI; 97 && tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI;
88 } 98 }
89 99
90 static CustomElementDefinition* definitionForName(const Document& document, cons t QualifiedName& name) 100 static CustomElementDefinition* definitionForName(const Document& document, cons t QualifiedName& name)
91 { 101 {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 179
170 // If the custom element reactions stack is not empty, then 180 // If the custom element reactions stack is not empty, then
171 // Add element to the current element queue. 181 // Add element to the current element queue.
172 if (CEReactionsScope* current = CEReactionsScope::current()) { 182 if (CEReactionsScope* current = CEReactionsScope::current()) {
173 current->enqueueToCurrentQueue(element, reaction); 183 current->enqueueToCurrentQueue(element, reaction);
174 return; 184 return;
175 } 185 }
176 186
177 // If the custom element reactions stack is empty, then 187 // If the custom element reactions stack is empty, then
178 // Add element to the backup element queue. 188 // Add element to the backup element queue.
179 element->document().frameHost()->customElementReactionStack() 189 contextFrameHost(*element)->customElementReactionStack()
180 .enqueueToBackupQueue(element, reaction); 190 .enqueueToBackupQueue(element, reaction);
181 } 191 }
182 192
183 void CustomElement::enqueueConnectedCallback(Element* element) 193 void CustomElement::enqueueConnectedCallback(Element* element)
184 { 194 {
185 DCHECK_EQ(element->getCustomElementState(), CustomElementState::Custom); 195 DCHECK_EQ(element->getCustomElementState(), CustomElementState::Custom);
186 CustomElementDefinition* definition = definitionForElement(*element); 196 CustomElementDefinition* definition = definitionForElement(*element);
187 if (definition->hasConnectedCallback()) 197 if (definition->hasConnectedCallback())
188 definition->enqueueConnectedCallback(element); 198 definition->enqueueConnectedCallback(element);
189 } 199 }
(...skipping 27 matching lines...) Expand all
217 CustomElementsRegistry* registry = CustomElement::registry(*element); 227 CustomElementsRegistry* registry = CustomElement::registry(*element);
218 if (!registry) 228 if (!registry)
219 return; 229 return;
220 if (CustomElementDefinition* definition = registry->definitionForName(elemen t->localName())) 230 if (CustomElementDefinition* definition = registry->definitionForName(elemen t->localName()))
221 definition->enqueueUpgradeReaction(element); 231 definition->enqueueUpgradeReaction(element);
222 else 232 else
223 registry->addCandidate(element); 233 registry->addCandidate(element);
224 } 234 }
225 235
226 } // namespace blink 236 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698