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" | 8 #include "bindings/core/v8/LocalWindowProxy.h" |
9 #include "bindings/core/v8/RemoteWindowProxy.h" | 9 #include "bindings/core/v8/RemoteWindowProxy.h" |
10 #include "core/CoreExport.h" | 10 #include "core/CoreExport.h" |
11 #include "core/frame/LocalFrame.h" | 11 #include "core/frame/LocalFrame.h" |
12 #include "core/frame/RemoteFrame.h" | 12 #include "core/frame/RemoteFrame.h" |
13 #include "platform/heap/Handle.h" | 13 #include "platform/heap/Handle.h" |
14 #include <utility> | 14 #include <utility> |
15 #include <v8.h> | 15 #include <v8.h> |
16 | 16 |
17 namespace blink { | 17 namespace blink { |
18 | 18 |
19 class DOMWrapperWorld; | 19 class DOMWrapperWorld; |
20 class SecurityOrigin; | |
21 class ScriptController; | |
22 | 20 |
23 class WindowProxyManagerBase : public GarbageCollected<WindowProxyManagerBase> { | 21 class CORE_EXPORT WindowProxyManagerBase |
| 22 : public GarbageCollected<WindowProxyManagerBase> { |
24 public: | 23 public: |
25 DECLARE_TRACE(); | 24 DECLARE_TRACE(); |
26 | 25 |
27 v8::Isolate* isolate() const { return m_isolate; } | 26 v8::Isolate* isolate() const { return m_isolate; } |
28 | 27 |
| 28 // Returns the global proxy for |world|'s WindowProxy. Note that it's possible |
| 29 // to return a non-empty global proxy for a detached WindowProxy. |
| 30 v8::Local<v8::Object> globalProxy(DOMWrapperWorld& world) { |
| 31 return possiblyUninitializedWindowProxy(world)->globalProxy(); |
| 32 } |
| 33 |
| 34 // Returns the v8::Context for |world|'s WindowProxy, initializing it first if |
| 35 // needed. This may not be called on a detached frame. |
| 36 v8::Local<v8::Context> context(DOMWrapperWorld& world) { |
| 37 DCHECK(frame()->client()); |
| 38 auto context = windowProxy(world)->contextIfInitialized(); |
| 39 DCHECK(!context.IsEmpty()); |
| 40 return context; |
| 41 } |
| 42 |
29 void clearForClose(); | 43 void clearForClose(); |
30 void CORE_EXPORT clearForNavigation(); | 44 void clearForNavigation(); |
31 | 45 |
32 void CORE_EXPORT | 46 void releaseGlobals(HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&); |
33 releaseGlobals(HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&); | 47 void setGlobals(const HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&); |
34 void CORE_EXPORT | |
35 setGlobals(const HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&); | |
36 | 48 |
37 protected: | 49 protected: |
38 using IsolatedWorldMap = HeapHashMap<int, Member<WindowProxy>>; | 50 using IsolatedWorldMap = HeapHashMap<int, Member<WindowProxy>>; |
39 | 51 |
40 explicit WindowProxyManagerBase(Frame&); | 52 explicit WindowProxyManagerBase(Frame&); |
41 | 53 |
42 Frame* frame() const { return m_frame; } | 54 Frame* frame() const { return m_frame; } |
| 55 // Note that this may return an uninitialized WindowProxy. |
43 WindowProxy* mainWorldProxy() const { return m_windowProxy.get(); } | 56 WindowProxy* mainWorldProxy() const { return m_windowProxy.get(); } |
| 57 IsolatedWorldMap& isolatedWorlds() { return m_isolatedWorlds; } |
| 58 |
| 59 // Returns the WindowProxy corresponding to |world|. The returned WindowProxy |
| 60 // is guaranteed to be initialized. |
44 WindowProxy* windowProxy(DOMWrapperWorld&); | 61 WindowProxy* windowProxy(DOMWrapperWorld&); |
45 | 62 |
46 IsolatedWorldMap& isolatedWorlds() { return m_isolatedWorlds; } | 63 private: |
| 64 WindowProxy* possiblyUninitializedWindowProxy(DOMWrapperWorld&); |
47 | 65 |
48 private: | |
49 v8::Isolate* const m_isolate; | 66 v8::Isolate* const m_isolate; |
50 const Member<Frame> m_frame; | 67 const Member<Frame> m_frame; |
51 const Member<WindowProxy> m_windowProxy; | 68 const Member<WindowProxy> m_windowProxy; |
52 IsolatedWorldMap m_isolatedWorlds; | 69 IsolatedWorldMap m_isolatedWorlds; |
53 }; | 70 }; |
54 | 71 |
55 template <typename FrameType, typename ProxyType> | 72 template <typename FrameType, typename ProxyType> |
56 class WindowProxyManagerImplHelper : public WindowProxyManagerBase { | 73 class WindowProxyManagerImplHelper : public WindowProxyManagerBase { |
57 private: | 74 protected: |
58 using Base = WindowProxyManagerBase; | 75 using Base = WindowProxyManagerBase; |
59 | 76 |
60 public: | 77 explicit WindowProxyManagerImplHelper(Frame& frame) |
61 FrameType* frame() const { return static_cast<FrameType*>(Base::frame()); } | 78 : WindowProxyManagerBase(frame) {} |
| 79 |
| 80 // Note that this may return an uninitialized WindowProxy. |
62 ProxyType* mainWorldProxy() const { | 81 ProxyType* mainWorldProxy() const { |
63 return static_cast<ProxyType*>(Base::mainWorldProxy()); | 82 return static_cast<ProxyType*>(Base::mainWorldProxy()); |
64 } | 83 } |
| 84 |
| 85 // Returns the WindowProxy corresponding to |world|. The returned WindowProxy |
| 86 // is guaranteed to be initialized. |
65 ProxyType* windowProxy(DOMWrapperWorld& world) { | 87 ProxyType* windowProxy(DOMWrapperWorld& world) { |
66 return static_cast<ProxyType*>(Base::windowProxy(world)); | 88 return static_cast<ProxyType*>(Base::windowProxy(world)); |
67 } | 89 } |
68 | 90 |
69 protected: | 91 FrameType* frame() const { return static_cast<FrameType*>(Base::frame()); } |
70 explicit WindowProxyManagerImplHelper(Frame& frame) | |
71 : WindowProxyManagerBase(frame) {} | |
72 }; | 92 }; |
73 | 93 |
74 class LocalWindowProxyManager | 94 class LocalWindowProxyManager |
75 : public WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy> { | 95 : public WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy> { |
76 public: | 96 protected: |
77 static LocalWindowProxyManager* create(LocalFrame& frame) { | |
78 return new LocalWindowProxyManager(frame); | |
79 } | |
80 | |
81 // Sets the given security origin to the main world's context. Also updates | |
82 // the security origin of the context for each isolated world. | |
83 void updateSecurityOrigin(SecurityOrigin*); | |
84 | |
85 private: | |
86 // TODO(dcheng): Merge LocalWindowProxyManager and ScriptController? | |
87 friend class ScriptController; | |
88 | |
89 explicit LocalWindowProxyManager(LocalFrame& frame) | 97 explicit LocalWindowProxyManager(LocalFrame& frame) |
90 : WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy>(frame) {} | 98 : WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy>(frame) {} |
91 }; | 99 }; |
92 | 100 |
93 class RemoteWindowProxyManager | 101 class RemoteWindowProxyManager |
94 : public WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy> { | 102 : public WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy> { |
95 public: | 103 public: |
96 static RemoteWindowProxyManager* create(RemoteFrame& frame) { | 104 static RemoteWindowProxyManager* create(RemoteFrame& frame) { |
97 return new RemoteWindowProxyManager(frame); | 105 return new RemoteWindowProxyManager(frame); |
98 } | 106 } |
99 | 107 |
100 private: | 108 private: |
101 explicit RemoteWindowProxyManager(RemoteFrame& frame) | 109 explicit RemoteWindowProxyManager(RemoteFrame& frame) |
102 : WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy>(frame) {} | 110 : WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy>(frame) {} |
103 }; | 111 }; |
104 | 112 |
105 } // namespace blink | 113 } // namespace blink |
106 | 114 |
107 #endif // WindowProxyManager_h | 115 #endif // WindowProxyManager_h |
OLD | NEW |