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 "bindings/core/v8/ScopedPersistent.h" | |
9 #include "bindings/core/v8/ScriptWrappable.h" | 8 #include "bindings/core/v8/ScriptWrappable.h" |
10 #include "core/CoreExport.h" | 9 #include "core/CoreExport.h" |
11 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
12 #include "v8.h" | 11 #include "wtf/Noncopyable.h" |
13 #include "wtf/HashSet.h" | |
14 #include "wtf/text/AtomicString.h" | 12 #include "wtf/text/AtomicString.h" |
15 #include "wtf/text/AtomicStringHash.h" | 13 #include "wtf/text/AtomicStringHash.h" |
16 | 14 |
17 namespace blink { | 15 namespace blink { |
18 | 16 |
19 class CustomElementDefinition; | 17 class CustomElementDefinition; |
| 18 class CustomElementDefinitionBuilder; |
20 class ElementRegistrationOptions; | 19 class ElementRegistrationOptions; |
21 class ExceptionState; | 20 class ExceptionState; |
22 class ScriptState; | 21 class ScriptState; |
23 class ScriptValue; | 22 class ScriptValue; |
24 class V0CustomElementRegistrationContext; | 23 class V0CustomElementRegistrationContext; |
25 | 24 |
26 class CORE_EXPORT CustomElementsRegistry final | 25 class CORE_EXPORT CustomElementsRegistry final |
27 : public GarbageCollectedFinalized<CustomElementsRegistry> | 26 : public GarbageCollectedFinalized<CustomElementsRegistry> |
28 , public ScriptWrappable { | 27 , public ScriptWrappable { |
29 DEFINE_WRAPPERTYPEINFO(); | 28 DEFINE_WRAPPERTYPEINFO(); |
| 29 WTF_MAKE_NONCOPYABLE(CustomElementsRegistry); |
30 public: | 30 public: |
31 using Id = uint32_t; | |
32 static CustomElementsRegistry* create( | 31 static CustomElementsRegistry* create( |
33 ScriptState*, | |
34 V0CustomElementRegistrationContext*); | 32 V0CustomElementRegistrationContext*); |
35 | 33 |
36 void define( | 34 void define( |
37 ScriptState*, | 35 ScriptState*, |
38 const AtomicString& name, | 36 const AtomicString& name, |
39 const ScriptValue& constructor, | 37 const ScriptValue& constructor, |
40 const ElementRegistrationOptions&, | 38 const ElementRegistrationOptions&, |
41 ExceptionState&); | 39 ExceptionState&); |
42 | 40 |
43 CustomElementDefinition* definitionForConstructor( | 41 void define( |
44 ScriptState*, | 42 const AtomicString& name, |
45 v8::Local<v8::Value> constructor); | 43 CustomElementDefinitionBuilder&, |
46 v8::Local<v8::Object> prototype( | 44 const ElementRegistrationOptions&, |
47 ScriptState*, | 45 ExceptionState&); |
48 const CustomElementDefinition&); | |
49 | 46 |
50 // TODO(dominicc): Remove this when V0CustomElements are removed. | 47 bool nameIsDefined(const AtomicString& name) const |
51 bool nameIsDefined(const AtomicString& name) const; | 48 { |
| 49 return m_definitions.contains(name); |
| 50 } |
| 51 |
| 52 CustomElementDefinition* definitionForName(const AtomicString& name) const; |
52 | 53 |
53 DECLARE_TRACE(); | 54 DECLARE_TRACE(); |
54 | 55 |
55 private: | 56 private: |
56 CustomElementsRegistry(const V0CustomElementRegistrationContext*); | 57 CustomElementsRegistry(const V0CustomElementRegistrationContext*); |
| 58 bool v0NameIsDefined(const AtomicString&) const; |
57 | 59 |
58 // Retrieves the Map which, given a constructor, contains the id | 60 using DefinitionMap = |
59 // of the definition; or given an id, contains the prototype. | 61 HeapHashMap<AtomicString, Member<CustomElementDefinition>>; |
60 // Returns true if the map was retrieved; false if the map was | 62 DefinitionMap m_definitions; |
61 // not initialized yet. | |
62 v8::Local<v8::Map> idMap(ScriptState*); | |
63 | |
64 bool idForConstructor( | |
65 ScriptState*, | |
66 v8::Local<v8::Value> constructor, | |
67 Id&) WARN_UNUSED_RETURN; | |
68 | |
69 bool v0NameIsDefined(const AtomicString& name); | |
70 | 63 |
71 Member<const V0CustomElementRegistrationContext> m_v0; | 64 Member<const V0CustomElementRegistrationContext> m_v0; |
72 HeapVector<Member<CustomElementDefinition>> m_definitions; | |
73 HashSet<AtomicString> m_names; | |
74 }; | 65 }; |
75 | 66 |
76 } // namespace blink | 67 } // namespace blink |
77 | 68 |
78 #endif // CustomElementsRegistry_h | 69 #endif // CustomElementsRegistry_h |
OLD | NEW |