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 #ifndef WindowProxyManager_h | 5 #ifndef WindowProxyManager_h |
6 #define WindowProxyManager_h | 6 #define WindowProxyManager_h |
7 | 7 |
| 8 #include "bindings/core/v8/LocalWindowProxy.h" |
| 9 #include "bindings/core/v8/RemoteWindowProxy.h" |
8 #include "core/CoreExport.h" | 10 #include "core/CoreExport.h" |
| 11 #include "core/frame/LocalFrame.h" |
| 12 #include "core/frame/RemoteFrame.h" |
9 #include "platform/heap/Handle.h" | 13 #include "platform/heap/Handle.h" |
10 #include "wtf/Vector.h" | |
11 #include <utility> | 14 #include <utility> |
12 #include <v8.h> | 15 #include <v8.h> |
13 | 16 |
14 namespace blink { | 17 namespace blink { |
15 | 18 |
16 class DOMWrapperWorld; | 19 class DOMWrapperWorld; |
17 class Frame; | |
18 class SecurityOrigin; | 20 class SecurityOrigin; |
19 class WindowProxy; | 21 class ScriptController; |
20 | 22 |
21 class CORE_EXPORT WindowProxyManager final | 23 class WindowProxyManagerBase : public GarbageCollected<WindowProxyManagerBase> { |
22 : public GarbageCollected<WindowProxyManager> { | |
23 public: | 24 public: |
24 static WindowProxyManager* create(Frame&); | |
25 | |
26 DECLARE_TRACE(); | 25 DECLARE_TRACE(); |
27 | 26 |
28 Frame* frame() const { return m_frame.get(); } | |
29 v8::Isolate* isolate() const { return m_isolate; } | 27 v8::Isolate* isolate() const { return m_isolate; } |
| 28 |
| 29 void clearForClose(); |
| 30 void CORE_EXPORT clearForNavigation(); |
| 31 |
| 32 void CORE_EXPORT |
| 33 releaseGlobals(HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&); |
| 34 void CORE_EXPORT |
| 35 setGlobals(const HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&); |
| 36 |
| 37 protected: |
| 38 using IsolatedWorldMap = HeapHashMap<int, Member<WindowProxy>>; |
| 39 |
| 40 explicit WindowProxyManagerBase(Frame&); |
| 41 |
| 42 Frame* frame() const { return m_frame; } |
30 WindowProxy* mainWorldProxy() const { return m_windowProxy.get(); } | 43 WindowProxy* mainWorldProxy() const { return m_windowProxy.get(); } |
31 | |
32 WindowProxy* windowProxy(DOMWrapperWorld&); | 44 WindowProxy* windowProxy(DOMWrapperWorld&); |
33 | 45 |
34 void clearForClose(); | 46 IsolatedWorldMap& isolatedWorlds() { return m_isolatedWorlds; } |
35 void clearForNavigation(); | 47 |
| 48 private: |
| 49 v8::Isolate* const m_isolate; |
| 50 const Member<Frame> m_frame; |
| 51 const Member<WindowProxy> m_windowProxy; |
| 52 IsolatedWorldMap m_isolatedWorlds; |
| 53 }; |
| 54 |
| 55 template <typename FrameType, typename ProxyType> |
| 56 class WindowProxyManagerImplHelper : public WindowProxyManagerBase { |
| 57 private: |
| 58 using Base = WindowProxyManagerBase; |
| 59 |
| 60 public: |
| 61 FrameType* frame() const { return static_cast<FrameType*>(Base::frame()); } |
| 62 ProxyType* mainWorldProxy() const { |
| 63 return static_cast<ProxyType*>(Base::mainWorldProxy()); |
| 64 } |
| 65 ProxyType* windowProxy(DOMWrapperWorld& world) { |
| 66 return static_cast<ProxyType*>(Base::windowProxy(world)); |
| 67 } |
| 68 |
| 69 protected: |
| 70 explicit WindowProxyManagerImplHelper(Frame& frame) |
| 71 : WindowProxyManagerBase(frame) {} |
| 72 }; |
| 73 |
| 74 class LocalWindowProxyManager |
| 75 : public WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy> { |
| 76 public: |
| 77 static LocalWindowProxyManager* create(LocalFrame& frame) { |
| 78 return new LocalWindowProxyManager(frame); |
| 79 } |
36 | 80 |
37 // Sets the given security origin to the main world's context. Also updates | 81 // Sets the given security origin to the main world's context. Also updates |
38 // the security origin of the context for each isolated world. | 82 // the security origin of the context for each isolated world. |
39 void updateSecurityOrigin(SecurityOrigin*); | 83 void updateSecurityOrigin(SecurityOrigin*); |
40 | 84 |
41 void releaseGlobals(HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&); | 85 private: |
42 void setGlobals(const HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&); | 86 // TODO(dcheng): Merge LocalWindowProxyManager and ScriptController? |
| 87 friend class ScriptController; |
| 88 |
| 89 explicit LocalWindowProxyManager(LocalFrame& frame) |
| 90 : WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy>(frame) {} |
| 91 }; |
| 92 |
| 93 class RemoteWindowProxyManager |
| 94 : public WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy> { |
| 95 public: |
| 96 static RemoteWindowProxyManager* create(RemoteFrame& frame) { |
| 97 return new RemoteWindowProxyManager(frame); |
| 98 } |
43 | 99 |
44 private: | 100 private: |
45 typedef HeapHashMap<int, Member<WindowProxy>> IsolatedWorldMap; | 101 explicit RemoteWindowProxyManager(RemoteFrame& frame) |
46 | 102 : WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy>(frame) {} |
47 explicit WindowProxyManager(Frame&); | |
48 | |
49 Member<Frame> m_frame; | |
50 v8::Isolate* const m_isolate; | |
51 | |
52 const Member<WindowProxy> m_windowProxy; | |
53 IsolatedWorldMap m_isolatedWorlds; | |
54 }; | 103 }; |
55 | 104 |
56 } // namespace blink | 105 } // namespace blink |
57 | 106 |
58 #endif // WindowProxyManager_h | 107 #endif // WindowProxyManager_h |
OLD | NEW |