OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 enum WorldIdConstants { | 47 enum WorldIdConstants { |
48 MainWorldId = 0, | 48 MainWorldId = 0, |
49 // Embedder isolated worlds can use IDs in [1, 1<<29). | 49 // Embedder isolated worlds can use IDs in [1, 1<<29). |
50 EmbedderWorldIdLimit = (1 << 29), | 50 EmbedderWorldIdLimit = (1 << 29), |
51 PrivateScriptIsolatedWorldId, | 51 PrivateScriptIsolatedWorldId, |
52 IsolatedWorldIdLimit, | 52 IsolatedWorldIdLimit, |
53 WorkerWorldId, | 53 WorkerWorldId, |
54 TestingWorldId, | 54 TestingWorldId, |
55 }; | 55 }; |
56 | 56 |
| 57 class DOMObjectHolderBase; |
| 58 template<typename T> class DOMObjectHolder; |
| 59 |
57 // This class represent a collection of DOM wrappers for a specific world. | 60 // This class represent a collection of DOM wrappers for a specific world. |
58 class CORE_EXPORT DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { | 61 class CORE_EXPORT DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { |
59 public: | 62 public: |
60 static PassRefPtr<DOMWrapperWorld> create(v8::Isolate*, int worldId = -1, in
t extensionGroup = -1); | 63 static PassRefPtr<DOMWrapperWorld> create(v8::Isolate*, int worldId = -1, in
t extensionGroup = -1); |
61 | 64 |
62 static const int mainWorldExtensionGroup = 0; | 65 static const int mainWorldExtensionGroup = 0; |
63 static const int privateScriptIsolatedWorldExtensionGroup = 1; | 66 static const int privateScriptIsolatedWorldExtensionGroup = 1; |
64 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(v8::Isolate*, int wor
ldId, int extensionGroup); | 67 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(v8::Isolate*, int wor
ldId, int extensionGroup); |
65 ~DOMWrapperWorld(); | 68 ~DOMWrapperWorld(); |
66 void dispose(); | 69 void dispose(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 int worldId() const { return m_worldId; } | 119 int worldId() const { return m_worldId; } |
117 int extensionGroup() const { return m_extensionGroup; } | 120 int extensionGroup() const { return m_extensionGroup; } |
118 DOMDataStore& domDataStore() const { return *m_domDataStore; } | 121 DOMDataStore& domDataStore() const { return *m_domDataStore; } |
119 | 122 |
120 static void setWorldOfInitializingWindow(DOMWrapperWorld* world) | 123 static void setWorldOfInitializingWindow(DOMWrapperWorld* world) |
121 { | 124 { |
122 ASSERT(isMainThread()); | 125 ASSERT(isMainThread()); |
123 worldOfInitializingWindow = world; | 126 worldOfInitializingWindow = world; |
124 } | 127 } |
125 | 128 |
126 private: | |
127 class DOMObjectHolderBase { | |
128 public: | |
129 DOMObjectHolderBase(v8::Isolate* isolate, v8::Local<v8::Value> wrapper) | |
130 : m_wrapper(isolate, wrapper) | |
131 , m_world(0) | |
132 { | |
133 } | |
134 virtual ~DOMObjectHolderBase() { } | |
135 | |
136 DOMWrapperWorld* world() const { return m_world; } | |
137 void setWorld(DOMWrapperWorld* world) { m_world = world; } | |
138 void setWeak(void (*callback)(const v8::WeakCallbackInfo<DOMObjectHolder
Base>&)) | |
139 { | |
140 m_wrapper.setWeak(this, callback); | |
141 } | |
142 | |
143 private: | |
144 ScopedPersistent<v8::Value> m_wrapper; | |
145 DOMWrapperWorld* m_world; | |
146 }; | |
147 | |
148 template<typename T> | |
149 class DOMObjectHolder : public DOMObjectHolderBase { | |
150 public: | |
151 static PassOwnPtr<DOMObjectHolder<T>> create(v8::Isolate* isolate, T* ob
ject, v8::Local<v8::Value> wrapper) | |
152 { | |
153 return adoptPtr(new DOMObjectHolder(isolate, object, wrapper)); | |
154 } | |
155 | |
156 private: | |
157 DOMObjectHolder(v8::Isolate* isolate, T* object, v8::Local<v8::Value> wr
apper) | |
158 : DOMObjectHolderBase(isolate, wrapper) | |
159 , m_object(object) | |
160 { | |
161 } | |
162 | |
163 Persistent<T> m_object; | |
164 }; | |
165 | |
166 public: | 129 public: |
167 template<typename T> | 130 template<typename T> |
168 void registerDOMObjectHolder(v8::Isolate* isolate, T* object, v8::Local<v8::
Value> wrapper) | 131 void registerDOMObjectHolder(v8::Isolate*, T*, v8::Local<v8::Value>); |
169 { | |
170 registerDOMObjectHolderInternal(DOMObjectHolder<T>::create(isolate, obje
ct, wrapper)); | |
171 } | |
172 | 132 |
173 private: | 133 private: |
174 DOMWrapperWorld(v8::Isolate*, int worldId, int extensionGroup); | 134 DOMWrapperWorld(v8::Isolate*, int worldId, int extensionGroup); |
175 | 135 |
176 static void weakCallbackForDOMObjectHolder(const v8::WeakCallbackInfo<DOMObj
ectHolderBase>&); | 136 static void weakCallbackForDOMObjectHolder(const v8::WeakCallbackInfo<DOMObj
ectHolderBase>&); |
177 void registerDOMObjectHolderInternal(PassOwnPtr<DOMObjectHolderBase>); | 137 void registerDOMObjectHolderInternal(PassOwnPtr<DOMObjectHolderBase>); |
178 void unregisterDOMObjectHolder(DOMObjectHolderBase*); | 138 void unregisterDOMObjectHolder(DOMObjectHolderBase*); |
179 | 139 |
180 static unsigned isolatedWorldCount; | 140 static unsigned isolatedWorldCount; |
181 static DOMWrapperWorld* worldOfInitializingWindow; | 141 static DOMWrapperWorld* worldOfInitializingWindow; |
182 | 142 |
183 const int m_worldId; | 143 const int m_worldId; |
184 const int m_extensionGroup; | 144 const int m_extensionGroup; |
185 OwnPtr<DOMDataStore> m_domDataStore; | 145 OwnPtr<DOMDataStore> m_domDataStore; |
186 HashSet<OwnPtr<DOMObjectHolderBase>> m_domObjectHolders; | 146 HashSet<OwnPtr<DOMObjectHolderBase>> m_domObjectHolders; |
187 }; | 147 }; |
188 | 148 |
189 } // namespace blink | 149 } // namespace blink |
190 | 150 |
191 #endif // DOMWrapperWorld_h | 151 #endif // DOMWrapperWorld_h |
OLD | NEW |