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 namespace { |
12 | 12 |
13 WindowProxy* createWindowProxyForFrame(v8::Isolate* isolate, | 13 WindowProxy* createWindowProxyForFrame(v8::Isolate* isolate, |
14 Frame& frame, | 14 Frame& frame, |
15 | |
16 RefPtr<DOMWrapperWorld> world) { | 15 RefPtr<DOMWrapperWorld> world) { |
17 if (frame.isLocalFrame()) { | 16 if (frame.isLocalFrame()) { |
18 return LocalWindowProxy::create(isolate, toLocalFrame(frame), | 17 return LocalWindowProxy::create(isolate, toLocalFrame(frame), |
19 std::move(world)); | 18 std::move(world)); |
20 } | 19 } |
21 return RemoteWindowProxy::create(isolate, toRemoteFrame(frame), | 20 return RemoteWindowProxy::create(isolate, toRemoteFrame(frame), |
22 std::move(world)); | 21 std::move(world)); |
23 } | 22 } |
24 } | |
25 | 23 |
26 DEFINE_TRACE(WindowProxyManagerBase) { | 24 } // namespace |
25 | |
26 DEFINE_TRACE(WindowProxyManager) { | |
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) { | 32 void WindowProxyManager::clearForClose() { |
33 m_windowProxy->clearForClose(); | |
34 for (auto& entry : m_isolatedWorlds) | |
35 entry.value->clearForClose(); | |
36 } | |
37 | |
38 void WindowProxyManager::clearForNavigation() { | |
39 m_windowProxy->clearForNavigation(); | |
40 for (auto& entry : m_isolatedWorlds) | |
41 entry.value->clearForNavigation(); | |
42 } | |
43 | |
44 void WindowProxyManager::releaseGlobals( | |
45 HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>& map) { | |
46 map.insert(&m_windowProxy->world(), m_windowProxy->releaseGlobal()); | |
47 for (auto& entry : m_isolatedWorlds) { | |
48 map.insert( | |
49 &entry.value->world(), | |
50 windowProxyMaybeUninitialized(entry.value->world())->releaseGlobal()); | |
51 } | |
52 } | |
53 | |
54 void WindowProxyManager::setGlobals( | |
55 const HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>& map) { | |
56 for (auto& entry : map) | |
57 windowProxyMaybeUninitialized(*entry.key)->setGlobal(entry.value); | |
58 } | |
59 | |
60 WindowProxyManager::WindowProxyManager(Frame& frame) | |
61 : m_isolate(v8::Isolate::GetCurrent()), | |
haraken
2017/03/10 12:44:12
toIsolate(frame).
Avoid using v8::Isolate::GetCur
Yuki
2017/03/10 15:21:50
blink::toIsolate(frame) is returning the frame's W
haraken
2017/03/11 19:35:24
Can we explicitly pass in the Isolate* parameter?
Yuki
2017/03/13 08:24:30
Currently, the call sites don't have an Isolate.
| |
62 m_frame(&frame), | |
63 m_windowProxy(createWindowProxyForFrame(m_isolate, | |
64 *m_frame, | |
65 &DOMWrapperWorld::mainWorld())) {} | |
66 | |
67 WindowProxy* WindowProxyManager::windowProxyMaybeUninitialized( | |
68 DOMWrapperWorld& world) { | |
33 WindowProxy* windowProxy = nullptr; | 69 WindowProxy* windowProxy = nullptr; |
34 if (world.isMainWorld()) { | 70 if (world.isMainWorld()) { |
35 windowProxy = m_windowProxy.get(); | 71 windowProxy = m_windowProxy.get(); |
36 } else { | 72 } else { |
37 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId()); | 73 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId()); |
38 if (iter != m_isolatedWorlds.end()) { | 74 if (iter != m_isolatedWorlds.end()) { |
39 windowProxy = iter->value.get(); | 75 windowProxy = iter->value.get(); |
40 } else { | 76 } else { |
41 windowProxy = createWindowProxyForFrame(m_isolate, *m_frame, &world); | 77 windowProxy = createWindowProxyForFrame(m_isolate, *m_frame, &world); |
42 m_isolatedWorlds.set(world.worldId(), windowProxy); | 78 m_isolatedWorlds.set(world.worldId(), windowProxy); |
43 } | 79 } |
44 } | 80 } |
45 return windowProxy; | 81 return windowProxy; |
46 } | 82 } |
47 | 83 |
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( | |
61 HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>& map) { | |
62 map.insert(&m_windowProxy->world(), m_windowProxy->releaseGlobal()); | |
63 for (auto& entry : m_isolatedWorlds) | |
64 map.insert(&entry.value->world(), | |
65 windowProxy(entry.value->world())->releaseGlobal()); | |
66 } | |
67 | |
68 void WindowProxyManagerBase::setGlobals( | |
69 const HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>& map) { | |
70 for (auto& entry : map) | |
71 windowProxy(*entry.key)->setGlobal(entry.value); | |
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( | 84 void LocalWindowProxyManager::updateSecurityOrigin( |
82 SecurityOrigin* securityOrigin) { | 85 SecurityOrigin* securityOrigin) { |
83 static_cast<LocalWindowProxy*>(mainWorldProxy()) | 86 static_cast<LocalWindowProxy*>(m_windowProxy.get()) |
84 ->updateSecurityOrigin(securityOrigin); | 87 ->updateSecurityOrigin(securityOrigin); |
85 for (auto& entry : isolatedWorlds()) { | 88 |
89 for (auto& entry : m_isolatedWorlds) { | |
86 auto* isolatedWindowProxy = | 90 auto* isolatedWindowProxy = |
87 static_cast<LocalWindowProxy*>(entry.value.get()); | 91 static_cast<LocalWindowProxy*>(entry.value.get()); |
88 SecurityOrigin* isolatedSecurityOrigin = | 92 SecurityOrigin* isolatedSecurityOrigin = |
89 isolatedWindowProxy->world().isolatedWorldSecurityOrigin(); | 93 isolatedWindowProxy->world().isolatedWorldSecurityOrigin(); |
90 isolatedWindowProxy->updateSecurityOrigin(isolatedSecurityOrigin); | 94 isolatedWindowProxy->updateSecurityOrigin(isolatedSecurityOrigin); |
91 } | 95 } |
92 } | 96 } |
93 | 97 |
94 } // namespace blink | 98 } // namespace blink |
OLD | NEW |