Chromium Code Reviews| 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 DCHECK(IsIsolatedWorldId(world_id)); |
|
bhagirathi.s
2017/04/13 14:04:39
This is failed to compile in build bot, since IsIs
tkent
2017/04/14 00:26:44
Yes, it's a straight-forward fix for this kind of
bhagirathi.s
2017/04/17 09:13:42
DCHECK_IS_ON() added to fix the compilation error.
| |
| 191 | 191 |
| 192 WorldMap& map = GetWorldMap(); | 192 WorldMap& map = GetWorldMap(); |
| 193 auto it = map.Find(world_id); | 193 auto it = map.Find(world_id); |
| 194 if (it != map.end()) { | 194 if (it != map.end()) { |
| 195 RefPtr<DOMWrapperWorld> world = it->value; | 195 RefPtr<DOMWrapperWorld> world = it->value; |
| 196 DCHECK(world->IsIsolatedWorld()); | 196 DCHECK(world->IsIsolatedWorld()); |
| 197 DCHECK_EQ(world_id, world->GetWorldId()); | 197 DCHECK_EQ(world_id, world->GetWorldId()); |
| 198 return world.Release(); | 198 return world.Release(); |
| 199 } | 199 } |
| 200 | 200 |
| 201 return AdoptRef(new DOMWrapperWorld(isolate, WorldType::kIsolated, world_id)); | 201 return AdoptRef(new DOMWrapperWorld(isolate, WorldType::kIsolated, world_id)); |
| 202 } | 202 } |
| 203 | 203 |
| 204 typedef HashMap<int, RefPtr<SecurityOrigin>> IsolatedWorldSecurityOriginMap; | 204 typedef HashMap<int, RefPtr<SecurityOrigin>> IsolatedWorldSecurityOriginMap; |
| 205 static IsolatedWorldSecurityOriginMap& IsolatedWorldSecurityOrigins() { | 205 static IsolatedWorldSecurityOriginMap& IsolatedWorldSecurityOrigins() { |
| 206 ASSERT(IsMainThread()); | 206 DCHECK(IsMainThread()); |
| 207 DEFINE_STATIC_LOCAL(IsolatedWorldSecurityOriginMap, map, ()); | 207 DEFINE_STATIC_LOCAL(IsolatedWorldSecurityOriginMap, map, ()); |
| 208 return map; | 208 return map; |
| 209 } | 209 } |
| 210 | 210 |
| 211 SecurityOrigin* DOMWrapperWorld::IsolatedWorldSecurityOrigin() { | 211 SecurityOrigin* DOMWrapperWorld::IsolatedWorldSecurityOrigin() { |
| 212 ASSERT(this->IsIsolatedWorld()); | 212 DCHECK(this->IsIsolatedWorld()); |
| 213 IsolatedWorldSecurityOriginMap& origins = IsolatedWorldSecurityOrigins(); | 213 IsolatedWorldSecurityOriginMap& origins = IsolatedWorldSecurityOrigins(); |
| 214 IsolatedWorldSecurityOriginMap::iterator it = origins.Find(GetWorldId()); | 214 IsolatedWorldSecurityOriginMap::iterator it = origins.Find(GetWorldId()); |
| 215 return it == origins.end() ? 0 : it->value.Get(); | 215 return it == origins.end() ? 0 : it->value.Get(); |
| 216 } | 216 } |
| 217 | 217 |
| 218 void DOMWrapperWorld::SetIsolatedWorldSecurityOrigin( | 218 void DOMWrapperWorld::SetIsolatedWorldSecurityOrigin( |
| 219 int world_id, | 219 int world_id, |
| 220 PassRefPtr<SecurityOrigin> security_origin) { | 220 PassRefPtr<SecurityOrigin> security_origin) { |
| 221 ASSERT(IsIsolatedWorldId(world_id)); | 221 DCHECK(IsIsolatedWorldId(world_id)); |
| 222 if (security_origin) | 222 if (security_origin) |
| 223 IsolatedWorldSecurityOrigins().Set(world_id, std::move(security_origin)); | 223 IsolatedWorldSecurityOrigins().Set(world_id, std::move(security_origin)); |
| 224 else | 224 else |
| 225 IsolatedWorldSecurityOrigins().erase(world_id); | 225 IsolatedWorldSecurityOrigins().erase(world_id); |
| 226 } | 226 } |
| 227 | 227 |
| 228 typedef HashMap<int, String> IsolatedWorldHumanReadableNameMap; | 228 typedef HashMap<int, String> IsolatedWorldHumanReadableNameMap; |
| 229 static IsolatedWorldHumanReadableNameMap& IsolatedWorldHumanReadableNames() { | 229 static IsolatedWorldHumanReadableNameMap& IsolatedWorldHumanReadableNames() { |
| 230 ASSERT(IsMainThread()); | 230 DCHECK(IsMainThread()); |
| 231 DEFINE_STATIC_LOCAL(IsolatedWorldHumanReadableNameMap, map, ()); | 231 DEFINE_STATIC_LOCAL(IsolatedWorldHumanReadableNameMap, map, ()); |
| 232 return map; | 232 return map; |
| 233 } | 233 } |
| 234 | 234 |
| 235 String DOMWrapperWorld::IsolatedWorldHumanReadableName() { | 235 String DOMWrapperWorld::IsolatedWorldHumanReadableName() { |
| 236 ASSERT(this->IsIsolatedWorld()); | 236 ASSERT(this->IsIsolatedWorld()); |
| 237 return IsolatedWorldHumanReadableNames().at(GetWorldId()); | 237 return IsolatedWorldHumanReadableNames().at(GetWorldId()); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void DOMWrapperWorld::SetIsolatedWorldHumanReadableName( | 240 void DOMWrapperWorld::SetIsolatedWorldHumanReadableName( |
| 241 int world_id, | 241 int world_id, |
| 242 const String& human_readable_name) { | 242 const String& human_readable_name) { |
| 243 ASSERT(IsIsolatedWorldId(world_id)); | 243 DCHECK(IsIsolatedWorldId(world_id)); |
| 244 IsolatedWorldHumanReadableNames().Set(world_id, human_readable_name); | 244 IsolatedWorldHumanReadableNames().Set(world_id, human_readable_name); |
| 245 } | 245 } |
| 246 | 246 |
| 247 typedef HashMap<int, bool> IsolatedWorldContentSecurityPolicyMap; | 247 typedef HashMap<int, bool> IsolatedWorldContentSecurityPolicyMap; |
| 248 static IsolatedWorldContentSecurityPolicyMap& | 248 static IsolatedWorldContentSecurityPolicyMap& |
| 249 IsolatedWorldContentSecurityPolicies() { | 249 IsolatedWorldContentSecurityPolicies() { |
| 250 ASSERT(IsMainThread()); | 250 DCHECK(IsMainThread()); |
| 251 DEFINE_STATIC_LOCAL(IsolatedWorldContentSecurityPolicyMap, map, ()); | 251 DEFINE_STATIC_LOCAL(IsolatedWorldContentSecurityPolicyMap, map, ()); |
| 252 return map; | 252 return map; |
| 253 } | 253 } |
| 254 | 254 |
| 255 bool DOMWrapperWorld::IsolatedWorldHasContentSecurityPolicy() { | 255 bool DOMWrapperWorld::IsolatedWorldHasContentSecurityPolicy() { |
| 256 ASSERT(this->IsIsolatedWorld()); | 256 DCHECK(this->IsIsolatedWorld()); |
| 257 IsolatedWorldContentSecurityPolicyMap& policies = | 257 IsolatedWorldContentSecurityPolicyMap& policies = |
| 258 IsolatedWorldContentSecurityPolicies(); | 258 IsolatedWorldContentSecurityPolicies(); |
| 259 IsolatedWorldContentSecurityPolicyMap::iterator it = | 259 IsolatedWorldContentSecurityPolicyMap::iterator it = |
| 260 policies.Find(GetWorldId()); | 260 policies.Find(GetWorldId()); |
| 261 return it == policies.end() ? false : it->value; | 261 return it == policies.end() ? false : it->value; |
| 262 } | 262 } |
| 263 | 263 |
| 264 void DOMWrapperWorld::SetIsolatedWorldContentSecurityPolicy( | 264 void DOMWrapperWorld::SetIsolatedWorldContentSecurityPolicy( |
| 265 int world_id, | 265 int world_id, |
| 266 const String& policy) { | 266 const String& policy) { |
| 267 ASSERT(IsIsolatedWorldId(world_id)); | 267 DCHECK(IsIsolatedWorldId(world_id)); |
| 268 if (!policy.IsEmpty()) | 268 if (!policy.IsEmpty()) |
| 269 IsolatedWorldContentSecurityPolicies().Set(world_id, true); | 269 IsolatedWorldContentSecurityPolicies().Set(world_id, true); |
| 270 else | 270 else |
| 271 IsolatedWorldContentSecurityPolicies().erase(world_id); | 271 IsolatedWorldContentSecurityPolicies().erase(world_id); |
| 272 } | 272 } |
| 273 | 273 |
| 274 template <typename T> | 274 template <typename T> |
| 275 void DOMWrapperWorld::RegisterDOMObjectHolder(v8::Isolate* isolate, | 275 void DOMWrapperWorld::RegisterDOMObjectHolder(v8::Isolate* isolate, |
| 276 T* object, | 276 T* object, |
| 277 v8::Local<v8::Value> wrapper) { | 277 v8::Local<v8::Value> wrapper) { |
| 278 RegisterDOMObjectHolderInternal( | 278 RegisterDOMObjectHolderInternal( |
| 279 DOMObjectHolder<T>::Create(isolate, object, wrapper)); | 279 DOMObjectHolder<T>::Create(isolate, object, wrapper)); |
| 280 } | 280 } |
| 281 | 281 |
| 282 template void DOMWrapperWorld::RegisterDOMObjectHolder(v8::Isolate*, | 282 template void DOMWrapperWorld::RegisterDOMObjectHolder(v8::Isolate*, |
| 283 ScriptFunction*, | 283 ScriptFunction*, |
| 284 v8::Local<v8::Value>); | 284 v8::Local<v8::Value>); |
| 285 | 285 |
| 286 void DOMWrapperWorld::RegisterDOMObjectHolderInternal( | 286 void DOMWrapperWorld::RegisterDOMObjectHolderInternal( |
| 287 std::unique_ptr<DOMObjectHolderBase> holder_base) { | 287 std::unique_ptr<DOMObjectHolderBase> holder_base) { |
| 288 ASSERT(!dom_object_holders_.Contains(holder_base.get())); | 288 DCHECK(!dom_object_holders_.Contains(holder_base.get())); |
| 289 holder_base->SetWorld(this); | 289 holder_base->SetWorld(this); |
| 290 holder_base->SetWeak(&DOMWrapperWorld::WeakCallbackForDOMObjectHolder); | 290 holder_base->SetWeak(&DOMWrapperWorld::WeakCallbackForDOMObjectHolder); |
| 291 dom_object_holders_.insert(std::move(holder_base)); | 291 dom_object_holders_.insert(std::move(holder_base)); |
| 292 } | 292 } |
| 293 | 293 |
| 294 void DOMWrapperWorld::UnregisterDOMObjectHolder( | 294 void DOMWrapperWorld::UnregisterDOMObjectHolder( |
| 295 DOMObjectHolderBase* holder_base) { | 295 DOMObjectHolderBase* holder_base) { |
| 296 ASSERT(dom_object_holders_.Contains(holder_base)); | 296 DCHECK(dom_object_holders_.Contains(holder_base)); |
| 297 dom_object_holders_.erase(holder_base); | 297 dom_object_holders_.erase(holder_base); |
| 298 } | 298 } |
| 299 | 299 |
| 300 void DOMWrapperWorld::WeakCallbackForDOMObjectHolder( | 300 void DOMWrapperWorld::WeakCallbackForDOMObjectHolder( |
| 301 const v8::WeakCallbackInfo<DOMObjectHolderBase>& data) { | 301 const v8::WeakCallbackInfo<DOMObjectHolderBase>& data) { |
| 302 DOMObjectHolderBase* holder_base = data.GetParameter(); | 302 DOMObjectHolderBase* holder_base = data.GetParameter(); |
| 303 holder_base->World()->UnregisterDOMObjectHolder(holder_base); | 303 holder_base->World()->UnregisterDOMObjectHolder(holder_base); |
| 304 } | 304 } |
| 305 | 305 |
| 306 int DOMWrapperWorld::GenerateWorldIdForType(WorldType world_type) { | 306 int DOMWrapperWorld::GenerateWorldIdForType(WorldType world_type) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 323 int world_id = *next_world_id; | 323 int world_id = *next_world_id; |
| 324 CHECK_GE(world_id, WorldId::kUnspecifiedWorldIdStart); | 324 CHECK_GE(world_id, WorldId::kUnspecifiedWorldIdStart); |
| 325 *next_world_id = world_id + 1; | 325 *next_world_id = world_id + 1; |
| 326 return world_id; | 326 return world_id; |
| 327 } | 327 } |
| 328 NOTREACHED(); | 328 NOTREACHED(); |
| 329 return kInvalidWorldId; | 329 return kInvalidWorldId; |
| 330 } | 330 } |
| 331 | 331 |
| 332 } // namespace blink | 332 } // namespace blink |
| OLD | NEW |