OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 #include "bindings/core/v8/WindowProxyManager.h" | |
7 | |
8 #include "bindings/core/v8/DOMWrapperWorld.h" | |
9 #include "bindings/core/v8/WindowProxy.h" | |
10 #include "core/frame/Frame.h" | |
11 | |
12 namespace blink { | |
13 | |
14 PassOwnPtrWillBeRawPtr<WindowProxyManager> WindowProxyManager::create(Frame* fra
me) | |
15 { | |
16 return adoptPtrWillBeNoop(new WindowProxyManager(frame)); | |
17 } | |
18 | |
19 WindowProxyManager::~WindowProxyManager() | |
20 { | |
21 } | |
22 | |
23 void WindowProxyManager::trace(Visitor* visitor) | |
24 { | |
25 #if ENABLE(OILPAN) | |
26 visitor->trace(m_frame); | |
27 visitor->trace(m_windowProxy); | |
28 visitor->trace(m_isolatedWorlds); | |
29 #endif | |
30 } | |
31 | |
32 WindowProxy* WindowProxyManager::windowProxy(DOMWrapperWorld& world) | |
33 { | |
34 WindowProxy* windowProxy = nullptr; | |
35 if (world.isMainWorld()) { | |
36 windowProxy = m_windowProxy.get(); | |
37 } else { | |
38 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId())
; | |
39 if (iter != m_isolatedWorlds.end()) { | |
40 windowProxy = iter->value.get(); | |
41 } else { | |
42 OwnPtrWillBeRawPtr<WindowProxy> isolatedWorldWindowProxy = WindowPro
xy::create(m_frame, world, m_isolate); | |
43 windowProxy = isolatedWorldWindowProxy.get(); | |
44 m_isolatedWorlds.set(world.worldId(), isolatedWorldWindowProxy.relea
se()); | |
45 } | |
46 } | |
47 return windowProxy; | |
48 } | |
49 | |
50 void WindowProxyManager::clearForClose() | |
51 { | |
52 m_windowProxy->clearForClose(); | |
53 for (auto& entry : m_isolatedWorlds) | |
54 entry.value->clearForClose(); | |
55 } | |
56 | |
57 void WindowProxyManager::clearForNavigation() | |
58 { | |
59 m_windowProxy->clearForNavigation(); | |
60 for (auto& entry : m_isolatedWorlds) | |
61 entry.value->clearForNavigation(); | |
62 } | |
63 | |
64 WindowProxy* WindowProxyManager::existingWindowProxy(DOMWrapperWorld& world) | |
65 { | |
66 if (world.isMainWorld()) | |
67 return m_windowProxy->isContextInitialized() ? m_windowProxy.get() : nul
lptr; | |
68 | |
69 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId()); | |
70 if (iter == m_isolatedWorlds.end()) | |
71 return nullptr; | |
72 return iter->value->isContextInitialized() ? iter->value.get() : nullptr; | |
73 } | |
74 | |
75 void WindowProxyManager::collectIsolatedContexts(Vector<std::pair<ScriptState*,
SecurityOrigin*>>& result) | |
76 { | |
77 for (auto& entry : m_isolatedWorlds) { | |
78 WindowProxy* isolatedWorldWindowProxy = entry.value.get(); | |
79 SecurityOrigin* origin = isolatedWorldWindowProxy->world().isolatedWorld
SecurityOrigin(); | |
80 if (!isolatedWorldWindowProxy->isContextInitialized()) | |
81 continue; | |
82 result.append(std::make_pair(isolatedWorldWindowProxy->scriptState(), or
igin)); | |
83 } | |
84 } | |
85 | |
86 void WindowProxyManager::setWorldDebugId(int worldId, int debuggerId) | |
87 { | |
88 ASSERT(debuggerId > 0); | |
89 bool isMainWorld = worldId == MainWorldId; | |
90 WindowProxy* windowProxy = nullptr; | |
91 if (isMainWorld) { | |
92 windowProxy = m_windowProxy.get(); | |
93 } else { | |
94 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(worldId); | |
95 if (iter != m_isolatedWorlds.end()) | |
96 windowProxy = iter->value.get(); | |
97 } | |
98 if (!windowProxy || !windowProxy->isContextInitialized()) | |
99 return; | |
100 v8::HandleScope scope(m_isolate); | |
101 v8::Local<v8::Context> context = windowProxy->context(); | |
102 const char* worldName = isMainWorld ? "page" : "injected"; | |
103 V8PerContextDebugData::setContextDebugData(context, worldName, debuggerId); | |
104 } | |
105 | |
106 WindowProxyManager::WindowProxyManager(Frame* frame) | |
107 : m_frame(frame) | |
108 , m_isolate(v8::Isolate::GetCurrent()) | |
109 , m_windowProxy(WindowProxy::create(frame, DOMWrapperWorld::mainWorld(), m_i
solate)) | |
110 { | |
111 } | |
112 | |
113 } // namespace blink | |
OLD | NEW |