Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bindings/core/v8/WindowProxyManager.h" | 5 #include "bindings/core/v8/WindowProxyManager.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/DOMWrapperWorld.h" | 7 #include "bindings/core/v8/DOMWrapperWorld.h" |
| 8 | 8 |
| 9 namespace blink { | 9 namespace blink { |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 std::move(world)); | 22 std::move(world)); |
| 23 } | 23 } |
| 24 } | 24 } |
| 25 | 25 |
| 26 DEFINE_TRACE(WindowProxyManagerBase) { | 26 DEFINE_TRACE(WindowProxyManagerBase) { |
| 27 visitor->trace(m_frame); | 27 visitor->trace(m_frame); |
| 28 visitor->trace(m_windowProxy); | 28 visitor->trace(m_windowProxy); |
| 29 visitor->trace(m_isolatedWorlds); | 29 visitor->trace(m_isolatedWorlds); |
| 30 } | 30 } |
| 31 | 31 |
| 32 WindowProxy* WindowProxyManagerBase::windowProxy(DOMWrapperWorld& world) { | |
| 33 WindowProxy* windowProxy = nullptr; | |
| 34 if (world.isMainWorld()) { | |
| 35 windowProxy = m_windowProxy.get(); | |
| 36 } else { | |
| 37 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId()); | |
| 38 if (iter != m_isolatedWorlds.end()) { | |
| 39 windowProxy = iter->value.get(); | |
| 40 } else { | |
| 41 windowProxy = createWindowProxyForFrame(m_isolate, *m_frame, &world); | |
| 42 m_isolatedWorlds.set(world.worldId(), windowProxy); | |
| 43 } | |
| 44 } | |
| 45 return windowProxy; | |
| 46 } | |
| 47 | |
| 48 void WindowProxyManagerBase::clearForClose() { | 32 void WindowProxyManagerBase::clearForClose() { |
| 49 m_windowProxy->clearForClose(); | 33 m_windowProxy->clearForClose(); |
| 50 for (auto& entry : m_isolatedWorlds) | 34 for (auto& entry : m_isolatedWorlds) |
| 51 entry.value->clearForClose(); | 35 entry.value->clearForClose(); |
| 52 } | 36 } |
| 53 | 37 |
| 54 void WindowProxyManagerBase::clearForNavigation() { | 38 void WindowProxyManagerBase::clearForNavigation() { |
| 55 m_windowProxy->clearForNavigation(); | 39 m_windowProxy->clearForNavigation(); |
| 56 for (auto& entry : m_isolatedWorlds) | 40 for (auto& entry : m_isolatedWorlds) |
| 57 entry.value->clearForNavigation(); | 41 entry.value->clearForNavigation(); |
| 58 } | 42 } |
| 59 | 43 |
| 60 void WindowProxyManagerBase::releaseGlobals( | 44 void WindowProxyManagerBase::releaseGlobals( |
| 61 HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>& map) { | 45 HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>& map) { |
| 62 map.add(&m_windowProxy->world(), m_windowProxy->releaseGlobal()); | 46 map.add(&m_windowProxy->world(), m_windowProxy->releaseGlobal()); |
| 63 for (auto& entry : m_isolatedWorlds) | 47 for (auto& entry : m_isolatedWorlds) |
| 64 map.add(&entry.value->world(), | 48 map.add(&entry.value->world(), |
| 65 windowProxy(entry.value->world())->releaseGlobal()); | 49 windowProxy(entry.value->world())->releaseGlobal()); |
|
dcheng
2017/01/13 18:57:30
I missed this in my original patch, but a few test
| |
| 66 } | 50 } |
| 67 | 51 |
| 68 void WindowProxyManagerBase::setGlobals( | 52 void WindowProxyManagerBase::setGlobals( |
| 69 const HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>& map) { | 53 const HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>& map) { |
| 54 // Note: it's important not to initialize the WindowProxy before SetGlobal() | |
| 55 // is called. Otherwise, the global proxy object the WindowProxy thinks it has | |
| 56 // and the global proxy object of any actual v8 contexts will not match! | |
| 70 for (auto& entry : map) | 57 for (auto& entry : map) |
| 71 windowProxy(*entry.key)->setGlobal(entry.value); | 58 possiblyUninitializedWindowProxy(*entry.key)->setGlobal(entry.value); |
| 72 } | 59 } |
| 73 | 60 |
| 74 WindowProxyManagerBase::WindowProxyManagerBase(Frame& frame) | 61 WindowProxyManagerBase::WindowProxyManagerBase(Frame& frame) |
| 75 : m_isolate(v8::Isolate::GetCurrent()), | 62 : m_isolate(v8::Isolate::GetCurrent()), |
| 76 m_frame(&frame), | 63 m_frame(&frame), |
| 77 m_windowProxy(createWindowProxyForFrame(m_isolate, | 64 m_windowProxy(createWindowProxyForFrame(m_isolate, |
| 78 frame, | 65 frame, |
| 79 &DOMWrapperWorld::mainWorld())) {} | 66 &DOMWrapperWorld::mainWorld())) {} |
| 80 | 67 |
| 81 void LocalWindowProxyManager::updateSecurityOrigin( | 68 WindowProxy* WindowProxyManagerBase::windowProxy(DOMWrapperWorld& world) { |
| 82 SecurityOrigin* securityOrigin) { | 69 WindowProxy* windowProxy = possiblyUninitializedWindowProxy(world); |
| 83 static_cast<LocalWindowProxy*>(mainWorldProxy()) | 70 windowProxy->initializeIfNeeded(); |
| 84 ->updateSecurityOrigin(securityOrigin); | 71 return windowProxy; |
| 85 for (auto& entry : isolatedWorlds()) { | 72 } |
| 86 auto* isolatedWindowProxy = | 73 |
| 87 static_cast<LocalWindowProxy*>(entry.value.get()); | 74 WindowProxy* WindowProxyManagerBase::possiblyUninitializedWindowProxy( |
| 88 SecurityOrigin* isolatedSecurityOrigin = | 75 DOMWrapperWorld& world) { |
| 89 isolatedWindowProxy->world().isolatedWorldSecurityOrigin(); | 76 WindowProxy* windowProxy = nullptr; |
| 90 isolatedWindowProxy->updateSecurityOrigin(isolatedSecurityOrigin); | 77 if (world.isMainWorld()) { |
| 78 windowProxy = m_windowProxy.get(); | |
| 79 } else { | |
| 80 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId()); | |
| 81 if (iter != m_isolatedWorlds.end()) { | |
| 82 windowProxy = iter->value.get(); | |
| 83 } else { | |
| 84 windowProxy = createWindowProxyForFrame(m_isolate, *m_frame, &world); | |
| 85 m_isolatedWorlds.set(world.worldId(), windowProxy); | |
| 86 } | |
| 91 } | 87 } |
| 88 return windowProxy; | |
| 92 } | 89 } |
| 93 | 90 |
| 94 } // namespace blink | 91 } // namespace blink |
| OLD | NEW |