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 |
| 11 namespace { | 11 DEFINE_TRACE(WindowProxyManager) { |
| 12 | |
| 13 WindowProxy* createWindowProxyForFrame(v8::Isolate* isolate, | |
| 14 Frame& frame, | |
| 15 | |
| 16 RefPtr<DOMWrapperWorld> world) { | |
| 17 if (frame.isLocalFrame()) { | |
| 18 return LocalWindowProxy::create(isolate, toLocalFrame(frame), | |
| 19 std::move(world)); | |
| 20 } | |
| 21 return RemoteWindowProxy::create(isolate, toRemoteFrame(frame), | |
| 22 std::move(world)); | |
| 23 } | |
| 24 } | |
| 25 | |
| 26 DEFINE_TRACE(WindowProxyManagerBase) { | |
| 27 visitor->trace(m_frame); | 12 visitor->trace(m_frame); |
| 28 visitor->trace(m_windowProxy); | 13 visitor->trace(m_windowProxy); |
| 29 visitor->trace(m_isolatedWorlds); | 14 visitor->trace(m_isolatedWorlds); |
| 30 } | 15 } |
| 31 | 16 |
| 32 WindowProxy* WindowProxyManagerBase::windowProxy(DOMWrapperWorld& world) { | 17 void WindowProxyManager::clearForClose() { |
| 18 m_windowProxy->clearForClose(); | |
| 19 for (auto& entry : m_isolatedWorlds) | |
| 20 entry.value->clearForClose(); | |
| 21 } | |
| 22 | |
| 23 void WindowProxyManager::clearForNavigation() { | |
| 24 m_windowProxy->clearForNavigation(); | |
| 25 for (auto& entry : m_isolatedWorlds) | |
| 26 entry.value->clearForNavigation(); | |
| 27 } | |
| 28 | |
| 29 void WindowProxyManager::releaseGlobals(GlobalsVector& globals) { | |
| 30 globals.reserveInitialCapacity(1 + m_isolatedWorlds.size()); | |
| 31 globals.emplace_back(&m_windowProxy->world(), m_windowProxy->releaseGlobal()); | |
| 32 for (auto& entry : m_isolatedWorlds) { | |
| 33 globals.emplace_back( | |
| 34 &entry.value->world(), | |
| 35 windowProxyMaybeUninitialized(entry.value->world())->releaseGlobal()); | |
| 36 } | |
| 37 } | |
| 38 | |
| 39 void WindowProxyManager::setGlobals(const GlobalsVector& globals) { | |
| 40 for (const auto& entry : globals) | |
| 41 windowProxyMaybeUninitialized(*entry.first)->setGlobal(entry.second); | |
| 42 } | |
| 43 | |
| 44 WindowProxyManager::WindowProxyManager(Frame& frame, FrameType frameType) | |
| 45 : m_isolate(v8::Isolate::GetCurrent()), | |
| 46 m_frame(&frame), | |
| 47 m_frameType(frameType), | |
| 48 m_windowProxy(createWindowProxy(DOMWrapperWorld::mainWorld())) {} | |
| 49 | |
| 50 WindowProxy* WindowProxyManager::createWindowProxy(DOMWrapperWorld& world) { | |
| 51 switch (m_frameType) { | |
| 52 case FrameType::Local: | |
| 53 // Directly use static_cast instead of toLocalFrame because | |
| 54 // WindowProxyManager gets instantiated during a construction of | |
| 55 // LocalFrame and at that time virtual member functions are not yet | |
| 56 // available (we cannot use LocalFrame::isLocalFrame). Ditto for | |
| 57 // RemoteFrame. | |
|
dcheng
2017/03/16 08:43:16
This makes me a little nervous: I remember hitting
Yuki
2017/03/16 12:41:21
I personally prefer making Frame::m_windowProxyMan
| |
| 58 return LocalWindowProxy::create( | |
| 59 m_isolate, *static_cast<LocalFrame*>(m_frame.get()), &world); | |
| 60 case FrameType::Remote: | |
| 61 return RemoteWindowProxy::create( | |
| 62 m_isolate, *static_cast<RemoteFrame*>(m_frame.get()), &world); | |
| 63 } | |
| 64 NOTREACHED(); | |
| 65 return nullptr; | |
| 66 } | |
| 67 | |
| 68 WindowProxy* WindowProxyManager::windowProxyMaybeUninitialized( | |
| 69 DOMWrapperWorld& world) { | |
| 33 WindowProxy* windowProxy = nullptr; | 70 WindowProxy* windowProxy = nullptr; |
| 34 if (world.isMainWorld()) { | 71 if (world.isMainWorld()) { |
| 35 windowProxy = m_windowProxy.get(); | 72 windowProxy = m_windowProxy.get(); |
| 36 } else { | 73 } else { |
| 37 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId()); | 74 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId()); |
| 38 if (iter != m_isolatedWorlds.end()) { | 75 if (iter != m_isolatedWorlds.end()) { |
| 39 windowProxy = iter->value.get(); | 76 windowProxy = iter->value.get(); |
| 40 } else { | 77 } else { |
| 41 windowProxy = createWindowProxyForFrame(m_isolate, *m_frame, &world); | 78 windowProxy = createWindowProxy(world); |
| 42 m_isolatedWorlds.set(world.worldId(), windowProxy); | 79 m_isolatedWorlds.set(world.worldId(), windowProxy); |
| 43 } | 80 } |
| 44 } | 81 } |
| 45 return windowProxy; | 82 return windowProxy; |
| 46 } | 83 } |
| 47 | 84 |
| 48 void WindowProxyManagerBase::clearForClose() { | |
| 49 m_windowProxy->clearForClose(); | |
| 50 for (auto& entry : m_isolatedWorlds) | |
| 51 entry.value->clearForClose(); | |
| 52 } | |
| 53 | |
| 54 void WindowProxyManagerBase::clearForNavigation() { | |
| 55 m_windowProxy->clearForNavigation(); | |
| 56 for (auto& entry : m_isolatedWorlds) | |
| 57 entry.value->clearForNavigation(); | |
| 58 } | |
| 59 | |
| 60 void WindowProxyManagerBase::releaseGlobals(GlobalsVector& globals) { | |
| 61 globals.reserveInitialCapacity(1 + m_isolatedWorlds.size()); | |
| 62 globals.emplace_back(&m_windowProxy->world(), m_windowProxy->releaseGlobal()); | |
| 63 for (auto& entry : m_isolatedWorlds) { | |
| 64 globals.emplace_back(&entry.value->world(), | |
| 65 windowProxy(entry.value->world())->releaseGlobal()); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 void WindowProxyManagerBase::setGlobals(const GlobalsVector& globals) { | |
| 70 for (const auto& entry : globals) | |
| 71 windowProxy(*entry.first)->setGlobal(entry.second); | |
| 72 } | |
| 73 | |
| 74 WindowProxyManagerBase::WindowProxyManagerBase(Frame& frame) | |
| 75 : m_isolate(v8::Isolate::GetCurrent()), | |
| 76 m_frame(&frame), | |
| 77 m_windowProxy(createWindowProxyForFrame(m_isolate, | |
| 78 frame, | |
| 79 &DOMWrapperWorld::mainWorld())) {} | |
| 80 | |
| 81 void LocalWindowProxyManager::updateSecurityOrigin( | 85 void LocalWindowProxyManager::updateSecurityOrigin( |
| 82 SecurityOrigin* securityOrigin) { | 86 SecurityOrigin* securityOrigin) { |
| 83 static_cast<LocalWindowProxy*>(mainWorldProxy()) | 87 static_cast<LocalWindowProxy*>(m_windowProxy.get()) |
| 84 ->updateSecurityOrigin(securityOrigin); | 88 ->updateSecurityOrigin(securityOrigin); |
| 85 for (auto& entry : isolatedWorlds()) { | 89 |
| 90 for (auto& entry : m_isolatedWorlds) { | |
| 86 auto* isolatedWindowProxy = | 91 auto* isolatedWindowProxy = |
| 87 static_cast<LocalWindowProxy*>(entry.value.get()); | 92 static_cast<LocalWindowProxy*>(entry.value.get()); |
| 88 SecurityOrigin* isolatedSecurityOrigin = | 93 SecurityOrigin* isolatedSecurityOrigin = |
| 89 isolatedWindowProxy->world().isolatedWorldSecurityOrigin(); | 94 isolatedWindowProxy->world().isolatedWorldSecurityOrigin(); |
| 90 isolatedWindowProxy->updateSecurityOrigin(isolatedSecurityOrigin); | 95 isolatedWindowProxy->updateSecurityOrigin(isolatedSecurityOrigin); |
| 91 } | 96 } |
| 92 } | 97 } |
| 93 | 98 |
| 94 } // namespace blink | 99 } // namespace blink |
| OLD | NEW |