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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 DCHECK(!map.Contains(world_id_)); | 128 DCHECK(!map.Contains(world_id_)); |
129 map.insert(world_id_, this); | 129 map.insert(world_id_, this); |
130 if (IsMainThread()) | 130 if (IsMainThread()) |
131 number_of_non_main_worlds_in_main_thread_++; | 131 number_of_non_main_worlds_in_main_thread_++; |
132 break; | 132 break; |
133 } | 133 } |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 DOMWrapperWorld& DOMWrapperWorld::MainWorld() { | 137 DOMWrapperWorld& DOMWrapperWorld::MainWorld() { |
138 ASSERT(IsMainThread()); | 138 DCHECK(IsMainThread()); |
139 DEFINE_STATIC_REF( | 139 DEFINE_STATIC_REF( |
140 DOMWrapperWorld, cached_main_world, | 140 DOMWrapperWorld, cached_main_world, |
141 (DOMWrapperWorld::Create(v8::Isolate::GetCurrent(), WorldType::kMain))); | 141 (DOMWrapperWorld::Create(v8::Isolate::GetCurrent(), WorldType::kMain))); |
142 return *cached_main_world; | 142 return *cached_main_world; |
143 } | 143 } |
144 | 144 |
145 void DOMWrapperWorld::AllWorldsInCurrentThread( | 145 void DOMWrapperWorld::AllWorldsInCurrentThread( |
146 Vector<RefPtr<DOMWrapperWorld>>& worlds) { | 146 Vector<RefPtr<DOMWrapperWorld>>& worlds) { |
147 if (IsMainThread()) | 147 if (IsMainThread()) |
148 worlds.push_back(&MainWorld()); | 148 worlds.push_back(&MainWorld()); |
(...skipping 11 matching lines...) Expand all Loading... |
160 if (data_store.ContainsWrapper(script_wrappable)) | 160 if (data_store.ContainsWrapper(script_wrappable)) |
161 data_store.MarkWrapper(script_wrappable); | 161 data_store.MarkWrapper(script_wrappable); |
162 } | 162 } |
163 | 163 |
164 // Marking for the main world. | 164 // Marking for the main world. |
165 if (IsMainThread()) | 165 if (IsMainThread()) |
166 script_wrappable->MarkWrapper(visitor); | 166 script_wrappable->MarkWrapper(visitor); |
167 } | 167 } |
168 | 168 |
169 DOMWrapperWorld::~DOMWrapperWorld() { | 169 DOMWrapperWorld::~DOMWrapperWorld() { |
170 ASSERT(!IsMainWorld()); | 170 DCHECK(!IsMainWorld()); |
171 if (IsMainThread()) | 171 if (IsMainThread()) |
172 number_of_non_main_worlds_in_main_thread_--; | 172 number_of_non_main_worlds_in_main_thread_--; |
173 | 173 |
174 // WorkerWorld should be disposed of before the dtor. | 174 // WorkerWorld should be disposed of before the dtor. |
175 if (!IsWorkerWorld()) | 175 if (!IsWorkerWorld()) |
176 Dispose(); | 176 Dispose(); |
177 DCHECK(!GetWorldMap().Contains(world_id_)); | 177 DCHECK(!GetWorldMap().Contains(world_id_)); |
178 } | 178 } |
179 | 179 |
180 void DOMWrapperWorld::Dispose() { | 180 void DOMWrapperWorld::Dispose() { |
181 dom_object_holders_.Clear(); | 181 dom_object_holders_.Clear(); |
182 dom_data_store_.reset(); | 182 dom_data_store_.reset(); |
183 DCHECK(GetWorldMap().Contains(world_id_)); | 183 DCHECK(GetWorldMap().Contains(world_id_)); |
184 GetWorldMap().erase(world_id_); | 184 GetWorldMap().erase(world_id_); |
185 } | 185 } |
186 | 186 |
187 PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::EnsureIsolatedWorld( | 187 PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::EnsureIsolatedWorld( |
188 v8::Isolate* isolate, | 188 v8::Isolate* isolate, |
189 int world_id) { | 189 int world_id) { |
190 ASSERT(IsIsolatedWorldId(world_id)); | 190 #if DCHECK_IS_ON() |
| 191 DCHECK(IsIsolatedWorldId(world_id)); |
| 192 #endif |
191 | 193 |
192 WorldMap& map = GetWorldMap(); | 194 WorldMap& map = GetWorldMap(); |
193 auto it = map.Find(world_id); | 195 auto it = map.Find(world_id); |
194 if (it != map.end()) { | 196 if (it != map.end()) { |
195 RefPtr<DOMWrapperWorld> world = it->value; | 197 RefPtr<DOMWrapperWorld> world = it->value; |
196 DCHECK(world->IsIsolatedWorld()); | 198 DCHECK(world->IsIsolatedWorld()); |
197 DCHECK_EQ(world_id, world->GetWorldId()); | 199 DCHECK_EQ(world_id, world->GetWorldId()); |
198 return world.Release(); | 200 return world.Release(); |
199 } | 201 } |
200 | 202 |
201 return AdoptRef(new DOMWrapperWorld(isolate, WorldType::kIsolated, world_id)); | 203 return AdoptRef(new DOMWrapperWorld(isolate, WorldType::kIsolated, world_id)); |
202 } | 204 } |
203 | 205 |
204 typedef HashMap<int, RefPtr<SecurityOrigin>> IsolatedWorldSecurityOriginMap; | 206 typedef HashMap<int, RefPtr<SecurityOrigin>> IsolatedWorldSecurityOriginMap; |
205 static IsolatedWorldSecurityOriginMap& IsolatedWorldSecurityOrigins() { | 207 static IsolatedWorldSecurityOriginMap& IsolatedWorldSecurityOrigins() { |
206 ASSERT(IsMainThread()); | 208 DCHECK(IsMainThread()); |
207 DEFINE_STATIC_LOCAL(IsolatedWorldSecurityOriginMap, map, ()); | 209 DEFINE_STATIC_LOCAL(IsolatedWorldSecurityOriginMap, map, ()); |
208 return map; | 210 return map; |
209 } | 211 } |
210 | 212 |
211 SecurityOrigin* DOMWrapperWorld::IsolatedWorldSecurityOrigin() { | 213 SecurityOrigin* DOMWrapperWorld::IsolatedWorldSecurityOrigin() { |
212 ASSERT(this->IsIsolatedWorld()); | 214 DCHECK(this->IsIsolatedWorld()); |
213 IsolatedWorldSecurityOriginMap& origins = IsolatedWorldSecurityOrigins(); | 215 IsolatedWorldSecurityOriginMap& origins = IsolatedWorldSecurityOrigins(); |
214 IsolatedWorldSecurityOriginMap::iterator it = origins.Find(GetWorldId()); | 216 IsolatedWorldSecurityOriginMap::iterator it = origins.Find(GetWorldId()); |
215 return it == origins.end() ? 0 : it->value.Get(); | 217 return it == origins.end() ? 0 : it->value.Get(); |
216 } | 218 } |
217 | 219 |
218 void DOMWrapperWorld::SetIsolatedWorldSecurityOrigin( | 220 void DOMWrapperWorld::SetIsolatedWorldSecurityOrigin( |
219 int world_id, | 221 int world_id, |
220 PassRefPtr<SecurityOrigin> security_origin) { | 222 PassRefPtr<SecurityOrigin> security_origin) { |
221 ASSERT(IsIsolatedWorldId(world_id)); | 223 #if DCHECK_IS_ON() |
| 224 DCHECK(IsIsolatedWorldId(world_id)); |
| 225 #endif |
222 if (security_origin) | 226 if (security_origin) |
223 IsolatedWorldSecurityOrigins().Set(world_id, std::move(security_origin)); | 227 IsolatedWorldSecurityOrigins().Set(world_id, std::move(security_origin)); |
224 else | 228 else |
225 IsolatedWorldSecurityOrigins().erase(world_id); | 229 IsolatedWorldSecurityOrigins().erase(world_id); |
226 } | 230 } |
227 | 231 |
228 typedef HashMap<int, String> IsolatedWorldHumanReadableNameMap; | 232 typedef HashMap<int, String> IsolatedWorldHumanReadableNameMap; |
229 static IsolatedWorldHumanReadableNameMap& IsolatedWorldHumanReadableNames() { | 233 static IsolatedWorldHumanReadableNameMap& IsolatedWorldHumanReadableNames() { |
230 ASSERT(IsMainThread()); | 234 DCHECK(IsMainThread()); |
231 DEFINE_STATIC_LOCAL(IsolatedWorldHumanReadableNameMap, map, ()); | 235 DEFINE_STATIC_LOCAL(IsolatedWorldHumanReadableNameMap, map, ()); |
232 return map; | 236 return map; |
233 } | 237 } |
234 | 238 |
235 String DOMWrapperWorld::IsolatedWorldHumanReadableName() { | 239 String DOMWrapperWorld::IsolatedWorldHumanReadableName() { |
236 ASSERT(this->IsIsolatedWorld()); | 240 ASSERT(this->IsIsolatedWorld()); |
237 return IsolatedWorldHumanReadableNames().at(GetWorldId()); | 241 return IsolatedWorldHumanReadableNames().at(GetWorldId()); |
238 } | 242 } |
239 | 243 |
240 void DOMWrapperWorld::SetIsolatedWorldHumanReadableName( | 244 void DOMWrapperWorld::SetIsolatedWorldHumanReadableName( |
241 int world_id, | 245 int world_id, |
242 const String& human_readable_name) { | 246 const String& human_readable_name) { |
243 ASSERT(IsIsolatedWorldId(world_id)); | 247 #if DCHECK_IS_ON() |
| 248 DCHECK(IsIsolatedWorldId(world_id)); |
| 249 #endif |
244 IsolatedWorldHumanReadableNames().Set(world_id, human_readable_name); | 250 IsolatedWorldHumanReadableNames().Set(world_id, human_readable_name); |
245 } | 251 } |
246 | 252 |
247 typedef HashMap<int, bool> IsolatedWorldContentSecurityPolicyMap; | 253 typedef HashMap<int, bool> IsolatedWorldContentSecurityPolicyMap; |
248 static IsolatedWorldContentSecurityPolicyMap& | 254 static IsolatedWorldContentSecurityPolicyMap& |
249 IsolatedWorldContentSecurityPolicies() { | 255 IsolatedWorldContentSecurityPolicies() { |
250 ASSERT(IsMainThread()); | 256 DCHECK(IsMainThread()); |
251 DEFINE_STATIC_LOCAL(IsolatedWorldContentSecurityPolicyMap, map, ()); | 257 DEFINE_STATIC_LOCAL(IsolatedWorldContentSecurityPolicyMap, map, ()); |
252 return map; | 258 return map; |
253 } | 259 } |
254 | 260 |
255 bool DOMWrapperWorld::IsolatedWorldHasContentSecurityPolicy() { | 261 bool DOMWrapperWorld::IsolatedWorldHasContentSecurityPolicy() { |
256 ASSERT(this->IsIsolatedWorld()); | 262 DCHECK(this->IsIsolatedWorld()); |
257 IsolatedWorldContentSecurityPolicyMap& policies = | 263 IsolatedWorldContentSecurityPolicyMap& policies = |
258 IsolatedWorldContentSecurityPolicies(); | 264 IsolatedWorldContentSecurityPolicies(); |
259 IsolatedWorldContentSecurityPolicyMap::iterator it = | 265 IsolatedWorldContentSecurityPolicyMap::iterator it = |
260 policies.Find(GetWorldId()); | 266 policies.Find(GetWorldId()); |
261 return it == policies.end() ? false : it->value; | 267 return it == policies.end() ? false : it->value; |
262 } | 268 } |
263 | 269 |
264 void DOMWrapperWorld::SetIsolatedWorldContentSecurityPolicy( | 270 void DOMWrapperWorld::SetIsolatedWorldContentSecurityPolicy( |
265 int world_id, | 271 int world_id, |
266 const String& policy) { | 272 const String& policy) { |
267 ASSERT(IsIsolatedWorldId(world_id)); | 273 #if DCHECK_IS_ON() |
| 274 DCHECK(IsIsolatedWorldId(world_id)); |
| 275 #endif |
268 if (!policy.IsEmpty()) | 276 if (!policy.IsEmpty()) |
269 IsolatedWorldContentSecurityPolicies().Set(world_id, true); | 277 IsolatedWorldContentSecurityPolicies().Set(world_id, true); |
270 else | 278 else |
271 IsolatedWorldContentSecurityPolicies().erase(world_id); | 279 IsolatedWorldContentSecurityPolicies().erase(world_id); |
272 } | 280 } |
273 | 281 |
274 template <typename T> | 282 template <typename T> |
275 void DOMWrapperWorld::RegisterDOMObjectHolder(v8::Isolate* isolate, | 283 void DOMWrapperWorld::RegisterDOMObjectHolder(v8::Isolate* isolate, |
276 T* object, | 284 T* object, |
277 v8::Local<v8::Value> wrapper) { | 285 v8::Local<v8::Value> wrapper) { |
278 RegisterDOMObjectHolderInternal( | 286 RegisterDOMObjectHolderInternal( |
279 DOMObjectHolder<T>::Create(isolate, object, wrapper)); | 287 DOMObjectHolder<T>::Create(isolate, object, wrapper)); |
280 } | 288 } |
281 | 289 |
282 template void DOMWrapperWorld::RegisterDOMObjectHolder(v8::Isolate*, | 290 template void DOMWrapperWorld::RegisterDOMObjectHolder(v8::Isolate*, |
283 ScriptFunction*, | 291 ScriptFunction*, |
284 v8::Local<v8::Value>); | 292 v8::Local<v8::Value>); |
285 | 293 |
286 void DOMWrapperWorld::RegisterDOMObjectHolderInternal( | 294 void DOMWrapperWorld::RegisterDOMObjectHolderInternal( |
287 std::unique_ptr<DOMObjectHolderBase> holder_base) { | 295 std::unique_ptr<DOMObjectHolderBase> holder_base) { |
288 ASSERT(!dom_object_holders_.Contains(holder_base.get())); | 296 DCHECK(!dom_object_holders_.Contains(holder_base.get())); |
289 holder_base->SetWorld(this); | 297 holder_base->SetWorld(this); |
290 holder_base->SetWeak(&DOMWrapperWorld::WeakCallbackForDOMObjectHolder); | 298 holder_base->SetWeak(&DOMWrapperWorld::WeakCallbackForDOMObjectHolder); |
291 dom_object_holders_.insert(std::move(holder_base)); | 299 dom_object_holders_.insert(std::move(holder_base)); |
292 } | 300 } |
293 | 301 |
294 void DOMWrapperWorld::UnregisterDOMObjectHolder( | 302 void DOMWrapperWorld::UnregisterDOMObjectHolder( |
295 DOMObjectHolderBase* holder_base) { | 303 DOMObjectHolderBase* holder_base) { |
296 ASSERT(dom_object_holders_.Contains(holder_base)); | 304 DCHECK(dom_object_holders_.Contains(holder_base)); |
297 dom_object_holders_.erase(holder_base); | 305 dom_object_holders_.erase(holder_base); |
298 } | 306 } |
299 | 307 |
300 void DOMWrapperWorld::WeakCallbackForDOMObjectHolder( | 308 void DOMWrapperWorld::WeakCallbackForDOMObjectHolder( |
301 const v8::WeakCallbackInfo<DOMObjectHolderBase>& data) { | 309 const v8::WeakCallbackInfo<DOMObjectHolderBase>& data) { |
302 DOMObjectHolderBase* holder_base = data.GetParameter(); | 310 DOMObjectHolderBase* holder_base = data.GetParameter(); |
303 holder_base->World()->UnregisterDOMObjectHolder(holder_base); | 311 holder_base->World()->UnregisterDOMObjectHolder(holder_base); |
304 } | 312 } |
305 | 313 |
306 int DOMWrapperWorld::GenerateWorldIdForType(WorldType world_type) { | 314 int DOMWrapperWorld::GenerateWorldIdForType(WorldType world_type) { |
(...skipping 16 matching lines...) Expand all Loading... |
323 int world_id = *next_world_id; | 331 int world_id = *next_world_id; |
324 CHECK_GE(world_id, WorldId::kUnspecifiedWorldIdStart); | 332 CHECK_GE(world_id, WorldId::kUnspecifiedWorldIdStart); |
325 *next_world_id = world_id + 1; | 333 *next_world_id = world_id + 1; |
326 return world_id; | 334 return world_id; |
327 } | 335 } |
328 NOTREACHED(); | 336 NOTREACHED(); |
329 return kInvalidWorldId; | 337 return kInvalidWorldId; |
330 } | 338 } |
331 | 339 |
332 } // namespace blink | 340 } // namespace blink |
OLD | NEW |