OLD | NEW |
---|---|
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/CustomElementsRegistry.h" | 5 #include "core/dom/custom/CustomElementsRegistry.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "bindings/core/v8/ScriptCustomElementDefinitionBuilder.h" | 8 #include "bindings/core/v8/ScriptCustomElementDefinitionBuilder.h" |
9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 document ? document->registrationContext() : nullptr) | 72 document ? document->registrationContext() : nullptr) |
73 registry->entangle(v0); | 73 registry->entangle(v0); |
74 return registry; | 74 return registry; |
75 } | 75 } |
76 | 76 |
77 CustomElementsRegistry::CustomElementsRegistry(const LocalDOMWindow* owner) | 77 CustomElementsRegistry::CustomElementsRegistry(const LocalDOMWindow* owner) |
78 : m_owner(owner) | 78 : m_owner(owner) |
79 , m_v0 (new V0RegistrySet()) | 79 , m_v0 (new V0RegistrySet()) |
80 , m_upgradeCandidates(new UpgradeCandidateMap()) | 80 , m_upgradeCandidates(new UpgradeCandidateMap()) |
81 { | 81 { |
82 DCHECK(m_owner->document() == m_owner->document()->contextDocument()); | |
kochi
2016/08/22 12:02:00
Hmm, this is a leftover from Koji's original patch
| |
82 } | 83 } |
83 | 84 |
84 DEFINE_TRACE(CustomElementsRegistry) | 85 DEFINE_TRACE(CustomElementsRegistry) |
85 { | 86 { |
86 visitor->trace(m_definitions); | 87 visitor->trace(m_definitions); |
87 visitor->trace(m_owner); | 88 visitor->trace(m_owner); |
88 visitor->trace(m_v0); | 89 visitor->trace(m_v0); |
89 visitor->trace(m_upgradeCandidates); | 90 visitor->trace(m_upgradeCandidates); |
90 visitor->trace(m_whenDefinedPromiseMap); | 91 visitor->trace(m_whenDefinedPromiseMap); |
91 } | 92 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 } | 228 } |
228 | 229 |
229 CustomElementDefinition* CustomElementsRegistry::definitionForName( | 230 CustomElementDefinition* CustomElementsRegistry::definitionForName( |
230 const AtomicString& name) const | 231 const AtomicString& name) const |
231 { | 232 { |
232 return m_definitions.get(name); | 233 return m_definitions.get(name); |
233 } | 234 } |
234 | 235 |
235 void CustomElementsRegistry::addCandidate(Element* candidate) | 236 void CustomElementsRegistry::addCandidate(Element* candidate) |
236 { | 237 { |
238 DCHECK(candidate->document().contextDocument() == m_owner->document()); | |
dominicc (has gone to gerrit)
2016/08/22 08:07:36
This should actually be harmless, but I guess I do
kochi
2016/08/22 12:02:00
After https://codereview.chromium.org/2252003002/
| |
239 | |
237 const AtomicString& name = candidate->localName(); | 240 const AtomicString& name = candidate->localName(); |
238 if (nameIsDefined(name) || v0NameIsDefined(name)) | 241 if (nameIsDefined(name) || v0NameIsDefined(name)) |
239 return; | 242 return; |
240 UpgradeCandidateMap::iterator it = m_upgradeCandidates->find(name); | 243 UpgradeCandidateMap::iterator it = m_upgradeCandidates->find(name); |
241 UpgradeCandidateSet* set; | 244 UpgradeCandidateSet* set; |
242 if (it != m_upgradeCandidates->end()) { | 245 if (it != m_upgradeCandidates->end()) { |
243 set = it->value; | 246 set = it->value; |
244 } else { | 247 } else { |
245 set = m_upgradeCandidates->add(name, new UpgradeCandidateSet()) | 248 set = m_upgradeCandidates->add(name, new UpgradeCandidateSet()) |
246 .storedValue | 249 .storedValue |
(...skipping 22 matching lines...) Expand all Loading... | |
269 return newResolver->promise(); | 272 return newResolver->promise(); |
270 } | 273 } |
271 | 274 |
272 void CustomElementsRegistry::collectCandidates( | 275 void CustomElementsRegistry::collectCandidates( |
273 const CustomElementDescriptor& desc, | 276 const CustomElementDescriptor& desc, |
274 HeapVector<Member<Element>>* elements) | 277 HeapVector<Member<Element>>* elements) |
275 { | 278 { |
276 UpgradeCandidateMap::iterator it = m_upgradeCandidates->find(desc.name()); | 279 UpgradeCandidateMap::iterator it = m_upgradeCandidates->find(desc.name()); |
277 if (it == m_upgradeCandidates->end()) | 280 if (it == m_upgradeCandidates->end()) |
278 return; | 281 return; |
282 | |
279 CustomElementUpgradeSorter sorter; | 283 CustomElementUpgradeSorter sorter; |
280 for (Element* element : *it.get()->value) { | 284 for (Element* element : *it.get()->value) { |
281 if (!element || !desc.matches(*element)) | 285 if (!element || !desc.matches(*element)) |
282 continue; | 286 continue; |
283 sorter.add(element); | 287 sorter.add(element); |
284 } | 288 } |
285 | 289 |
286 m_upgradeCandidates->remove(it); | 290 m_upgradeCandidates->remove(it); |
287 | 291 |
288 Document* document = m_owner->document(); | 292 Document* document = m_owner->document(); |
289 if (!document) | 293 if (!document) |
290 return; | 294 return; |
291 | 295 |
292 sorter.sorted(elements, document); | 296 sorter.sorted(elements, document); |
293 } | 297 } |
294 | 298 |
295 } // namespace blink | 299 } // namespace blink |
OLD | NEW |