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

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

Issue 2630693002: Make ScriptController inherit LocalWindowProxyManager
Patch Set: Add comments Created 3 years, 11 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;
21 class ScriptController;
22 20
23 class WindowProxyManagerBase : public GarbageCollected<WindowProxyManagerBase> { 21 class CORE_EXPORT WindowProxyManagerBase
22 : public GarbageCollected<WindowProxyManagerBase> {
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 clearForNavigation();
31 30
32 void CORE_EXPORT 31 void releaseGlobals(HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&);
33 releaseGlobals(HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&); 32 void setGlobals(const HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&);
34 void CORE_EXPORT
35 setGlobals(const HashMap<DOMWrapperWorld*, v8::Local<v8::Object>>&);
36 33
37 protected: 34 protected:
38 using IsolatedWorldMap = HeapHashMap<int, Member<WindowProxy>>; 35 using IsolatedWorldMap = HeapHashMap<int, Member<WindowProxy>>;
39 36
40 explicit WindowProxyManagerBase(Frame&); 37 explicit WindowProxyManagerBase(Frame&);
41 38
42 Frame* frame() const { return m_frame; } 39 Frame* frame() const { return m_frame; }
43 WindowProxy* mainWorldProxy() const { return m_windowProxy.get(); } 40 WindowProxy* mainWorldProxy() const { return m_windowProxy.get(); }
41 IsolatedWorldMap& isolatedWorlds() { return m_isolatedWorlds; }
42
44 WindowProxy* windowProxy(DOMWrapperWorld&); 43 WindowProxy* windowProxy(DOMWrapperWorld&);
45 44
46 IsolatedWorldMap& isolatedWorlds() { return m_isolatedWorlds; } 45 private:
46 WindowProxy* possiblyUninitializedWindowProxy(DOMWrapperWorld&);
47 47
48 private:
49 v8::Isolate* const m_isolate; 48 v8::Isolate* const m_isolate;
50 const Member<Frame> m_frame; 49 const Member<Frame> m_frame;
51 const Member<WindowProxy> m_windowProxy; 50 const Member<WindowProxy> m_windowProxy;
52 IsolatedWorldMap m_isolatedWorlds; 51 IsolatedWorldMap m_isolatedWorlds;
53 }; 52 };
54 53
55 template <typename FrameType, typename ProxyType> 54 template <typename FrameType, typename ProxyType>
56 class WindowProxyManagerImplHelper : public WindowProxyManagerBase { 55 class WindowProxyManagerImplHelper : public WindowProxyManagerBase {
57 private: 56 private:
58 using Base = WindowProxyManagerBase; 57 using Base = WindowProxyManagerBase;
59 58
60 public: 59 public:
61 FrameType* frame() const { return static_cast<FrameType*>(Base::frame()); } 60 // Note that this may return an uninitialized WindowProxy.
Yuki 2017/01/13 10:42:00 This is a very good comment, but could you write t
dcheng 2017/01/13 18:57:31 Done.
62 ProxyType* mainWorldProxy() const { 61 ProxyType* mainWorldProxy() const {
63 return static_cast<ProxyType*>(Base::mainWorldProxy()); 62 return static_cast<ProxyType*>(Base::mainWorldProxy());
64 } 63 }
64 // Returns the WindowProxy corresponding to |world|. The returned WindowProxy
65 // is guaranteed to be initialized.
Yuki 2017/01/13 10:42:00 Ditto.
dcheng 2017/01/13 18:57:30 Done.
65 ProxyType* windowProxy(DOMWrapperWorld& world) { 66 ProxyType* windowProxy(DOMWrapperWorld& world) {
66 return static_cast<ProxyType*>(Base::windowProxy(world)); 67 return static_cast<ProxyType*>(Base::windowProxy(world));
67 } 68 }
68 69
69 protected: 70 protected:
70 explicit WindowProxyManagerImplHelper(Frame& frame) 71 explicit WindowProxyManagerImplHelper(Frame& frame)
71 : WindowProxyManagerBase(frame) {} 72 : WindowProxyManagerBase(frame) {}
73
74 FrameType* frame() const { return static_cast<FrameType*>(Base::frame()); }
72 }; 75 };
73 76
74 class LocalWindowProxyManager 77 class LocalWindowProxyManager
75 : public WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy> { 78 : public WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy> {
76 public: 79 protected:
77 static LocalWindowProxyManager* create(LocalFrame& frame) {
78 return new LocalWindowProxyManager(frame);
79 }
80
81 // Sets the given security origin to the main world's context. Also updates
82 // the security origin of the context for each isolated world.
83 void updateSecurityOrigin(SecurityOrigin*);
84
85 private:
86 // TODO(dcheng): Merge LocalWindowProxyManager and ScriptController?
87 friend class ScriptController;
88
89 explicit LocalWindowProxyManager(LocalFrame& frame) 80 explicit LocalWindowProxyManager(LocalFrame& frame)
90 : WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy>(frame) {} 81 : WindowProxyManagerImplHelper<LocalFrame, LocalWindowProxy>(frame) {}
91 }; 82 };
92 83
93 class RemoteWindowProxyManager 84 class RemoteWindowProxyManager
94 : public WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy> { 85 : public WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy> {
95 public: 86 public:
96 static RemoteWindowProxyManager* create(RemoteFrame& frame) { 87 static RemoteWindowProxyManager* create(RemoteFrame& frame) {
97 return new RemoteWindowProxyManager(frame); 88 return new RemoteWindowProxyManager(frame);
98 } 89 }
99 90
100 private: 91 private:
101 explicit RemoteWindowProxyManager(RemoteFrame& frame) 92 explicit RemoteWindowProxyManager(RemoteFrame& frame)
102 : WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy>(frame) {} 93 : WindowProxyManagerImplHelper<RemoteFrame, RemoteWindowProxy>(frame) {}
103 }; 94 };
104 95
105 } // namespace blink 96 } // namespace blink
106 97
107 #endif // WindowProxyManager_h 98 #endif // WindowProxyManager_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698