| 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 <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "bindings/core/v8/LocalWindowProxy.h" | 10 #include "bindings/core/v8/LocalWindowProxy.h" |
| 11 #include "bindings/core/v8/RemoteWindowProxy.h" | 11 #include "bindings/core/v8/RemoteWindowProxy.h" |
| 12 #include "core/CoreExport.h" | 12 #include "core/CoreExport.h" |
| 13 #include "core/frame/LocalFrame.h" | 13 #include "core/frame/LocalFrame.h" |
| 14 #include "core/frame/RemoteFrame.h" | 14 #include "core/frame/RemoteFrame.h" |
| 15 #include "platform/heap/Handle.h" | 15 #include "platform/heap/Handle.h" |
| 16 #include "v8/include/v8.h" | 16 #include "v8/include/v8.h" |
| 17 | 17 |
| 18 namespace blink { | 18 namespace blink { |
| 19 | 19 |
| 20 class DOMWrapperWorld; | 20 class DOMWrapperWorld; |
| 21 class SecurityOrigin; | 21 class SecurityOrigin; |
| 22 class ScriptController; | |
| 23 | 22 |
| 24 class WindowProxyManagerBase : public GarbageCollected<WindowProxyManagerBase> { | 23 class WindowProxyManager : public GarbageCollected<WindowProxyManager> { |
| 25 public: | 24 public: |
| 26 DECLARE_TRACE(); | 25 DECLARE_TRACE(); |
| 27 | 26 |
| 28 v8::Isolate* isolate() const { return m_isolate; } | 27 v8::Isolate* isolate() const { return m_isolate; } |
| 29 | 28 |
| 30 void clearForClose(); | 29 void clearForClose(); |
| 31 void CORE_EXPORT clearForNavigation(); | 30 void CORE_EXPORT clearForNavigation(); |
| 32 | 31 |
| 33 // Globals are passed in a vector to maintain their order: global object for | 32 // Globals are passed in a vector to maintain their order: global object for |
| 34 // the main world is always first. This is needed to prevent bugs like | 33 // the main world is always first. This is needed to prevent bugs like |
| 35 // https://crbug.com/700077. | 34 // https://crbug.com/700077. |
| 36 using GlobalsVector = | 35 using GlobalsVector = |
| 37 Vector<std::pair<DOMWrapperWorld*, v8::Local<v8::Object>>>; | 36 Vector<std::pair<DOMWrapperWorld*, v8::Local<v8::Object>>>; |
| 38 void CORE_EXPORT releaseGlobals(GlobalsVector&); | 37 void CORE_EXPORT releaseGlobals(GlobalsVector&); |
| 39 void CORE_EXPORT setGlobals(const GlobalsVector&); | 38 void CORE_EXPORT setGlobals(const GlobalsVector&); |
| 40 | 39 |
| 40 WindowProxy* mainWorldProxy() { |
| 41 m_windowProxy->initializeIfNeeded(); |
| 42 return m_windowProxy; |
| 43 } |
| 44 |
| 45 WindowProxy* windowProxy(DOMWrapperWorld& world) { |
| 46 WindowProxy* windowProxy = windowProxyMaybeUninitialized(world); |
| 47 windowProxy->initializeIfNeeded(); |
| 48 return windowProxy; |
| 49 } |
| 50 |
| 41 protected: | 51 protected: |
| 42 using IsolatedWorldMap = HeapHashMap<int, Member<WindowProxy>>; | 52 using IsolatedWorldMap = HeapHashMap<int, Member<WindowProxy>>; |
| 53 enum class FrameType { Local, Remote }; |
| 43 | 54 |
| 44 explicit WindowProxyManagerBase(Frame&); | 55 WindowProxyManager(Frame&, FrameType); |
| 45 | |
| 46 Frame* frame() const { return m_frame; } | |
| 47 WindowProxy* mainWorldProxy() const { return m_windowProxy.get(); } | |
| 48 WindowProxy* windowProxy(DOMWrapperWorld&); | |
| 49 | |
| 50 IsolatedWorldMap& isolatedWorlds() { return m_isolatedWorlds; } | |
| 51 | 56 |
| 52 private: | 57 private: |
| 58 // Creates an uninitialized WindowProxy. |
| 59 WindowProxy* createWindowProxy(DOMWrapperWorld&); |
| 60 WindowProxy* windowProxyMaybeUninitialized(DOMWrapperWorld&); |
| 61 |
| 53 v8::Isolate* const m_isolate; | 62 v8::Isolate* const m_isolate; |
| 54 const Member<Frame> m_frame; | 63 const Member<Frame> m_frame; |
| 64 const FrameType m_frameType; |
| 65 |
| 66 protected: |
| 55 const Member<WindowProxy> m_windowProxy; | 67 const Member<WindowProxy> m_windowProxy; |
| 56 IsolatedWorldMap m_isolatedWorlds; | 68 IsolatedWorldMap m_isolatedWorlds; |
| 57 }; | 69 }; |
| 58 | 70 |
| 59 template <typename FrameType, typename ProxyType> | 71 template <typename FrameType, typename ProxyType> |
| 60 class WindowProxyManagerImplHelper : public WindowProxyManagerBase { | 72 class WindowProxyManagerImplHelper : public WindowProxyManager { |
| 61 private: | 73 private: |
| 62 using Base = WindowProxyManagerBase; | 74 using Base = WindowProxyManager; |
| 63 | 75 |
| 64 public: | 76 public: |
| 65 FrameType* frame() const { return static_cast<FrameType*>(Base::frame()); } | 77 ProxyType* mainWorldProxy() { |
| 66 ProxyType* mainWorldProxy() const { | |
| 67 return static_cast<ProxyType*>(Base::mainWorldProxy()); | 78 return static_cast<ProxyType*>(Base::mainWorldProxy()); |
| 68 } | 79 } |
| 69 ProxyType* windowProxy(DOMWrapperWorld& world) { | 80 ProxyType* windowProxy(DOMWrapperWorld& world) { |
| 70 return static_cast<ProxyType*>(Base::windowProxy(world)); | 81 return static_cast<ProxyType*>(Base::windowProxy(world)); |
| 71 } | 82 } |
| 72 | 83 |
| 73 protected: | 84 protected: |
| 74 explicit WindowProxyManagerImplHelper(Frame& frame) | 85 WindowProxyManagerImplHelper(Frame& frame, FrameType frameType) |
| 75 : WindowProxyManagerBase(frame) {} | 86 : WindowProxyManager(frame, frameType) {} |
| 76 }; | 87 }; |
| 77 | 88 |
| 78 class LocalWindowProxyManager | 89 class LocalWindowProxyManager |
| 79 : public WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy> { | 90 : public WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy> { |
| 80 public: | 91 public: |
| 81 static LocalWindowProxyManager* create(LocalFrame& frame) { | 92 static LocalWindowProxyManager* create(LocalFrame& frame) { |
| 82 return new LocalWindowProxyManager(frame); | 93 return new LocalWindowProxyManager(frame); |
| 83 } | 94 } |
| 84 | 95 |
| 96 // TODO(yukishiino): Remove this method. |
| 97 LocalWindowProxy* mainWorldProxyMaybeUninitialized() { |
| 98 return static_cast<LocalWindowProxy*>(m_windowProxy.get()); |
| 99 } |
| 100 |
| 85 // Sets the given security origin to the main world's context. Also updates | 101 // Sets the given security origin to the main world's context. Also updates |
| 86 // the security origin of the context for each isolated world. | 102 // the security origin of the context for each isolated world. |
| 87 void updateSecurityOrigin(SecurityOrigin*); | 103 void updateSecurityOrigin(SecurityOrigin*); |
| 88 | 104 |
| 89 private: | 105 private: |
| 90 // TODO(dcheng): Merge LocalWindowProxyManager and ScriptController? | |
| 91 friend class ScriptController; | |
| 92 | |
| 93 explicit LocalWindowProxyManager(LocalFrame& frame) | 106 explicit LocalWindowProxyManager(LocalFrame& frame) |
| 94 : WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy>(frame) {} | 107 : WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy>( |
| 108 frame, |
| 109 FrameType::Local) {} |
| 95 }; | 110 }; |
| 96 | 111 |
| 97 class RemoteWindowProxyManager | 112 class RemoteWindowProxyManager |
| 98 : public WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy> { | 113 : public WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy> { |
| 99 public: | 114 public: |
| 100 static RemoteWindowProxyManager* create(RemoteFrame& frame) { | 115 static RemoteWindowProxyManager* create(RemoteFrame& frame) { |
| 101 return new RemoteWindowProxyManager(frame); | 116 return new RemoteWindowProxyManager(frame); |
| 102 } | 117 } |
| 103 | 118 |
| 104 private: | 119 private: |
| 105 explicit RemoteWindowProxyManager(RemoteFrame& frame) | 120 explicit RemoteWindowProxyManager(RemoteFrame& frame) |
| 106 : WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy>(frame) {} | 121 : WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy>( |
| 122 frame, |
| 123 FrameType::Remote) {} |
| 107 }; | 124 }; |
| 108 | 125 |
| 109 } // namespace blink | 126 } // namespace blink |
| 110 | 127 |
| 111 #endif // WindowProxyManager_h | 128 #endif // WindowProxyManager_h |
| OLD | NEW |