Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/WindowProxyManager.h

Issue 2702273004: bindings: Simplifies WindowProxyManager and its relation to Frame. (Closed)
Patch Set: Addressed review comments. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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; }
dcheng 2017/02/23 19:02:36 I would personally prefer not to expose this publi
Yuki 2017/03/09 14:58:53 Since this is only used by ScriptController, I rem
37
38 bool isMainWorldProxyInitialized() const {
39 return m_windowProxy->isInitialized();
40 }
41
42 WindowProxy* mainWorldProxy() {
43 m_windowProxy->initializeIfNeeded();
44 return m_windowProxy;
45 }
46
47 WindowProxy* windowProxy(DOMWrapperWorld& world) {
48 WindowProxy* windowProxy = windowProxyMaybeUninitialized(world);
49 windowProxy->initializeIfNeeded();
50 return windowProxy;
51 }
52
37 protected: 53 protected:
38 using IsolatedWorldMap = HeapHashMap<int, Member<WindowProxy>>; 54 using IsolatedWorldMap = HeapHashMap<int, Member<WindowProxy>>;
39 55
40 explicit WindowProxyManagerBase(Frame&); 56 explicit WindowProxyManager(Frame&);
41
42 Frame* frame() const { return m_frame; }
43 WindowProxy* mainWorldProxy() const { return m_windowProxy.get(); }
44 WindowProxy* windowProxy(DOMWrapperWorld&);
45 57
46 IsolatedWorldMap& isolatedWorlds() { return m_isolatedWorlds; } 58 IsolatedWorldMap& isolatedWorlds() { return m_isolatedWorlds; }
47 59
48 private: 60 private:
61 WindowProxy* windowProxyMaybeUninitialized(DOMWrapperWorld&);
62
49 v8::Isolate* const m_isolate; 63 v8::Isolate* const m_isolate;
50 const Member<Frame> m_frame; 64 const Member<Frame> m_frame;
51 const Member<WindowProxy> m_windowProxy; 65 const Member<WindowProxy> m_windowProxy;
52 IsolatedWorldMap m_isolatedWorlds; 66 IsolatedWorldMap m_isolatedWorlds;
53 }; 67 };
54 68
55 template <typename FrameType, typename ProxyType> 69 template <typename FrameType, typename ProxyType>
56 class WindowProxyManagerImplHelper : public WindowProxyManagerBase { 70 class WindowProxyManagerImplHelper : public WindowProxyManager {
57 private: 71 private:
58 using Base = WindowProxyManagerBase; 72 using Base = WindowProxyManager;
59 73
60 public: 74 public:
61 FrameType* frame() const { return static_cast<FrameType*>(Base::frame()); } 75 FrameType* frame() const { return static_cast<FrameType*>(Base::frame()); }
62 ProxyType* mainWorldProxy() const { 76 ProxyType* mainWorldProxy() {
63 return static_cast<ProxyType*>(Base::mainWorldProxy()); 77 return static_cast<ProxyType*>(Base::mainWorldProxy());
64 } 78 }
65 ProxyType* windowProxy(DOMWrapperWorld& world) { 79 ProxyType* windowProxy(DOMWrapperWorld& world) {
66 return static_cast<ProxyType*>(Base::windowProxy(world)); 80 return static_cast<ProxyType*>(Base::windowProxy(world));
67 } 81 }
68 82
69 protected: 83 protected:
70 explicit WindowProxyManagerImplHelper(Frame& frame) 84 explicit WindowProxyManagerImplHelper(Frame& frame)
71 : WindowProxyManagerBase(frame) {} 85 : WindowProxyManager(frame) {}
72 }; 86 };
73 87
74 class LocalWindowProxyManager 88 class LocalWindowProxyManager
75 : public WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy> { 89 : public WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy> {
76 public: 90 public:
77 static LocalWindowProxyManager* create(LocalFrame& frame) { 91 static LocalWindowProxyManager* create(LocalFrame& frame) {
78 return new LocalWindowProxyManager(frame); 92 return new LocalWindowProxyManager(frame);
79 } 93 }
80 94
81 // Sets the given security origin to the main world's context. Also updates 95 // Sets the given security origin to the main world's context. Also updates
82 // the security origin of the context for each isolated world. 96 // the security origin of the context for each isolated world.
83 void updateSecurityOrigin(SecurityOrigin*); 97 void updateSecurityOrigin(SecurityOrigin*);
84 98
85 private: 99 private:
86 // TODO(dcheng): Merge LocalWindowProxyManager and ScriptController?
87 friend class ScriptController;
88
89 explicit LocalWindowProxyManager(LocalFrame& frame) 100 explicit LocalWindowProxyManager(LocalFrame& frame)
90 : WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy>(frame) {} 101 : WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy>(frame) {}
91 }; 102 };
92 103
93 class RemoteWindowProxyManager 104 class RemoteWindowProxyManager
94 : public WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy> { 105 : public WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy> {
95 public: 106 public:
96 static RemoteWindowProxyManager* create(RemoteFrame& frame) { 107 static RemoteWindowProxyManager* create(RemoteFrame& frame) {
97 return new RemoteWindowProxyManager(frame); 108 return new RemoteWindowProxyManager(frame);
98 } 109 }
99 110
100 private: 111 private:
101 explicit RemoteWindowProxyManager(RemoteFrame& frame) 112 explicit RemoteWindowProxyManager(RemoteFrame& frame)
102 : WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy>(frame) {} 113 : WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy>(frame) {}
103 }; 114 };
104 115
105 } // namespace blink 116 } // namespace blink
106 117
107 #endif // WindowProxyManager_h 118 #endif // WindowProxyManager_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698