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 27 matching lines...) Expand all Loading... |
38 #include "bindings/core/v8/V8DOMWrapper.h" | 38 #include "bindings/core/v8/V8DOMWrapper.h" |
39 #include "bindings/core/v8/V8Window.h" | 39 #include "bindings/core/v8/V8Window.h" |
40 #include "bindings/core/v8/WindowProxy.h" | 40 #include "bindings/core/v8/WindowProxy.h" |
41 #include "bindings/core/v8/WrapperTypeInfo.h" | 41 #include "bindings/core/v8/WrapperTypeInfo.h" |
42 #include "core/dom/ExecutionContext.h" | 42 #include "core/dom/ExecutionContext.h" |
43 #include "wtf/HashTraits.h" | 43 #include "wtf/HashTraits.h" |
44 #include "wtf/StdLibExtras.h" | 44 #include "wtf/StdLibExtras.h" |
45 | 45 |
46 namespace blink { | 46 namespace blink { |
47 | 47 |
| 48 class DOMObjectHolderBase { |
| 49 WTF_MAKE_FAST_ALLOCATED(DOMObjectHolderBase); |
| 50 public: |
| 51 DOMObjectHolderBase(v8::Isolate* isolate, v8::Local<v8::Value> wrapper) |
| 52 : m_wrapper(isolate, wrapper) |
| 53 , m_world(0) |
| 54 { |
| 55 } |
| 56 virtual ~DOMObjectHolderBase() { } |
| 57 |
| 58 DOMWrapperWorld* world() const { return m_world; } |
| 59 void setWorld(DOMWrapperWorld* world) { m_world = world; } |
| 60 void setWeak(void (*callback)(const v8::WeakCallbackInfo<DOMObjectHolderBase
>&)) |
| 61 { |
| 62 m_wrapper.setWeak(this, callback); |
| 63 } |
| 64 |
| 65 private: |
| 66 ScopedPersistent<v8::Value> m_wrapper; |
| 67 DOMWrapperWorld* m_world; |
| 68 }; |
| 69 |
| 70 template<typename T> |
| 71 class DOMObjectHolder : public DOMObjectHolderBase { |
| 72 public: |
| 73 static PassOwnPtr<DOMObjectHolder<T>> create(v8::Isolate* isolate, T* object
, v8::Local<v8::Value> wrapper) |
| 74 { |
| 75 return adoptPtr(new DOMObjectHolder(isolate, object, wrapper)); |
| 76 } |
| 77 |
| 78 private: |
| 79 DOMObjectHolder(v8::Isolate* isolate, T* object, v8::Local<v8::Value> wrappe
r) |
| 80 : DOMObjectHolderBase(isolate, wrapper) |
| 81 , m_object(object) |
| 82 { |
| 83 } |
| 84 |
| 85 Persistent<T> m_object; |
| 86 }; |
| 87 |
48 unsigned DOMWrapperWorld::isolatedWorldCount = 0; | 88 unsigned DOMWrapperWorld::isolatedWorldCount = 0; |
49 DOMWrapperWorld* DOMWrapperWorld::worldOfInitializingWindow = 0; | 89 DOMWrapperWorld* DOMWrapperWorld::worldOfInitializingWindow = 0; |
50 | 90 |
51 PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::create(v8::Isolate* isolate, int wo
rldId, int extensionGroup) | 91 PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::create(v8::Isolate* isolate, int wo
rldId, int extensionGroup) |
52 { | 92 { |
53 return adoptRef(new DOMWrapperWorld(isolate, worldId, extensionGroup)); | 93 return adoptRef(new DOMWrapperWorld(isolate, worldId, extensionGroup)); |
54 } | 94 } |
55 | 95 |
56 DOMWrapperWorld::DOMWrapperWorld(v8::Isolate* isolate, int worldId, int extensio
nGroup) | 96 DOMWrapperWorld::DOMWrapperWorld(v8::Isolate* isolate, int worldId, int extensio
nGroup) |
57 : m_worldId(worldId) | 97 : m_worldId(worldId) |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 254 |
215 void DOMWrapperWorld::setIsolatedWorldContentSecurityPolicy(int worldId, const S
tring& policy) | 255 void DOMWrapperWorld::setIsolatedWorldContentSecurityPolicy(int worldId, const S
tring& policy) |
216 { | 256 { |
217 ASSERT(isIsolatedWorldId(worldId)); | 257 ASSERT(isIsolatedWorldId(worldId)); |
218 if (!policy.isEmpty()) | 258 if (!policy.isEmpty()) |
219 isolatedWorldContentSecurityPolicies().set(worldId, true); | 259 isolatedWorldContentSecurityPolicies().set(worldId, true); |
220 else | 260 else |
221 isolatedWorldContentSecurityPolicies().remove(worldId); | 261 isolatedWorldContentSecurityPolicies().remove(worldId); |
222 } | 262 } |
223 | 263 |
| 264 template<typename T> |
| 265 void DOMWrapperWorld::registerDOMObjectHolder(v8::Isolate* isolate, T* object, v
8::Local<v8::Value> wrapper) |
| 266 { |
| 267 registerDOMObjectHolderInternal(DOMObjectHolder<T>::create(isolate, object,
wrapper)); |
| 268 } |
| 269 |
| 270 template void DOMWrapperWorld::registerDOMObjectHolder(v8::Isolate*, ScriptFunct
ion*, v8::Local<v8::Value>); |
| 271 |
224 void DOMWrapperWorld::registerDOMObjectHolderInternal(PassOwnPtr<DOMObjectHolder
Base> holderBase) | 272 void DOMWrapperWorld::registerDOMObjectHolderInternal(PassOwnPtr<DOMObjectHolder
Base> holderBase) |
225 { | 273 { |
226 ASSERT(!m_domObjectHolders.contains(holderBase.get())); | 274 ASSERT(!m_domObjectHolders.contains(holderBase.get())); |
227 holderBase->setWorld(this); | 275 holderBase->setWorld(this); |
228 holderBase->setWeak(&DOMWrapperWorld::weakCallbackForDOMObjectHolder); | 276 holderBase->setWeak(&DOMWrapperWorld::weakCallbackForDOMObjectHolder); |
229 m_domObjectHolders.add(holderBase); | 277 m_domObjectHolders.add(holderBase); |
230 } | 278 } |
231 | 279 |
232 void DOMWrapperWorld::unregisterDOMObjectHolder(DOMObjectHolderBase* holderBase) | 280 void DOMWrapperWorld::unregisterDOMObjectHolder(DOMObjectHolderBase* holderBase) |
233 { | 281 { |
234 ASSERT(m_domObjectHolders.contains(holderBase)); | 282 ASSERT(m_domObjectHolders.contains(holderBase)); |
235 m_domObjectHolders.remove(holderBase); | 283 m_domObjectHolders.remove(holderBase); |
236 } | 284 } |
237 | 285 |
238 void DOMWrapperWorld::weakCallbackForDOMObjectHolder(const v8::WeakCallbackInfo<
DOMObjectHolderBase>& data) | 286 void DOMWrapperWorld::weakCallbackForDOMObjectHolder(const v8::WeakCallbackInfo<
DOMObjectHolderBase>& data) |
239 { | 287 { |
240 DOMObjectHolderBase* holderBase = data.GetParameter(); | 288 DOMObjectHolderBase* holderBase = data.GetParameter(); |
241 holderBase->world()->unregisterDOMObjectHolder(holderBase); | 289 holderBase->world()->unregisterDOMObjectHolder(holderBase); |
242 } | 290 } |
243 | 291 |
244 } // namespace blink | 292 } // namespace blink |
OLD | NEW |