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 28 matching lines...) Expand all Loading... | |
39 #include "bindings/core/v8/WindowProxy.h" | 39 #include "bindings/core/v8/WindowProxy.h" |
40 #include "bindings/core/v8/WrapperTypeInfo.h" | 40 #include "bindings/core/v8/WrapperTypeInfo.h" |
41 #include "core/dom/ExecutionContext.h" | 41 #include "core/dom/ExecutionContext.h" |
42 #include "wtf/HashTraits.h" | 42 #include "wtf/HashTraits.h" |
43 #include "wtf/PtrUtil.h" | 43 #include "wtf/PtrUtil.h" |
44 #include "wtf/StdLibExtras.h" | 44 #include "wtf/StdLibExtras.h" |
45 #include <memory> | 45 #include <memory> |
46 | 46 |
47 namespace blink { | 47 namespace blink { |
48 | 48 |
49 // Returns an identifier for a given world type other than WorldType::Isolated. | |
50 // IsolatedWorld has its unique convention to allocate an identifier. | |
51 int getWorldIdForType(WorldType worldType) { | |
52 switch (worldType) { | |
53 case WorldType::Unknown: | |
54 return UnknownWorldId; | |
55 case WorldType::Main: | |
56 return MainWorldId; | |
57 case WorldType::Isolated: | |
58 NOTREACHED(); | |
haraken
2017/03/08 09:39:09
Why is it not reached?
nhiroki
2017/03/08 10:24:52
Because IsolatedWorld is created by DOMWrapperWorl
haraken
2017/03/08 10:27:47
Hmm. So an ID for an isolated world is provided ex
nhiroki
2017/03/08 10:44:22
That's right.
| |
59 return -1; | |
60 // Currently, WorldId for a worker/worklet is fixed value, but this doesn't | |
peria
2017/03/08 09:48:19
*a* fixed value
nhiroki
2017/03/08 10:24:52
Done.
| |
61 // work when multiple worklets are created on a thread. | |
62 // TODO(nhiroki): Expand the identifier space for workers/worklets. | |
63 case WorldType::Worker: | |
64 return WorkerWorldId; | |
65 } | |
66 NOTREACHED(); | |
67 return -1; | |
68 } | |
69 | |
49 class DOMObjectHolderBase { | 70 class DOMObjectHolderBase { |
50 USING_FAST_MALLOC(DOMObjectHolderBase); | 71 USING_FAST_MALLOC(DOMObjectHolderBase); |
51 | 72 |
52 public: | 73 public: |
53 DOMObjectHolderBase(v8::Isolate* isolate, v8::Local<v8::Value> wrapper) | 74 DOMObjectHolderBase(v8::Isolate* isolate, v8::Local<v8::Value> wrapper) |
54 : m_wrapper(isolate, wrapper), m_world(0) {} | 75 : m_wrapper(isolate, wrapper), m_world(nullptr) {} |
55 virtual ~DOMObjectHolderBase() {} | 76 virtual ~DOMObjectHolderBase() {} |
56 | 77 |
57 DOMWrapperWorld* world() const { return m_world; } | 78 DOMWrapperWorld* world() const { return m_world; } |
58 void setWorld(DOMWrapperWorld* world) { m_world = world; } | 79 void setWorld(DOMWrapperWorld* world) { m_world = world; } |
59 void setWeak( | 80 void setWeak( |
60 void (*callback)(const v8::WeakCallbackInfo<DOMObjectHolderBase>&)) { | 81 void (*callback)(const v8::WeakCallbackInfo<DOMObjectHolderBase>&)) { |
61 m_wrapper.setWeak(this, callback); | 82 m_wrapper.setWeak(this, callback); |
62 } | 83 } |
63 | 84 |
64 private: | 85 private: |
(...skipping 12 matching lines...) Expand all Loading... | |
77 private: | 98 private: |
78 DOMObjectHolder(v8::Isolate* isolate, T* object, v8::Local<v8::Value> wrapper) | 99 DOMObjectHolder(v8::Isolate* isolate, T* object, v8::Local<v8::Value> wrapper) |
79 : DOMObjectHolderBase(isolate, wrapper), m_object(object) {} | 100 : DOMObjectHolderBase(isolate, wrapper), m_object(object) {} |
80 | 101 |
81 Persistent<T> m_object; | 102 Persistent<T> m_object; |
82 }; | 103 }; |
83 | 104 |
84 unsigned DOMWrapperWorld::isolatedWorldCount = 0; | 105 unsigned DOMWrapperWorld::isolatedWorldCount = 0; |
85 | 106 |
86 PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::create(v8::Isolate* isolate, | 107 PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::create(v8::Isolate* isolate, |
87 int worldId) { | 108 WorldType worldType) { |
88 return adoptRef(new DOMWrapperWorld(isolate, worldId)); | 109 DCHECK_NE(WorldType::Isolated, worldType); |
110 return adoptRef( | |
111 new DOMWrapperWorld(isolate, worldType, getWorldIdForType(worldType))); | |
89 } | 112 } |
90 | 113 |
91 DOMWrapperWorld::DOMWrapperWorld(v8::Isolate* isolate, int worldId) | 114 DOMWrapperWorld::DOMWrapperWorld(v8::Isolate* isolate, |
92 : m_worldId(worldId), | 115 WorldType worldType, |
116 int worldId) | |
117 : m_worldType(worldType), | |
118 m_worldId(worldId), | |
93 m_domDataStore( | 119 m_domDataStore( |
94 WTF::wrapUnique(new DOMDataStore(isolate, isMainWorld()))) { | 120 WTF::wrapUnique(new DOMDataStore(isolate, isMainWorld()))) { |
95 if (worldId == WorkerWorldId) { | 121 if (isWorkerWorld()) |
96 workerWorld() = this; | 122 workerWorld() = this; |
97 } | |
98 } | 123 } |
99 | 124 |
100 DOMWrapperWorld& DOMWrapperWorld::mainWorld() { | 125 DOMWrapperWorld& DOMWrapperWorld::mainWorld() { |
101 ASSERT(isMainThread()); | 126 ASSERT(isMainThread()); |
102 DEFINE_STATIC_REF( | 127 DEFINE_STATIC_REF( |
103 DOMWrapperWorld, cachedMainWorld, | 128 DOMWrapperWorld, cachedMainWorld, |
104 (DOMWrapperWorld::create(v8::Isolate::GetCurrent(), MainWorldId))); | 129 (DOMWrapperWorld::create(v8::Isolate::GetCurrent(), WorldType::Main))); |
105 return *cachedMainWorld; | 130 return *cachedMainWorld; |
106 } | 131 } |
107 | 132 |
108 DOMWrapperWorld*& DOMWrapperWorld::workerWorld() { | 133 DOMWrapperWorld*& DOMWrapperWorld::workerWorld() { |
109 DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<DOMWrapperWorld*>, workerWorld, | 134 DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<DOMWrapperWorld*>, workerWorld, |
110 new ThreadSpecific<DOMWrapperWorld*>); | 135 new ThreadSpecific<DOMWrapperWorld*>); |
111 return *workerWorld; | 136 return *workerWorld; |
112 } | 137 } |
113 | 138 |
114 PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::fromWorldId(v8::Isolate* isolate, | 139 PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::fromWorldId(v8::Isolate* isolate, |
115 int worldId) { | 140 int worldId) { |
116 if (worldId == MainWorldId) | 141 if (worldId == MainWorldId) |
peria
2017/03/08 09:48:19
isMainWorld()
nhiroki
2017/03/08 10:24:53
isMainWorld() is not available here because fromWo
| |
117 return &mainWorld(); | 142 return &mainWorld(); |
118 return ensureIsolatedWorld(isolate, worldId); | 143 return ensureIsolatedWorld(isolate, worldId); |
119 } | 144 } |
120 | 145 |
121 typedef HashMap<int, DOMWrapperWorld*> WorldMap; | 146 typedef HashMap<int, DOMWrapperWorld*> WorldMap; |
122 static WorldMap& isolatedWorldMap() { | 147 static WorldMap& isolatedWorldMap() { |
123 ASSERT(isMainThread()); | 148 ASSERT(isMainThread()); |
124 DEFINE_STATIC_LOCAL(WorldMap, map, ()); | 149 DEFINE_STATIC_LOCAL(WorldMap, map, ()); |
125 return map; | 150 return map; |
126 } | 151 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 ASSERT(isIsolatedWorldId(worldId)); | 226 ASSERT(isIsolatedWorldId(worldId)); |
202 | 227 |
203 WorldMap& map = isolatedWorldMap(); | 228 WorldMap& map = isolatedWorldMap(); |
204 WorldMap::AddResult result = map.insert(worldId, nullptr); | 229 WorldMap::AddResult result = map.insert(worldId, nullptr); |
205 RefPtr<DOMWrapperWorld> world = result.storedValue->value; | 230 RefPtr<DOMWrapperWorld> world = result.storedValue->value; |
206 if (world) { | 231 if (world) { |
207 ASSERT(world->worldId() == worldId); | 232 ASSERT(world->worldId() == worldId); |
208 return world.release(); | 233 return world.release(); |
209 } | 234 } |
210 | 235 |
211 world = DOMWrapperWorld::create(isolate, worldId); | 236 world = adoptRef(new DOMWrapperWorld(isolate, WorldType::Isolated, worldId)); |
212 result.storedValue->value = world.get(); | 237 result.storedValue->value = world.get(); |
213 isolatedWorldCount++; | 238 isolatedWorldCount++; |
214 return world.release(); | 239 return world.release(); |
215 } | 240 } |
216 | 241 |
217 typedef HashMap<int, RefPtr<SecurityOrigin>> IsolatedWorldSecurityOriginMap; | 242 typedef HashMap<int, RefPtr<SecurityOrigin>> IsolatedWorldSecurityOriginMap; |
218 static IsolatedWorldSecurityOriginMap& isolatedWorldSecurityOrigins() { | 243 static IsolatedWorldSecurityOriginMap& isolatedWorldSecurityOrigins() { |
219 ASSERT(isMainThread()); | 244 ASSERT(isMainThread()); |
220 DEFINE_STATIC_LOCAL(IsolatedWorldSecurityOriginMap, map, ()); | 245 DEFINE_STATIC_LOCAL(IsolatedWorldSecurityOriginMap, map, ()); |
221 return map; | 246 return map; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 m_domObjectHolders.erase(holderBase); | 334 m_domObjectHolders.erase(holderBase); |
310 } | 335 } |
311 | 336 |
312 void DOMWrapperWorld::weakCallbackForDOMObjectHolder( | 337 void DOMWrapperWorld::weakCallbackForDOMObjectHolder( |
313 const v8::WeakCallbackInfo<DOMObjectHolderBase>& data) { | 338 const v8::WeakCallbackInfo<DOMObjectHolderBase>& data) { |
314 DOMObjectHolderBase* holderBase = data.GetParameter(); | 339 DOMObjectHolderBase* holderBase = data.GetParameter(); |
315 holderBase->world()->unregisterDOMObjectHolder(holderBase); | 340 holderBase->world()->unregisterDOMObjectHolder(holderBase); |
316 } | 341 } |
317 | 342 |
318 } // namespace blink | 343 } // namespace blink |
OLD | NEW |