| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 static const int mainWorldExtensionGroup = 0; | 62 static const int mainWorldExtensionGroup = 0; |
| 63 static const int privateScriptIsolatedWorldExtensionGroup = 1; | 63 static const int privateScriptIsolatedWorldExtensionGroup = 1; |
| 64 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(v8::Isolate*, int wor
ldId, int extensionGroup); | 64 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(v8::Isolate*, int wor
ldId, int extensionGroup); |
| 65 ~DOMWrapperWorld(); | 65 ~DOMWrapperWorld(); |
| 66 void dispose(); | 66 void dispose(); |
| 67 | 67 |
| 68 static bool isolatedWorldsExist() { return isolatedWorldCount; } | 68 static bool isolatedWorldsExist() { return isolatedWorldCount; } |
| 69 static void allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld>>& worlds); | 69 static void allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld>>& worlds); |
| 70 | 70 |
| 71 static DOMWrapperWorld& world(v8::Handle<v8::Context> context) | 71 static DOMWrapperWorld& world(v8::Local<v8::Context> context) |
| 72 { | 72 { |
| 73 return ScriptState::from(context)->world(); | 73 return ScriptState::from(context)->world(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 static DOMWrapperWorld& current(v8::Isolate* isolate) | 76 static DOMWrapperWorld& current(v8::Isolate* isolate) |
| 77 { | 77 { |
| 78 if (isMainThread() && worldOfInitializingWindow) { | 78 if (isMainThread() && worldOfInitializingWindow) { |
| 79 // It's possible that current() is being called while window is bein
g initialized. | 79 // It's possible that current() is being called while window is bein
g initialized. |
| 80 // In order to make current() workable during the initialization pha
se, | 80 // In order to make current() workable during the initialization pha
se, |
| 81 // we cache the world of the initializing window on worldOfInitializ
ingWindow. | 81 // we cache the world of the initializing window on worldOfInitializ
ingWindow. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 119 |
| 120 static void setWorldOfInitializingWindow(DOMWrapperWorld* world) | 120 static void setWorldOfInitializingWindow(DOMWrapperWorld* world) |
| 121 { | 121 { |
| 122 ASSERT(isMainThread()); | 122 ASSERT(isMainThread()); |
| 123 worldOfInitializingWindow = world; | 123 worldOfInitializingWindow = world; |
| 124 } | 124 } |
| 125 | 125 |
| 126 private: | 126 private: |
| 127 class DOMObjectHolderBase { | 127 class DOMObjectHolderBase { |
| 128 public: | 128 public: |
| 129 DOMObjectHolderBase(v8::Isolate* isolate, v8::Handle<v8::Value> wrapper) | 129 DOMObjectHolderBase(v8::Isolate* isolate, v8::Local<v8::Value> wrapper) |
| 130 : m_wrapper(isolate, wrapper) | 130 : m_wrapper(isolate, wrapper) |
| 131 , m_world(0) | 131 , m_world(0) |
| 132 { | 132 { |
| 133 } | 133 } |
| 134 virtual ~DOMObjectHolderBase() { } | 134 virtual ~DOMObjectHolderBase() { } |
| 135 | 135 |
| 136 DOMWrapperWorld* world() const { return m_world; } | 136 DOMWrapperWorld* world() const { return m_world; } |
| 137 void setWorld(DOMWrapperWorld* world) { m_world = world; } | 137 void setWorld(DOMWrapperWorld* world) { m_world = world; } |
| 138 void setWeak(void (*callback)(const v8::WeakCallbackInfo<DOMObjectHolder
Base>&)) | 138 void setWeak(void (*callback)(const v8::WeakCallbackInfo<DOMObjectHolder
Base>&)) |
| 139 { | 139 { |
| 140 m_wrapper.setWeak(this, callback); | 140 m_wrapper.setWeak(this, callback); |
| 141 } | 141 } |
| 142 | 142 |
| 143 private: | 143 private: |
| 144 ScopedPersistent<v8::Value> m_wrapper; | 144 ScopedPersistent<v8::Value> m_wrapper; |
| 145 DOMWrapperWorld* m_world; | 145 DOMWrapperWorld* m_world; |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 template<typename T> | 148 template<typename T> |
| 149 class DOMObjectHolder : public DOMObjectHolderBase { | 149 class DOMObjectHolder : public DOMObjectHolderBase { |
| 150 public: | 150 public: |
| 151 static PassOwnPtr<DOMObjectHolder<T>> create(v8::Isolate* isolate, T* ob
ject, v8::Handle<v8::Value> wrapper) | 151 static PassOwnPtr<DOMObjectHolder<T>> create(v8::Isolate* isolate, T* ob
ject, v8::Local<v8::Value> wrapper) |
| 152 { | 152 { |
| 153 return adoptPtr(new DOMObjectHolder(isolate, object, wrapper)); | 153 return adoptPtr(new DOMObjectHolder(isolate, object, wrapper)); |
| 154 } | 154 } |
| 155 | 155 |
| 156 private: | 156 private: |
| 157 DOMObjectHolder(v8::Isolate* isolate, T* object, v8::Handle<v8::Value> w
rapper) | 157 DOMObjectHolder(v8::Isolate* isolate, T* object, v8::Local<v8::Value> wr
apper) |
| 158 : DOMObjectHolderBase(isolate, wrapper) | 158 : DOMObjectHolderBase(isolate, wrapper) |
| 159 , m_object(object) | 159 , m_object(object) |
| 160 { | 160 { |
| 161 } | 161 } |
| 162 | 162 |
| 163 Persistent<T> m_object; | 163 Persistent<T> m_object; |
| 164 }; | 164 }; |
| 165 | 165 |
| 166 public: | 166 public: |
| 167 template<typename T> | 167 template<typename T> |
| 168 void registerDOMObjectHolder(v8::Isolate* isolate, T* object, v8::Handle<v8:
:Value> wrapper) | 168 void registerDOMObjectHolder(v8::Isolate* isolate, T* object, v8::Local<v8::
Value> wrapper) |
| 169 { | 169 { |
| 170 registerDOMObjectHolderInternal(DOMObjectHolder<T>::create(isolate, obje
ct, wrapper)); | 170 registerDOMObjectHolderInternal(DOMObjectHolder<T>::create(isolate, obje
ct, wrapper)); |
| 171 } | 171 } |
| 172 | 172 |
| 173 private: | 173 private: |
| 174 DOMWrapperWorld(v8::Isolate*, int worldId, int extensionGroup); | 174 DOMWrapperWorld(v8::Isolate*, int worldId, int extensionGroup); |
| 175 | 175 |
| 176 static void weakCallbackForDOMObjectHolder(const v8::WeakCallbackInfo<DOMObj
ectHolderBase>&); | 176 static void weakCallbackForDOMObjectHolder(const v8::WeakCallbackInfo<DOMObj
ectHolderBase>&); |
| 177 void registerDOMObjectHolderInternal(PassOwnPtr<DOMObjectHolderBase>); | 177 void registerDOMObjectHolderInternal(PassOwnPtr<DOMObjectHolderBase>); |
| 178 void unregisterDOMObjectHolder(DOMObjectHolderBase*); | 178 void unregisterDOMObjectHolder(DOMObjectHolderBase*); |
| 179 | 179 |
| 180 static unsigned isolatedWorldCount; | 180 static unsigned isolatedWorldCount; |
| 181 static DOMWrapperWorld* worldOfInitializingWindow; | 181 static DOMWrapperWorld* worldOfInitializingWindow; |
| 182 | 182 |
| 183 const int m_worldId; | 183 const int m_worldId; |
| 184 const int m_extensionGroup; | 184 const int m_extensionGroup; |
| 185 OwnPtr<DOMDataStore> m_domDataStore; | 185 OwnPtr<DOMDataStore> m_domDataStore; |
| 186 HashSet<OwnPtr<DOMObjectHolderBase>> m_domObjectHolders; | 186 HashSet<OwnPtr<DOMObjectHolderBase>> m_domObjectHolders; |
| 187 }; | 187 }; |
| 188 | 188 |
| 189 } // namespace blink | 189 } // namespace blink |
| 190 | 190 |
| 191 #endif // DOMWrapperWorld_h | 191 #endif // DOMWrapperWorld_h |
| OLD | NEW |