Chromium Code Reviews| 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 explicit WindowProxyManagerBase(Frame&); | |
| 39 | |
| 40 Frame* frame() const { return m_frame; } | |
| 30 WindowProxy* mainWorldProxy() const { return m_windowProxy.get(); } | 41 WindowProxy* mainWorldProxy() const { return m_windowProxy.get(); } |
| 31 | |
| 32 WindowProxy* windowProxy(DOMWrapperWorld&); | 42 WindowProxy* windowProxy(DOMWrapperWorld&); |
| 33 | 43 |
| 34 void clearForClose(); | 44 private: |
| 35 void clearForNavigation(); | 45 using IsolatedWorldMap = HeapHashMap<int, Member<WindowProxy>>; |
| 46 | |
| 47 const Member<Frame> m_frame; | |
| 48 v8::Isolate* const m_isolate; | |
| 49 | |
| 50 protected: | |
|
Yuki
2017/01/11 10:09:24
nit: Could you unify two protected: sections into
dcheng
2017/01/11 10:35:29
Made this private and added protected getters for
| |
| 51 const Member<WindowProxy> m_windowProxy; | |
| 52 IsolatedWorldMap m_isolatedWorlds; | |
| 53 }; | |
| 54 | |
| 55 template <typename FrameType, typename ProxyType> | |
| 56 class WindowProxyManager : public WindowProxyManagerBase { | |
|
Yuki
2017/01/11 10:09:24
nit: I guess "WindowProxyManager" is not a good na
dcheng
2017/01/11 10:35:29
Renamed it ImplHelper.
| |
| 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 WindowProxyManager(Frame& frame) : WindowProxyManagerBase(frame) {} | |
| 71 }; | |
| 72 | |
| 73 class LocalWindowProxyManager | |
| 74 : public WindowProxyManager<LocalFrame, LocalWindowProxy> { | |
| 75 public: | |
| 76 static LocalWindowProxyManager* create(LocalFrame& frame) { | |
| 77 return new LocalWindowProxyManager(frame); | |
| 78 } | |
| 36 | 79 |
| 37 // Sets the given security origin to the main world's context. Also updates | 80 // Sets the given security origin to the main world's context. Also updates |
| 38 // the security origin of the context for each isolated world. | 81 // the security origin of the context for each isolated world. |
| 39 void updateSecurityOrigin(SecurityOrigin*); | 82 void updateSecurityOrigin(SecurityOrigin*); |
| 40 | 83 |
| 41 void releaseGlobals(HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&); | 84 private: |
| 42 void setGlobals(const HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&); | 85 // TODO(dcheng): Merge LocalWindowProxyManager and ScriptController? |
| 86 friend class ScriptController; | |
| 87 | |
| 88 LocalWindowProxyManager(LocalFrame& frame) | |
| 89 : WindowProxyManager<LocalFrame, LocalWindowProxy>(frame) {} | |
| 90 }; | |
| 91 | |
| 92 class RemoteWindowProxyManager | |
| 93 : public WindowProxyManager<RemoteFrame, RemoteWindowProxy> { | |
| 94 public: | |
| 95 static RemoteWindowProxyManager* create(RemoteFrame& frame) { | |
| 96 return new RemoteWindowProxyManager(frame); | |
| 97 } | |
| 43 | 98 |
| 44 private: | 99 private: |
| 45 typedef HeapHashMap<int, Member<WindowProxy>> IsolatedWorldMap; | 100 RemoteWindowProxyManager(RemoteFrame& frame) |
| 46 | 101 : WindowProxyManager<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 }; | 102 }; |
| 55 | 103 |
| 56 } // namespace blink | 104 } // namespace blink |
| 57 | 105 |
| 58 #endif // WindowProxyManager_h | 106 #endif // WindowProxyManager_h |
| OLD | NEW |