| 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 29 matching lines...) Expand all Loading... |
| 40 #include "sky/engine/bindings/core/v8/WrapperTypeInfo.h" | 40 #include "sky/engine/bindings/core/v8/WrapperTypeInfo.h" |
| 41 #include "sky/engine/core/dom/ExecutionContext.h" | 41 #include "sky/engine/core/dom/ExecutionContext.h" |
| 42 #include "sky/engine/wtf/HashTraits.h" | 42 #include "sky/engine/wtf/HashTraits.h" |
| 43 #include "sky/engine/wtf/StdLibExtras.h" | 43 #include "sky/engine/wtf/StdLibExtras.h" |
| 44 | 44 |
| 45 namespace blink { | 45 namespace blink { |
| 46 | 46 |
| 47 unsigned DOMWrapperWorld::isolatedWorldCount = 0; | 47 unsigned DOMWrapperWorld::isolatedWorldCount = 0; |
| 48 DOMWrapperWorld* DOMWrapperWorld::worldOfInitializingWindow = 0; | 48 DOMWrapperWorld* DOMWrapperWorld::worldOfInitializingWindow = 0; |
| 49 | 49 |
| 50 PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::create(int worldId, int extensionGr
oup) | 50 PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::create(FakeWorldMarker marker) |
| 51 { | 51 { |
| 52 return adoptRef(new DOMWrapperWorld(worldId, extensionGroup)); | 52 return adoptRef(new DOMWrapperWorld(marker)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 DOMWrapperWorld::DOMWrapperWorld(int worldId, int extensionGroup) | 55 DOMWrapperWorld::DOMWrapperWorld(FakeWorldMarker marker) |
| 56 : m_worldId(worldId) | 56 : m_isFakeWorld(marker == FakeWorld) |
| 57 , m_extensionGroup(extensionGroup) | |
| 58 , m_domDataStore(adoptPtr(new DOMDataStore(isMainWorld()))) | 57 , m_domDataStore(adoptPtr(new DOMDataStore(isMainWorld()))) |
| 59 { | 58 { |
| 60 } | 59 } |
| 61 | 60 |
| 62 DOMWrapperWorld& DOMWrapperWorld::mainWorld() | 61 DOMWrapperWorld& DOMWrapperWorld::mainWorld() |
| 63 { | 62 { |
| 64 ASSERT(isMainThread()); | 63 ASSERT(isMainThread()); |
| 65 DEFINE_STATIC_REF(DOMWrapperWorld, cachedMainWorld, (DOMWrapperWorld::create
(MainWorldId, mainWorldExtensionGroup))); | 64 DEFINE_STATIC_REF(DOMWrapperWorld, cachedMainWorld, (DOMWrapperWorld::create
(MainWorld))); |
| 66 return *cachedMainWorld; | 65 return *cachedMainWorld; |
| 67 } | 66 } |
| 68 | 67 |
| 69 typedef HashMap<int, DOMWrapperWorld*> WorldMap; | |
| 70 static WorldMap& isolatedWorldMap() | |
| 71 { | |
| 72 ASSERT(isMainThread()); | |
| 73 DEFINE_STATIC_LOCAL(WorldMap, map, ()); | |
| 74 return map; | |
| 75 } | |
| 76 | |
| 77 void DOMWrapperWorld::allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld> >& wo
rlds) | |
| 78 { | |
| 79 ASSERT(isMainThread()); | |
| 80 worlds.append(&mainWorld()); | |
| 81 WorldMap& isolatedWorlds = isolatedWorldMap(); | |
| 82 for (WorldMap::iterator it = isolatedWorlds.begin(); it != isolatedWorlds.en
d(); ++it) | |
| 83 worlds.append(it->value); | |
| 84 } | |
| 85 | |
| 86 DOMWrapperWorld::~DOMWrapperWorld() | 68 DOMWrapperWorld::~DOMWrapperWorld() |
| 87 { | 69 { |
| 88 ASSERT(!isMainWorld()); | 70 ASSERT(!isMainWorld()); |
| 89 | 71 |
| 90 dispose(); | 72 dispose(); |
| 91 | |
| 92 if (!isIsolatedWorld()) | |
| 93 return; | |
| 94 | |
| 95 WorldMap& map = isolatedWorldMap(); | |
| 96 WorldMap::iterator it = map.find(m_worldId); | |
| 97 if (it == map.end()) { | |
| 98 ASSERT_NOT_REACHED(); | |
| 99 return; | |
| 100 } | |
| 101 ASSERT(it->value == this); | |
| 102 | |
| 103 map.remove(it); | |
| 104 isolatedWorldCount--; | |
| 105 } | 73 } |
| 106 | 74 |
| 107 void DOMWrapperWorld::dispose() | 75 void DOMWrapperWorld::dispose() |
| 108 { | 76 { |
| 109 m_domObjectHolders.clear(); | 77 m_domObjectHolders.clear(); |
| 110 m_domDataStore.clear(); | 78 m_domDataStore.clear(); |
| 111 } | 79 } |
| 112 | 80 |
| 113 #if ENABLE(ASSERT) | |
| 114 static bool isIsolatedWorldId(int worldId) | |
| 115 { | |
| 116 return MainWorldId < worldId && worldId < IsolatedWorldIdLimit; | |
| 117 } | |
| 118 #endif | |
| 119 | |
| 120 PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::ensureIsolatedWorld(int worldId, in
t extensionGroup) | |
| 121 { | |
| 122 ASSERT(isIsolatedWorldId(worldId)); | |
| 123 | |
| 124 WorldMap& map = isolatedWorldMap(); | |
| 125 WorldMap::AddResult result = map.add(worldId, 0); | |
| 126 RefPtr<DOMWrapperWorld> world = result.storedValue->value; | |
| 127 if (world) { | |
| 128 ASSERT(world->worldId() == worldId); | |
| 129 ASSERT(world->extensionGroup() == extensionGroup); | |
| 130 return world.release(); | |
| 131 } | |
| 132 | |
| 133 world = DOMWrapperWorld::create(worldId, extensionGroup); | |
| 134 result.storedValue->value = world.get(); | |
| 135 isolatedWorldCount++; | |
| 136 return world.release(); | |
| 137 } | |
| 138 | |
| 139 typedef HashMap<int, String > IsolatedWorldHumanReadableNameMap; | |
| 140 static IsolatedWorldHumanReadableNameMap& isolatedWorldHumanReadableNames() | |
| 141 { | |
| 142 ASSERT(isMainThread()); | |
| 143 DEFINE_STATIC_LOCAL(IsolatedWorldHumanReadableNameMap, map, ()); | |
| 144 return map; | |
| 145 } | |
| 146 | |
| 147 String DOMWrapperWorld::isolatedWorldHumanReadableName() | |
| 148 { | |
| 149 ASSERT(this->isIsolatedWorld()); | |
| 150 return isolatedWorldHumanReadableNames().get(worldId()); | |
| 151 } | |
| 152 | |
| 153 void DOMWrapperWorld::setIsolatedWorldHumanReadableName(int worldId, const Strin
g& humanReadableName) | |
| 154 { | |
| 155 ASSERT(isIsolatedWorldId(worldId)); | |
| 156 isolatedWorldHumanReadableNames().set(worldId, humanReadableName); | |
| 157 } | |
| 158 | |
| 159 void DOMWrapperWorld::registerDOMObjectHolderInternal(PassOwnPtr<DOMObjectHolder
Base> holderBase) | 81 void DOMWrapperWorld::registerDOMObjectHolderInternal(PassOwnPtr<DOMObjectHolder
Base> holderBase) |
| 160 { | 82 { |
| 161 ASSERT(!m_domObjectHolders.contains(holderBase.get())); | 83 ASSERT(!m_domObjectHolders.contains(holderBase.get())); |
| 162 holderBase->setWorld(this); | 84 holderBase->setWorld(this); |
| 163 holderBase->setWeak(&DOMWrapperWorld::weakCallbackForDOMObjectHolder); | 85 holderBase->setWeak(&DOMWrapperWorld::weakCallbackForDOMObjectHolder); |
| 164 m_domObjectHolders.add(holderBase); | 86 m_domObjectHolders.add(holderBase); |
| 165 } | 87 } |
| 166 | 88 |
| 167 void DOMWrapperWorld::unregisterDOMObjectHolder(DOMObjectHolderBase* holderBase) | 89 void DOMWrapperWorld::unregisterDOMObjectHolder(DOMObjectHolderBase* holderBase) |
| 168 { | 90 { |
| 169 ASSERT(m_domObjectHolders.contains(holderBase)); | 91 ASSERT(m_domObjectHolders.contains(holderBase)); |
| 170 m_domObjectHolders.remove(holderBase); | 92 m_domObjectHolders.remove(holderBase); |
| 171 } | 93 } |
| 172 | 94 |
| 173 void DOMWrapperWorld::weakCallbackForDOMObjectHolder(const v8::WeakCallbackData<
v8::Value, DOMObjectHolderBase>& data) | 95 void DOMWrapperWorld::weakCallbackForDOMObjectHolder(const v8::WeakCallbackData<
v8::Value, DOMObjectHolderBase>& data) |
| 174 { | 96 { |
| 175 DOMObjectHolderBase* holderBase = data.GetParameter(); | 97 DOMObjectHolderBase* holderBase = data.GetParameter(); |
| 176 holderBase->world()->unregisterDOMObjectHolder(holderBase); | 98 holderBase->world()->unregisterDOMObjectHolder(holderBase); |
| 177 } | 99 } |
| 178 | 100 |
| 179 } // namespace blink | 101 } // namespace blink |
| OLD | NEW |