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 "bindings/core/v8/ScriptWrappable.h" | 9 #include "bindings/core/v8/ScriptWrappable.h" |
9 #include "core/CoreExport.h" | 10 #include "core/CoreExport.h" |
10 #include "platform/heap/Handle.h" | 11 #include "platform/heap/Handle.h" |
11 #include "wtf/Noncopyable.h" | |
12 #include "wtf/text/AtomicString.h" | 12 #include "wtf/text/AtomicString.h" |
13 #include "wtf/text/AtomicStringHash.h" | 13 #include "wtf/text/AtomicStringHash.h" |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 | 16 |
17 class CustomElementDefinition; | 17 class CustomElementDefinition; |
18 class CustomElementDefinitionBuilder; | 18 class CustomElementDefinitionBuilder; |
| 19 class CustomElementDescriptor; |
| 20 class Document; |
| 21 class Element; |
19 class ElementRegistrationOptions; | 22 class ElementRegistrationOptions; |
20 class ExceptionState; | 23 class ExceptionState; |
21 class ScriptState; | 24 class ScriptState; |
22 class ScriptValue; | 25 class ScriptValue; |
23 class V0CustomElementRegistrationContext; | 26 class V0CustomElementRegistrationContext; |
24 | 27 |
25 class CORE_EXPORT CustomElementsRegistry final | 28 class CORE_EXPORT CustomElementsRegistry final |
26 : public GarbageCollectedFinalized<CustomElementsRegistry> | 29 : public GarbageCollectedFinalized<CustomElementsRegistry> |
27 , public ScriptWrappable { | 30 , public ScriptWrappable { |
28 DEFINE_WRAPPERTYPEINFO(); | 31 DEFINE_WRAPPERTYPEINFO(); |
29 WTF_MAKE_NONCOPYABLE(CustomElementsRegistry); | 32 DISALLOW_COPY_AND_ASSIGN(CustomElementsRegistry); |
30 public: | 33 public: |
31 static CustomElementsRegistry* create( | 34 static CustomElementsRegistry* create(Document*); |
32 V0CustomElementRegistrationContext*); | |
33 | 35 |
34 void define( | 36 void define( |
35 ScriptState*, | 37 ScriptState*, |
36 const AtomicString& name, | 38 const AtomicString& name, |
37 const ScriptValue& constructor, | 39 const ScriptValue& constructor, |
38 const ElementRegistrationOptions&, | 40 const ElementRegistrationOptions&, |
39 ExceptionState&); | 41 ExceptionState&); |
40 | 42 |
41 void define( | 43 void define( |
42 const AtomicString& name, | 44 const AtomicString& name, |
43 CustomElementDefinitionBuilder&, | 45 CustomElementDefinitionBuilder&, |
44 const ElementRegistrationOptions&, | 46 const ElementRegistrationOptions&, |
45 ExceptionState&); | 47 ExceptionState&); |
46 | 48 |
47 bool nameIsDefined(const AtomicString& name) const | 49 bool nameIsDefined(const AtomicString& name) const; |
48 { | |
49 return m_definitions.contains(name); | |
50 } | |
51 | 50 |
52 CustomElementDefinition* definitionForName(const AtomicString& name) const; | 51 CustomElementDefinition* definitionForName(const AtomicString& name) const; |
53 | 52 |
| 53 // TODO(dominicc): Consider broadening this API when type extensions are |
| 54 // implemented. |
| 55 void addCandidate(Element*); |
| 56 |
54 DECLARE_TRACE(); | 57 DECLARE_TRACE(); |
55 | 58 |
56 private: | 59 private: |
57 CustomElementsRegistry(const V0CustomElementRegistrationContext*); | 60 friend class CustomElementsRegistryTestBase; |
58 bool v0NameIsDefined(const AtomicString&) const; | 61 |
| 62 CustomElementsRegistry(Document*); |
| 63 |
| 64 V0CustomElementRegistrationContext* v0(); |
| 65 bool v0NameIsDefined(const AtomicString& name); |
| 66 |
| 67 void collectCandidates( |
| 68 const CustomElementDescriptor&, |
| 69 HeapVector<Member<Element>>*); |
59 | 70 |
60 using DefinitionMap = | 71 using DefinitionMap = |
61 HeapHashMap<AtomicString, Member<CustomElementDefinition>>; | 72 HeapHashMap<AtomicString, Member<CustomElementDefinition>>; |
62 DefinitionMap m_definitions; | 73 DefinitionMap m_definitions; |
63 | 74 |
64 Member<const V0CustomElementRegistrationContext> m_v0; | 75 Member<Document> m_document; |
| 76 |
| 77 using UpgradeCandidateSet = HeapHashSet<WeakMember<Element>>; |
| 78 using UpgradeCandidateMap = HeapHashMap< |
| 79 AtomicString, |
| 80 Member<UpgradeCandidateSet>>; |
| 81 Member<UpgradeCandidateMap> m_upgradeCandidates; |
65 }; | 82 }; |
66 | 83 |
67 } // namespace blink | 84 } // namespace blink |
68 | 85 |
69 #endif // CustomElementsRegistry_h | 86 #endif // CustomElementsRegistry_h |
OLD | NEW |