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 <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 void CORE_EXPORT | 32 void CORE_EXPORT |
| 34 releaseGlobals(HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&); | 33 releaseGlobals(HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&); |
| 35 void CORE_EXPORT | 34 void CORE_EXPORT |
| 36 setGlobals(const HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&); | 35 setGlobals(const HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&); |
| 37 | 36 |
| 37 bool isMainWorldContextInitialized() const { | |
| 38 return !m_windowProxy->contextIfInitialized().IsEmpty(); | |
|
dcheng
2017/03/10 09:52:13
Can we move this to LocalWindowProxyManager, since
Yuki
2017/03/10 15:21:51
Done.
| |
| 39 } | |
| 40 | |
| 41 WindowProxy* mainWorldProxy() { | |
| 42 m_windowProxy->initializeIfNeeded(); | |
| 43 return m_windowProxy; | |
| 44 } | |
| 45 | |
| 46 WindowProxy* windowProxy(DOMWrapperWorld& world) { | |
|
dcheng
2017/03/10 09:52:13
It's not necessary to do it now, but maybe there i
Yuki
2017/03/10 15:21:51
Acknowledged.
| |
| 47 WindowProxy* windowProxy = windowProxyMaybeUninitialized(world); | |
| 48 windowProxy->initializeIfNeeded(); | |
| 49 return windowProxy; | |
| 50 } | |
| 51 | |
| 38 protected: | 52 protected: |
| 39 using IsolatedWorldMap = HeapHashMap<int, Member<WindowProxy>>; | 53 using IsolatedWorldMap = HeapHashMap<int, Member<WindowProxy>>; |
| 40 | 54 |
| 41 explicit WindowProxyManagerBase(Frame&); | 55 explicit WindowProxyManager(Frame&); |
| 42 | |
| 43 Frame* frame() const { return m_frame; } | |
| 44 WindowProxy* mainWorldProxy() const { return m_windowProxy.get(); } | |
| 45 WindowProxy* windowProxy(DOMWrapperWorld&); | |
| 46 | |
| 47 IsolatedWorldMap& isolatedWorlds() { return m_isolatedWorlds; } | |
| 48 | 56 |
| 49 private: | 57 private: |
| 58 WindowProxy* windowProxyMaybeUninitialized(DOMWrapperWorld&); | |
| 59 | |
| 50 v8::Isolate* const m_isolate; | 60 v8::Isolate* const m_isolate; |
| 51 const Member<Frame> m_frame; | 61 const Member<Frame> m_frame; |
| 62 | |
| 63 protected: | |
| 52 const Member<WindowProxy> m_windowProxy; | 64 const Member<WindowProxy> m_windowProxy; |
| 53 IsolatedWorldMap m_isolatedWorlds; | 65 IsolatedWorldMap m_isolatedWorlds; |
| 54 }; | 66 }; |
| 55 | 67 |
| 56 template <typename FrameType, typename ProxyType> | 68 template <typename FrameType, typename ProxyType> |
| 57 class WindowProxyManagerImplHelper : public WindowProxyManagerBase { | 69 class WindowProxyManagerImplHelper : public WindowProxyManager { |
| 58 private: | 70 private: |
| 59 using Base = WindowProxyManagerBase; | 71 using Base = WindowProxyManager; |
| 60 | 72 |
| 61 public: | 73 public: |
| 62 FrameType* frame() const { return static_cast<FrameType*>(Base::frame()); } | 74 ProxyType* mainWorldProxy() { |
| 63 ProxyType* mainWorldProxy() const { | |
| 64 return static_cast<ProxyType*>(Base::mainWorldProxy()); | 75 return static_cast<ProxyType*>(Base::mainWorldProxy()); |
| 65 } | 76 } |
| 66 ProxyType* windowProxy(DOMWrapperWorld& world) { | 77 ProxyType* windowProxy(DOMWrapperWorld& world) { |
| 67 return static_cast<ProxyType*>(Base::windowProxy(world)); | 78 return static_cast<ProxyType*>(Base::windowProxy(world)); |
| 68 } | 79 } |
| 69 | 80 |
| 70 protected: | 81 protected: |
| 71 explicit WindowProxyManagerImplHelper(Frame& frame) | 82 explicit WindowProxyManagerImplHelper(Frame& frame) |
| 72 : WindowProxyManagerBase(frame) {} | 83 : WindowProxyManager(frame) {} |
| 73 }; | 84 }; |
| 74 | 85 |
| 75 class LocalWindowProxyManager | 86 class LocalWindowProxyManager |
| 76 : public WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy> { | 87 : public WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy> { |
| 77 public: | 88 public: |
| 78 static LocalWindowProxyManager* create(LocalFrame& frame) { | 89 static LocalWindowProxyManager* create(LocalFrame& frame) { |
| 79 return new LocalWindowProxyManager(frame); | 90 return new LocalWindowProxyManager(frame); |
| 80 } | 91 } |
| 81 | 92 |
| 93 // TODO(yukishiino): Remove this method. | |
| 94 LocalWindowProxy* mainWorldProxyMaybeUninitialized() { | |
| 95 return static_cast<LocalWindowProxy*>(m_windowProxy.get()); | |
| 96 } | |
| 97 | |
| 82 // Sets the given security origin to the main world's context. Also updates | 98 // Sets the given security origin to the main world's context. Also updates |
| 83 // the security origin of the context for each isolated world. | 99 // the security origin of the context for each isolated world. |
| 84 void updateSecurityOrigin(SecurityOrigin*); | 100 void updateSecurityOrigin(SecurityOrigin*); |
| 85 | 101 |
| 86 private: | 102 private: |
| 87 // TODO(dcheng): Merge LocalWindowProxyManager and ScriptController? | |
| 88 friend class ScriptController; | |
| 89 | |
| 90 explicit LocalWindowProxyManager(LocalFrame& frame) | 103 explicit LocalWindowProxyManager(LocalFrame& frame) |
| 91 : WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy>(frame) {} | 104 : WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy>(frame) {} |
| 92 }; | 105 }; |
| 93 | 106 |
| 94 class RemoteWindowProxyManager | 107 class RemoteWindowProxyManager |
| 95 : public WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy> { | 108 : public WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy> { |
| 96 public: | 109 public: |
| 97 static RemoteWindowProxyManager* create(RemoteFrame& frame) { | 110 static RemoteWindowProxyManager* create(RemoteFrame& frame) { |
| 98 return new RemoteWindowProxyManager(frame); | 111 return new RemoteWindowProxyManager(frame); |
| 99 } | 112 } |
| 100 | 113 |
| 101 private: | 114 private: |
| 102 explicit RemoteWindowProxyManager(RemoteFrame& frame) | 115 explicit RemoteWindowProxyManager(RemoteFrame& frame) |
| 103 : WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy>(frame) {} | 116 : WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy>(frame) {} |
| 104 }; | 117 }; |
| 105 | 118 |
| 106 } // namespace blink | 119 } // namespace blink |
| 107 | 120 |
| 108 #endif // WindowProxyManager_h | 121 #endif // WindowProxyManager_h |
| OLD | NEW |