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" | 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; | 20 class SecurityOrigin; |
| 21 class ScriptController; | |
| 22 | 21 |
| 23 class WindowProxyManagerBase : public GarbageCollected<WindowProxyManagerBase> { | 22 class WindowProxyManager : public GarbageCollected<WindowProxyManager> { |
| 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 |
| 29 void clearForClose(); | 28 void clearForClose(); |
| 30 void CORE_EXPORT clearForNavigation(); | 29 void CORE_EXPORT clearForNavigation(); |
| 31 | 30 |
| 32 void CORE_EXPORT | 31 void CORE_EXPORT |
| 33 releaseGlobals(HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&); | 32 releaseGlobals(HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&); |
| 34 void CORE_EXPORT | 33 void CORE_EXPORT |
| 35 setGlobals(const HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&); | 34 setGlobals(const HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&); |
| 36 | 35 |
| 36 Frame* frame() const { return m_frame; } | |
| 37 WindowProxy* windowProxy(DOMWrapperWorld& world) { | |
| 38 WindowProxy* windowProxy = windowProxyMaybeUninitialized(world); | |
| 39 windowProxy->initializeIfNeeded(); | |
| 40 return windowProxy; | |
| 41 } | |
| 42 | |
| 37 protected: | 43 protected: |
| 38 using IsolatedWorldMap = HeapHashMap<int, Member<WindowProxy>>; | 44 using IsolatedWorldMap = HeapHashMap<int, Member<WindowProxy>>; |
| 39 | 45 |
| 40 explicit WindowProxyManagerBase(Frame&); | 46 explicit WindowProxyManager(Frame&); |
| 41 | |
| 42 Frame* frame() const { return m_frame; } | |
| 43 WindowProxy* mainWorldProxy() const { return m_windowProxy.get(); } | |
| 44 WindowProxy* windowProxy(DOMWrapperWorld&); | |
| 45 | 47 |
| 46 IsolatedWorldMap& isolatedWorlds() { return m_isolatedWorlds; } | 48 IsolatedWorldMap& isolatedWorlds() { return m_isolatedWorlds; } |
| 47 | 49 |
| 50 WindowProxy* mainWorldProxyMaybeUninitialized() { | |
| 51 return m_windowProxy; | |
| 52 } | |
| 53 | |
| 48 private: | 54 private: |
| 55 WindowProxy* windowProxyMaybeUninitialized(DOMWrapperWorld&); | |
| 56 | |
| 49 v8::Isolate* const m_isolate; | 57 v8::Isolate* const m_isolate; |
| 50 const Member<Frame> m_frame; | 58 const Member<Frame> m_frame; |
| 51 const Member<WindowProxy> m_windowProxy; | 59 const Member<WindowProxy> m_windowProxy; |
| 52 IsolatedWorldMap m_isolatedWorlds; | 60 IsolatedWorldMap m_isolatedWorlds; |
| 53 }; | 61 }; |
| 54 | 62 |
| 55 template <typename FrameType, typename ProxyType> | 63 template <typename FrameType, typename ProxyType> |
| 56 class WindowProxyManagerImplHelper : public WindowProxyManagerBase { | 64 class WindowProxyManagerImplHelper : public WindowProxyManager { |
| 57 private: | 65 private: |
| 58 using Base = WindowProxyManagerBase; | 66 using Base = WindowProxyManager; |
| 59 | 67 |
| 60 public: | 68 public: |
| 61 FrameType* frame() const { return static_cast<FrameType*>(Base::frame()); } | 69 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) { | 70 ProxyType* windowProxy(DOMWrapperWorld& world) { |
| 66 return static_cast<ProxyType*>(Base::windowProxy(world)); | 71 return static_cast<ProxyType*>(Base::windowProxy(world)); |
| 67 } | 72 } |
| 68 | 73 |
| 69 protected: | 74 protected: |
| 70 explicit WindowProxyManagerImplHelper(Frame& frame) | 75 explicit WindowProxyManagerImplHelper(Frame& frame) |
| 71 : WindowProxyManagerBase(frame) {} | 76 : WindowProxyManager(frame) {} |
| 72 }; | 77 }; |
| 73 | 78 |
| 74 class LocalWindowProxyManager | 79 class LocalWindowProxyManager |
| 75 : public WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy> { | 80 : public WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy> { |
| 76 public: | 81 public: |
| 77 static LocalWindowProxyManager* create(LocalFrame& frame) { | 82 static LocalWindowProxyManager* create(LocalFrame& frame) { |
| 78 return new LocalWindowProxyManager(frame); | 83 return new LocalWindowProxyManager(frame); |
| 79 } | 84 } |
| 80 | 85 |
| 86 LocalWindowProxy* mainWorldProxyMaybeUninitialized() { | |
|
dcheng
2017/02/22 01:07:06
I would prefer not to expose this publicly if poss
Yuki
2017/02/22 09:01:33
Hmm, I added WindowProxy::isInitialized() and chan
| |
| 87 return static_cast<LocalWindowProxy*>( | |
| 88 WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy>:: | |
| 89 mainWorldProxyMaybeUninitialized()); | |
| 90 } | |
| 91 | |
| 81 // Sets the given security origin to the main world's context. Also updates | 92 // Sets the given security origin to the main world's context. Also updates |
| 82 // the security origin of the context for each isolated world. | 93 // the security origin of the context for each isolated world. |
| 83 void updateSecurityOrigin(SecurityOrigin*); | 94 void updateSecurityOrigin(SecurityOrigin*); |
| 84 | 95 |
| 85 private: | 96 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 |