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 "WrapperTypeInfo.h" | 39 #include "WrapperTypeInfo.h" |
40 #include <wtf/HashTraits.h> | 40 #include <wtf/HashTraits.h> |
41 #include <wtf/MainThread.h> | 41 #include <wtf/MainThread.h> |
42 #include <wtf/StdLibExtras.h> | 42 #include <wtf/StdLibExtras.h> |
43 | 43 |
44 namespace WebCore { | 44 namespace WebCore { |
45 | 45 |
46 int DOMWrapperWorld::isolatedWorldCount = 0; | 46 int DOMWrapperWorld::isolatedWorldCount = 0; |
47 static bool initializingWindow = false; | 47 static bool initializingWindow = false; |
48 | 48 |
49 PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::createUninitializedWorld() | |
50 { | |
51 return adoptRef(new DOMWrapperWorld(uninitializedWorldId, uninitializedExten sionGroup)); | |
52 } | |
53 | |
54 void DOMWrapperWorld::setInitializingWindow(bool initializing) | 49 void DOMWrapperWorld::setInitializingWindow(bool initializing) |
55 { | 50 { |
56 initializingWindow = initializing; | 51 initializingWindow = initializing; |
57 } | 52 } |
58 | 53 |
59 PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::createMainWorld() | 54 PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::createMainWorld() |
60 { | 55 { |
61 return adoptRef(new DOMWrapperWorld(mainWorldId, mainWorldExtensionGroup)); | 56 return adoptRef(new DOMWrapperWorld(mainWorldId, mainWorldExtensionGroup)); |
62 } | 57 } |
63 | 58 |
64 DOMWrapperWorld::DOMWrapperWorld(int worldId, int extensionGroup) | 59 DOMWrapperWorld::DOMWrapperWorld(int worldId, int extensionGroup) |
65 : m_worldId(worldId) | 60 : m_worldId(worldId) |
66 , m_extensionGroup(extensionGroup) | 61 , m_extensionGroup(extensionGroup) |
67 { | 62 { |
68 if (isIsolatedWorld()) | 63 if (isIsolatedWorld()) |
69 m_domDataStore = adoptPtr(new DOMDataStore(IsolatedWorld)); | 64 m_domDataStore = adoptPtr(new DOMDataStore(IsolatedWorld)); |
70 } | 65 } |
71 | 66 |
72 DOMWrapperWorld* mainThreadNormalWorld() | 67 DOMWrapperWorld* mainThreadNormalWorld() |
73 { | 68 { |
74 ASSERT(isMainThread()); | 69 ASSERT(isMainThread()); |
75 DEFINE_STATIC_LOCAL(RefPtr<DOMWrapperWorld>, cachedNormalWorld, (DOMWrapperW orld::createMainWorld())); | 70 DEFINE_STATIC_LOCAL(RefPtr<DOMWrapperWorld>, cachedNormalWorld, (DOMWrapperW orld::createMainWorld())); |
76 return cachedNormalWorld.get(); | 71 return cachedNormalWorld.get(); |
77 } | 72 } |
78 | 73 |
74 // FIXME: Remove this function. There is currently an issue with the inspector r elated to the call to dispatchDidClearWindowObjectInWorld in ScriptController::w indowShell. | |
75 DOMWrapperWorld* existingWindowShellWorkaroundWorld() | |
76 { | |
77 DEFINE_STATIC_LOCAL(RefPtr<DOMWrapperWorld>, world, (adoptRef(new DOMWrapper World(DOMWrapperWorld::mainWorldId - 1, DOMWrapperWorld::mainWorldExtensionGroup - 1)))); | |
78 return world.get(); | |
79 } | |
80 | |
79 bool DOMWrapperWorld::contextHasCorrectPrototype(v8::Handle<v8::Context> context ) | 81 bool DOMWrapperWorld::contextHasCorrectPrototype(v8::Handle<v8::Context> context ) |
80 { | 82 { |
81 ASSERT(isMainThread()); | 83 ASSERT(isMainThread()); |
82 if (initializingWindow) | 84 if (initializingWindow) |
83 return true; | 85 return true; |
84 return V8DOMWrapper::isWrapperOfType(toInnerGlobalObject(context), &V8DOMWin dow::info); | 86 return V8DOMWrapper::isWrapperOfType(toInnerGlobalObject(context), &V8DOMWin dow::info); |
85 } | 87 } |
86 | 88 |
87 template<> | 89 template<> |
88 void WeakHandleListener<DOMWrapperWorld>::callback(v8::Isolate* isolate, v8::Per sistent<v8::Value> object, DOMWrapperWorld* world) | 90 void WeakHandleListener<DOMWrapperWorld>::callback(v8::Isolate* isolate, v8::Per sistent<v8::Value> object, DOMWrapperWorld* world) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 ASSERT_NOT_REACHED(); | 139 ASSERT_NOT_REACHED(); |
138 return; | 140 return; |
139 } | 141 } |
140 ASSERT(i->value == this); | 142 ASSERT(i->value == this); |
141 | 143 |
142 map.remove(i); | 144 map.remove(i); |
143 isolatedWorldCount--; | 145 isolatedWorldCount--; |
144 ASSERT(map.size() == isolatedWorldCount); | 146 ASSERT(map.size() == isolatedWorldCount); |
145 } | 147 } |
146 | 148 |
147 static int temporaryWorldId = DOMWrapperWorld::uninitializedWorldId-1; | |
148 | |
149 PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::ensureIsolatedWorld(int worldId, in t extensionGroup) | 149 PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::ensureIsolatedWorld(int worldId, in t extensionGroup) |
150 { | 150 { |
151 ASSERT(worldId != mainWorldId); | 151 ASSERT(worldId > mainWorldId); |
152 ASSERT(worldId >= uninitializedWorldId); | |
153 | 152 |
154 WorldMap& map = isolatedWorldMap(); | 153 WorldMap& map = isolatedWorldMap(); |
155 if (worldId == uninitializedWorldId) | 154 WorldMap::AddResult result = map.add(worldId, 0); |
haraken
2013/04/12 02:14:19
Shouldn't this be map.find()? And then you need to
adamk
2013/04/12 15:44:04
Odd though this code looks, this is the idiomatic
| |
156 worldId = temporaryWorldId--; | 155 RefPtr<DOMWrapperWorld> world = result.iterator->value; |
157 else { | 156 if (world) { |
158 WorldMap::iterator i = map.find(worldId); | 157 ASSERT(world->worldId() == worldId); |
159 if (i != map.end()) { | 158 ASSERT(world->extensionGroup() == extensionGroup); |
160 ASSERT(i->value->worldId() == worldId); | 159 return world.release(); |
161 ASSERT(i->value->extensionGroup() == extensionGroup); | |
162 return i->value; | |
163 } | |
164 } | 160 } |
165 | 161 |
166 RefPtr<DOMWrapperWorld> world = adoptRef(new DOMWrapperWorld(worldId, extens ionGroup)); | 162 world = adoptRef(new DOMWrapperWorld(worldId, extensionGroup)); |
167 map.add(worldId, world.get()); | 163 result.iterator->value = world.get(); |
168 isolatedWorldCount++; | 164 isolatedWorldCount++; |
169 ASSERT(map.size() == isolatedWorldCount); | 165 ASSERT(map.size() == isolatedWorldCount); |
170 | 166 |
171 return world.release(); | 167 return world.release(); |
172 } | 168 } |
173 | 169 |
174 typedef HashMap<int, RefPtr<SecurityOrigin> > IsolatedWorldSecurityOriginMap; | 170 typedef HashMap<int, RefPtr<SecurityOrigin> > IsolatedWorldSecurityOriginMap; |
175 static IsolatedWorldSecurityOriginMap& isolatedWorldSecurityOrigins() | 171 static IsolatedWorldSecurityOriginMap& isolatedWorldSecurityOrigins() |
176 { | 172 { |
177 ASSERT(isMainThread()); | 173 ASSERT(isMainThread()); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 } | 243 } |
248 | 244 |
249 V8DOMActivityLogger* DOMWrapperWorld::activityLogger(int worldId) | 245 V8DOMActivityLogger* DOMWrapperWorld::activityLogger(int worldId) |
250 { | 246 { |
251 DOMActivityLoggerMap& loggers = domActivityLoggers(); | 247 DOMActivityLoggerMap& loggers = domActivityLoggers(); |
252 DOMActivityLoggerMap::iterator it = loggers.find(worldId); | 248 DOMActivityLoggerMap::iterator it = loggers.find(worldId); |
253 return it == loggers.end() ? 0 : it->value.get(); | 249 return it == loggers.end() ? 0 : it->value.get(); |
254 } | 250 } |
255 | 251 |
256 } // namespace WebCore | 252 } // namespace WebCore |
OLD | NEW |