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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 #if DCHECK_IS_ON() | 55 #if DCHECK_IS_ON() |
56 static bool IsIsolatedWorldId(int world_id) { | 56 static bool IsIsolatedWorldId(int world_id) { |
57 return DOMWrapperWorld::kMainWorldId < world_id && | 57 return DOMWrapperWorld::kMainWorldId < world_id && |
58 world_id < DOMWrapperWorld::kIsolatedWorldIdLimit; | 58 world_id < DOMWrapperWorld::kIsolatedWorldIdLimit; |
59 } | 59 } |
60 #endif | 60 #endif |
61 | 61 |
62 PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::Create(v8::Isolate* isolate, | 62 PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::Create(v8::Isolate* isolate, |
63 WorldType world_type) { | 63 WorldType world_type) { |
64 DCHECK_NE(WorldType::kIsolated, world_type); | 64 DCHECK_NE(WorldType::kIsolated, world_type); |
65 return AdoptRef(new DOMWrapperWorld(isolate, world_type, | 65 int world_id = GenerateWorldIdForType(world_type); |
66 GenerateWorldIdForType(world_type))); | 66 if (world_id == kInvalidWorldId) |
| 67 return nullptr; |
| 68 return AdoptRef(new DOMWrapperWorld(isolate, world_type, world_id)); |
67 } | 69 } |
68 | 70 |
69 DOMWrapperWorld::DOMWrapperWorld(v8::Isolate* isolate, | 71 DOMWrapperWorld::DOMWrapperWorld(v8::Isolate* isolate, |
70 WorldType world_type, | 72 WorldType world_type, |
71 int world_id) | 73 int world_id) |
72 : world_type_(world_type), | 74 : world_type_(world_type), |
73 world_id_(world_id), | 75 world_id_(world_id), |
74 dom_data_store_( | 76 dom_data_store_( |
75 WTF::WrapUnique(new DOMDataStore(isolate, IsMainWorld()))) { | 77 WTF::WrapUnique(new DOMDataStore(isolate, IsMainWorld()))) { |
76 switch (world_type_) { | 78 switch (world_type_) { |
77 case WorldType::kMain: | 79 case WorldType::kMain: |
78 // The main world is managed separately from worldMap(). See worldMap(). | 80 // The main world is managed separately from worldMap(). See worldMap(). |
79 break; | 81 break; |
80 case WorldType::kIsolated: | 82 case WorldType::kIsolated: |
| 83 case WorldType::kInspectorIsolated: |
81 case WorldType::kGarbageCollector: | 84 case WorldType::kGarbageCollector: |
82 case WorldType::kRegExp: | 85 case WorldType::kRegExp: |
83 case WorldType::kTesting: | 86 case WorldType::kTesting: |
84 case WorldType::kWorker: { | 87 case WorldType::kWorker: { |
85 WorldMap& map = GetWorldMap(); | 88 WorldMap& map = GetWorldMap(); |
86 DCHECK(!map.Contains(world_id_)); | 89 DCHECK(!map.Contains(world_id_)); |
87 map.insert(world_id_, this); | 90 map.insert(world_id_, this); |
88 if (IsMainThread()) | 91 if (IsMainThread()) |
89 number_of_non_main_worlds_in_main_thread_++; | 92 number_of_non_main_worlds_in_main_thread_++; |
90 break; | 93 break; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 DCHECK(dom_object_holders_.Contains(holder_base)); | 253 DCHECK(dom_object_holders_.Contains(holder_base)); |
251 dom_object_holders_.erase(holder_base); | 254 dom_object_holders_.erase(holder_base); |
252 } | 255 } |
253 | 256 |
254 void DOMWrapperWorld::WeakCallbackForDOMObjectHolder( | 257 void DOMWrapperWorld::WeakCallbackForDOMObjectHolder( |
255 const v8::WeakCallbackInfo<DOMObjectHolderBase>& data) { | 258 const v8::WeakCallbackInfo<DOMObjectHolderBase>& data) { |
256 DOMObjectHolderBase* holder_base = data.GetParameter(); | 259 DOMObjectHolderBase* holder_base = data.GetParameter(); |
257 holder_base->World()->UnregisterDOMObjectHolder(holder_base); | 260 holder_base->World()->UnregisterDOMObjectHolder(holder_base); |
258 } | 261 } |
259 | 262 |
| 263 // static |
260 int DOMWrapperWorld::GenerateWorldIdForType(WorldType world_type) { | 264 int DOMWrapperWorld::GenerateWorldIdForType(WorldType world_type) { |
261 DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<int>, next_world_id, | 265 DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<int>, next_world_id, |
262 new ThreadSpecific<int>); | 266 new ThreadSpecific<int>); |
263 if (!next_world_id.IsSet()) | 267 if (!next_world_id.IsSet()) |
264 *next_world_id = WorldId::kUnspecifiedWorldIdStart; | 268 *next_world_id = WorldId::kUnspecifiedWorldIdStart; |
265 switch (world_type) { | 269 switch (world_type) { |
266 case WorldType::kMain: | 270 case WorldType::kMain: |
267 return kMainWorldId; | 271 return kMainWorldId; |
268 case WorldType::kIsolated: | 272 case WorldType::kIsolated: |
269 // This function should not be called for IsolatedWorld because an | 273 // This function should not be called for IsolatedWorld because an |
270 // identifier for the world is given from out of DOMWrapperWorld. | 274 // identifier for the world is given from out of DOMWrapperWorld. |
271 NOTREACHED(); | 275 NOTREACHED(); |
272 return kInvalidWorldId; | 276 return kInvalidWorldId; |
| 277 case WorldType::kInspectorIsolated: { |
| 278 DCHECK(IsMainThread()); |
| 279 static int next_devtools_isolated_world_id = |
| 280 WorldId::kDevToolsFirstIsolatedWorldId; |
| 281 if (next_devtools_isolated_world_id > |
| 282 WorldId::kDevToolsLastIsolatedWorldId) |
| 283 return WorldId::kInvalidWorldId; |
| 284 return next_devtools_isolated_world_id++; |
| 285 } |
273 case WorldType::kGarbageCollector: | 286 case WorldType::kGarbageCollector: |
274 case WorldType::kRegExp: | 287 case WorldType::kRegExp: |
275 case WorldType::kTesting: | 288 case WorldType::kTesting: |
276 case WorldType::kWorker: | 289 case WorldType::kWorker: |
277 int world_id = *next_world_id; | 290 int world_id = *next_world_id; |
278 CHECK_GE(world_id, WorldId::kUnspecifiedWorldIdStart); | 291 CHECK_GE(world_id, WorldId::kUnspecifiedWorldIdStart); |
279 *next_world_id = world_id + 1; | 292 *next_world_id = world_id + 1; |
280 return world_id; | 293 return world_id; |
281 } | 294 } |
282 NOTREACHED(); | 295 NOTREACHED(); |
283 return kInvalidWorldId; | 296 return kInvalidWorldId; |
284 } | 297 } |
285 | 298 |
286 void DOMWrapperWorld::DissociateDOMWindowWrappersInAllWorlds( | 299 void DOMWrapperWorld::DissociateDOMWindowWrappersInAllWorlds( |
287 ScriptWrappable* script_wrappable) { | 300 ScriptWrappable* script_wrappable) { |
288 DCHECK(script_wrappable); | 301 DCHECK(script_wrappable); |
289 DCHECK(IsMainThread()); | 302 DCHECK(IsMainThread()); |
290 | 303 |
291 script_wrappable->UnsetWrapperIfAny(); | 304 script_wrappable->UnsetWrapperIfAny(); |
292 | 305 |
293 for (auto& world : GetWorldMap().Values()) | 306 for (auto& world : GetWorldMap().Values()) |
294 world->DomDataStore().UnsetWrapperIfAny(script_wrappable); | 307 world->DomDataStore().UnsetWrapperIfAny(script_wrappable); |
295 } | 308 } |
296 | 309 |
297 } // namespace blink | 310 } // namespace blink |
OLD | NEW |