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" | 8 #include "bindings/core/v8/ScopedPersistent.h" |
9 #include "bindings/core/v8/ScriptWrappable.h" | 9 #include "bindings/core/v8/ScriptWrappable.h" |
10 #include "core/CoreExport.h" | 10 #include "core/CoreExport.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 class ScriptState; | 22 class ScriptState; |
23 class ScriptValue; | 23 class ScriptValue; |
24 class V0CustomElementRegistrationContext; | 24 class V0CustomElementRegistrationContext; |
25 | 25 |
26 class CORE_EXPORT CustomElementsRegistry final | 26 class CORE_EXPORT CustomElementsRegistry final |
27 : public GarbageCollectedFinalized<CustomElementsRegistry> | 27 : public GarbageCollectedFinalized<CustomElementsRegistry> |
28 , public ScriptWrappable { | 28 , public ScriptWrappable { |
29 DEFINE_WRAPPERTYPEINFO(); | 29 DEFINE_WRAPPERTYPEINFO(); |
30 public: | 30 public: |
31 using Id = uint32_t; | 31 using Id = uint32_t; |
32 static CustomElementsRegistry* create( | 32 |
33 ScriptState*, | 33 static CustomElementsRegistry* create(V0CustomElementRegistrationContext*); |
34 V0CustomElementRegistrationContext*); | |
35 | 34 |
36 void define( | 35 void define( |
37 ScriptState*, | 36 ScriptState*, |
38 const AtomicString& name, | 37 const AtomicString& name, |
39 const ScriptValue& constructor, | 38 const ScriptValue& constructor, |
40 const ElementRegistrationOptions&, | 39 const ElementRegistrationOptions&, |
41 ExceptionState&); | 40 ExceptionState&); |
42 | 41 |
43 CustomElementDefinition* definitionForConstructor( | 42 CustomElementDefinition* definitionForConstructor( |
44 ScriptState*, | 43 ScriptState*, |
45 v8::Local<v8::Value> constructor); | 44 v8::Local<v8::Value> constructor); |
46 v8::Local<v8::Object> prototype( | 45 v8::Local<v8::Object> prototype( |
47 ScriptState*, | 46 ScriptState*, |
48 const CustomElementDefinition&); | 47 const CustomElementDefinition&); |
49 | 48 |
50 // TODO(dominicc): Remove this when V0CustomElements are removed. | 49 // TODO(dominicc): Remove this when V0CustomElements are removed. |
51 bool nameIsDefined(const AtomicString& name) const; | 50 bool nameIsDefined(const AtomicString& name) const; |
52 | 51 |
53 DECLARE_TRACE(); | 52 DECLARE_TRACE(); |
54 | 53 |
55 private: | 54 private: |
56 CustomElementsRegistry(const V0CustomElementRegistrationContext*); | 55 CustomElementsRegistry(const V0CustomElementRegistrationContext*); |
57 | 56 |
57 void ensureScriptInitialized(ScriptState* scriptState) | |
58 { | |
59 if (State::ScriptNotInitialized == m_state) | |
60 initializeScript(scriptState); | |
61 } | |
62 void initializeScript(ScriptState*); | |
63 | |
58 // Retrieves the Map which, given a constructor, contains the id | 64 // Retrieves the Map which, given a constructor, contains the id |
59 // of the definition; or given an id, contains the prototype. | 65 // of the definition; or given an id, contains the prototype. |
60 // Returns true if the map was retrieved; false if the map was | |
61 // not initialized yet. | |
62 v8::Local<v8::Map> idMap(ScriptState*); | 66 v8::Local<v8::Map> idMap(ScriptState*); |
63 | 67 |
64 bool idForConstructor( | 68 bool idForConstructor( |
65 ScriptState*, | 69 ScriptState*, |
66 v8::Local<v8::Value> constructor, | 70 v8::Local<v8::Value> constructor, |
67 Id&) WARN_UNUSED_RETURN; | 71 Id&) WARN_UNUSED_RETURN; |
68 | 72 |
69 bool v0NameIsDefined(const AtomicString& name); | 73 bool v0NameIsDefined(const AtomicString& name); |
70 | 74 |
75 enum class State { | |
esprehn
2016/05/21 01:47:02
We should be able to null check something instead,
| |
76 ScriptNotInitialized, | |
77 ScriptInitialized | |
78 }; | |
79 State m_state; | |
80 | |
71 Member<const V0CustomElementRegistrationContext> m_v0; | 81 Member<const V0CustomElementRegistrationContext> m_v0; |
72 HeapVector<Member<CustomElementDefinition>> m_definitions; | 82 HeapVector<Member<CustomElementDefinition>> m_definitions; |
73 HashSet<AtomicString> m_names; | 83 HashSet<AtomicString> m_names; |
74 }; | 84 }; |
75 | 85 |
76 } // namespace blink | 86 } // namespace blink |
77 | 87 |
78 #endif // CustomElementsRegistry_h | 88 #endif // CustomElementsRegistry_h |
OLD | NEW |