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 } | 23 } |
25 | 24 |
26 DEFINE_TRACE(WindowProxyManagerBase) { | 25 DEFINE_TRACE(WindowProxyManagerBase) { |
27 visitor->trace(m_frame); | 26 visitor->trace(m_frame); |
28 visitor->trace(m_windowProxy); | 27 visitor->trace(m_windowProxy); |
29 visitor->trace(m_isolatedWorlds); | 28 visitor->trace(m_isolatedWorlds); |
30 } | 29 } |
31 | 30 |
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() { | 31 void WindowProxyManagerBase::clearForClose() { |
49 m_windowProxy->clearForClose(); | 32 m_windowProxy->clearForClose(); |
50 for (auto& entry : m_isolatedWorlds) | 33 for (auto& entry : m_isolatedWorlds) |
51 entry.value->clearForClose(); | 34 entry.value->clearForClose(); |
52 } | 35 } |
53 | 36 |
54 void WindowProxyManagerBase::clearForNavigation() { | 37 void WindowProxyManagerBase::clearForNavigation() { |
55 m_windowProxy->clearForNavigation(); | 38 m_windowProxy->clearForNavigation(); |
56 for (auto& entry : m_isolatedWorlds) | 39 for (auto& entry : m_isolatedWorlds) |
57 entry.value->clearForNavigation(); | 40 entry.value->clearForNavigation(); |
58 } | 41 } |
59 | 42 |
60 void WindowProxyManagerBase::releaseGlobals( | 43 void WindowProxyManagerBase::releaseGlobals( |
61 HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>& map) { | 44 HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>& map) { |
62 map.add(&m_windowProxy->world(), m_windowProxy->releaseGlobal()); | 45 map.add(&m_windowProxy->world(), m_windowProxy->releaseGlobal()); |
63 for (auto& entry : m_isolatedWorlds) | 46 for (auto& entry : m_isolatedWorlds) |
64 map.add(&entry.value->world(), | 47 map.add(&entry.value->world(), entry.value->releaseGlobal()); |
65 windowProxy(entry.value->world())->releaseGlobal()); | |
66 } | 48 } |
67 | 49 |
68 void WindowProxyManagerBase::setGlobals( | 50 void WindowProxyManagerBase::setGlobals( |
69 const HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>& map) { | 51 const HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>& map) { |
| 52 // Note: it's important not to initialize the WindowProxy before SetGlobal() |
| 53 // is called. Otherwise, the global proxy object the WindowProxy thinks it has |
| 54 // and the global proxy object of any actual v8 contexts will not match! |
70 for (auto& entry : map) | 55 for (auto& entry : map) |
71 windowProxy(*entry.key)->setGlobal(entry.value); | 56 possiblyUninitializedWindowProxy(*entry.key)->setGlobal(entry.value); |
72 } | 57 } |
73 | 58 |
74 WindowProxyManagerBase::WindowProxyManagerBase(Frame& frame) | 59 WindowProxyManagerBase::WindowProxyManagerBase(Frame& frame) |
75 : m_isolate(v8::Isolate::GetCurrent()), | 60 : m_isolate(v8::Isolate::GetCurrent()), |
76 m_frame(&frame), | 61 m_frame(&frame), |
77 m_windowProxy(createWindowProxyForFrame(m_isolate, | 62 m_windowProxy(createWindowProxyForFrame(m_isolate, |
78 frame, | 63 frame, |
79 &DOMWrapperWorld::mainWorld())) {} | 64 &DOMWrapperWorld::mainWorld())) {} |
80 | 65 |
81 void LocalWindowProxyManager::updateSecurityOrigin( | 66 WindowProxy* WindowProxyManagerBase::windowProxy(DOMWrapperWorld& world) { |
82 SecurityOrigin* securityOrigin) { | 67 WindowProxy* windowProxy = possiblyUninitializedWindowProxy(world); |
83 static_cast<LocalWindowProxy*>(mainWorldProxy()) | 68 windowProxy->initializeIfNeeded(); |
84 ->updateSecurityOrigin(securityOrigin); | 69 return windowProxy; |
85 for (auto& entry : isolatedWorlds()) { | 70 } |
86 auto* isolatedWindowProxy = | 71 |
87 static_cast<LocalWindowProxy*>(entry.value.get()); | 72 WindowProxy* WindowProxyManagerBase::possiblyUninitializedWindowProxy( |
88 SecurityOrigin* isolatedSecurityOrigin = | 73 DOMWrapperWorld& world) { |
89 isolatedWindowProxy->world().isolatedWorldSecurityOrigin(); | 74 WindowProxy* windowProxy = nullptr; |
90 isolatedWindowProxy->updateSecurityOrigin(isolatedSecurityOrigin); | 75 if (world.isMainWorld()) { |
| 76 windowProxy = m_windowProxy.get(); |
| 77 } else { |
| 78 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId()); |
| 79 if (iter != m_isolatedWorlds.end()) { |
| 80 windowProxy = iter->value.get(); |
| 81 } else { |
| 82 windowProxy = createWindowProxyForFrame(m_isolate, *m_frame, &world); |
| 83 m_isolatedWorlds.set(world.worldId(), windowProxy); |
| 84 } |
91 } | 85 } |
| 86 return windowProxy; |
92 } | 87 } |
93 | 88 |
94 } // namespace blink | 89 } // namespace blink |
OLD | NEW |