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 #ifndef CustomElementsRegistry_h | 5 #ifndef CustomElementsRegistry_h |
6 #define CustomElementsRegistry_h | 6 #define CustomElementsRegistry_h |
7 | 7 |
8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
10 #include "bindings/core/v8/ScriptWrappable.h" | 10 #include "bindings/core/v8/ScriptWrappable.h" |
11 #include "core/CoreExport.h" | 11 #include "core/CoreExport.h" |
12 #include "platform/heap/Handle.h" | 12 #include "platform/heap/Handle.h" |
13 #include "wtf/HashSet.h" | 13 #include "wtf/HashSet.h" |
14 #include "wtf/Noncopyable.h" | 14 #include "wtf/Noncopyable.h" |
15 #include "wtf/text/AtomicString.h" | 15 #include "wtf/text/AtomicString.h" |
16 #include "wtf/text/AtomicStringHash.h" | 16 #include "wtf/text/AtomicStringHash.h" |
17 | 17 |
18 namespace blink { | 18 namespace blink { |
19 | 19 |
20 class CustomElementDefinition; | 20 class CustomElementDefinition; |
21 class CustomElementDefinitionBuilder; | 21 class CustomElementDefinitionBuilder; |
22 class CustomElementDescriptor; | 22 class CustomElementDescriptor; |
23 class Document; | |
24 class Element; | 23 class Element; |
25 class ElementRegistrationOptions; | 24 class ElementRegistrationOptions; |
26 class ExceptionState; | 25 class ExceptionState; |
| 26 class LocalDOMWindow; |
27 class ScriptPromiseResolver; | 27 class ScriptPromiseResolver; |
28 class ScriptState; | 28 class ScriptState; |
29 class ScriptValue; | 29 class ScriptValue; |
30 class V0CustomElementRegistrationContext; | 30 class V0CustomElementRegistrationContext; |
31 | 31 |
32 class CORE_EXPORT CustomElementsRegistry final | 32 class CORE_EXPORT CustomElementsRegistry final |
33 : public GarbageCollectedFinalized<CustomElementsRegistry> | 33 : public GarbageCollectedFinalized<CustomElementsRegistry> |
34 , public ScriptWrappable { | 34 , public ScriptWrappable { |
35 DEFINE_WRAPPERTYPEINFO(); | 35 DEFINE_WRAPPERTYPEINFO(); |
36 WTF_MAKE_NONCOPYABLE(CustomElementsRegistry); | 36 WTF_MAKE_NONCOPYABLE(CustomElementsRegistry); |
37 public: | 37 public: |
38 static CustomElementsRegistry* create(Document*); | 38 static CustomElementsRegistry* create(const LocalDOMWindow*); |
39 | 39 |
40 virtual ~CustomElementsRegistry() = default; | 40 virtual ~CustomElementsRegistry() = default; |
41 | 41 |
42 void define( | 42 void define( |
43 ScriptState*, | 43 ScriptState*, |
44 const AtomicString& name, | 44 const AtomicString& name, |
45 const ScriptValue& constructor, | 45 const ScriptValue& constructor, |
46 const ElementRegistrationOptions&, | 46 const ElementRegistrationOptions&, |
47 ExceptionState&); | 47 ExceptionState&); |
48 | 48 |
49 void define( | 49 void define( |
50 const AtomicString& name, | 50 const AtomicString& name, |
51 CustomElementDefinitionBuilder&, | 51 CustomElementDefinitionBuilder&, |
52 const ElementRegistrationOptions&, | 52 const ElementRegistrationOptions&, |
53 ExceptionState&); | 53 ExceptionState&); |
54 | 54 |
55 ScriptValue get(const AtomicString& name); | 55 ScriptValue get(const AtomicString& name); |
56 bool nameIsDefined(const AtomicString& name) const; | 56 bool nameIsDefined(const AtomicString& name) const; |
57 CustomElementDefinition* definitionForName(const AtomicString& name) const; | 57 CustomElementDefinition* definitionForName(const AtomicString& name) const; |
58 | 58 |
| 59 // TODO(dominicc): Switch most callers of definitionForName to |
| 60 // definitionFor when implementing type extensions. |
| 61 CustomElementDefinition* definitionFor(const CustomElementDescriptor&) const
; |
| 62 |
59 // TODO(dominicc): Consider broadening this API when type extensions are | 63 // TODO(dominicc): Consider broadening this API when type extensions are |
60 // implemented. | 64 // implemented. |
61 void addCandidate(Element*); | 65 void addCandidate(Element*); |
62 ScriptPromise whenDefined( | 66 ScriptPromise whenDefined( |
63 ScriptState*, | 67 ScriptState*, |
64 const AtomicString& name, | 68 const AtomicString& name, |
65 ExceptionState&); | 69 ExceptionState&); |
66 | 70 |
| 71 void entangle(V0CustomElementRegistrationContext*); |
| 72 |
67 DECLARE_TRACE(); | 73 DECLARE_TRACE(); |
68 | 74 |
69 private: | 75 private: |
70 friend class CustomElementsRegistryTestBase; | 76 friend class CustomElementsRegistryTest; |
71 | 77 |
72 CustomElementsRegistry(Document*); | 78 CustomElementsRegistry(const LocalDOMWindow*); |
73 | 79 |
74 V0CustomElementRegistrationContext* v0(); | |
75 bool v0NameIsDefined(const AtomicString& name); | 80 bool v0NameIsDefined(const AtomicString& name); |
76 | 81 |
77 void collectCandidates( | 82 void collectCandidates( |
78 const CustomElementDescriptor&, | 83 const CustomElementDescriptor&, |
79 HeapVector<Member<Element>>*); | 84 HeapVector<Member<Element>>*); |
80 | 85 |
81 class NameIsBeingDefined; | 86 class NameIsBeingDefined; |
82 | 87 |
83 HashSet<AtomicString> m_namesBeingDefined; | 88 HashSet<AtomicString> m_namesBeingDefined; |
84 using DefinitionMap = | 89 using DefinitionMap = |
85 HeapHashMap<AtomicString, Member<CustomElementDefinition>>; | 90 HeapHashMap<AtomicString, Member<CustomElementDefinition>>; |
86 DefinitionMap m_definitions; | 91 DefinitionMap m_definitions; |
87 | 92 |
88 Member<Document> m_document; | 93 Member<const LocalDOMWindow> m_owner; |
| 94 |
| 95 using V0RegistrySet = HeapHashSet<WeakMember<V0CustomElementRegistrationCont
ext>>; |
| 96 Member<V0RegistrySet> m_v0; |
89 | 97 |
90 using UpgradeCandidateSet = HeapHashSet<WeakMember<Element>>; | 98 using UpgradeCandidateSet = HeapHashSet<WeakMember<Element>>; |
91 using UpgradeCandidateMap = HeapHashMap< | 99 using UpgradeCandidateMap = HeapHashMap< |
92 AtomicString, | 100 AtomicString, |
93 Member<UpgradeCandidateSet>>; | 101 Member<UpgradeCandidateSet>>; |
94 Member<UpgradeCandidateMap> m_upgradeCandidates; | 102 Member<UpgradeCandidateMap> m_upgradeCandidates; |
95 | 103 |
96 using WhenDefinedPromiseMap = | 104 using WhenDefinedPromiseMap = |
97 HeapHashMap<AtomicString, Member<ScriptPromiseResolver>>; | 105 HeapHashMap<AtomicString, Member<ScriptPromiseResolver>>; |
98 WhenDefinedPromiseMap m_whenDefinedPromiseMap; | 106 WhenDefinedPromiseMap m_whenDefinedPromiseMap; |
99 }; | 107 }; |
100 | 108 |
101 } // namespace blink | 109 } // namespace blink |
102 | 110 |
103 #endif // CustomElementsRegistry_h | 111 #endif // CustomElementsRegistry_h |
OLD | NEW |