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

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

Issue 2724573002: Prepare WindowProxy for using v8::Context::NewRemoteContext(). (Closed)
Patch Set: Remove duplicate v8 include Created 3 years, 9 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 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef WindowProxy_h 31 #ifndef WindowProxy_h
32 #define WindowProxy_h 32 #define WindowProxy_h
33 33
34 #include "bindings/core/v8/DOMWrapperWorld.h" 34 #include "bindings/core/v8/DOMWrapperWorld.h"
35 #include "bindings/core/v8/ScopedPersistent.h" 35 #include "bindings/core/v8/ScopedPersistent.h"
36 #include "bindings/core/v8/ScriptState.h" 36 #include "core/CoreExport.h"
37 #include "platform/heap/Handle.h" 37 #include "platform/heap/Handle.h"
38 #include "v8/include/v8.h" 38 #include "v8/include/v8.h"
39 #include "wtf/RefPtr.h" 39 #include "wtf/RefPtr.h"
40 40
41 namespace blink { 41 namespace blink {
42 42
43 class Frame; 43 class Frame;
44 class ScriptController;
45 44
46 // WindowProxy represents all the per-global object state for a Frame that 45 // WindowProxy implements the split window model of a window for a frame. In the
47 // persist between navigations. 46 // HTML standard, the split window model is composed of the Window interface
47 // (the inner global object) and the WindowProxy interface (the outer global
48 // proxy).
49 //
50 // The Window interface is backed by the Blink DOMWindow C++ implementation.
51 // In contrast, the WindowProxy interface does not have a corresponding
52 // C++ implementation in Blink: the WindowProxy class defined here only manages
53 // context initialization and detach. Instead, the behavior of the WindowProxy
54 // interface is defined by JSGlobalProxy in v8 and the prototype chain set up
55 // during context initialization.
56 //
57 // ====== Inner Global Object ======
58 // The inner global object is the global for the script environment of a Frame.
59 // Since Window and Document also have a 1:1 relationship, this means that each
60 // inner global object has an associated Document which does not change. On
61 // navigation, the new Document receives a new inner global object.
62 //
63 // However, there is one exception to the 1:1 DOMWindow:Document rule. If:
64 // - the previous Document is the initial empty document
65 // - the new Document is same-origin to the previous Document
66 // then the inner global object will be reused for the new Document. This is the
67 // only case where the associated Document of an inner global object can change.
68 //
69 // All methods and attributes defined on the Window interface are exposed via
70 // the inner global object. Global variables defined by script running in the
71 // Document also live on the inner global object.
72 //
73 // ====== Outer Global Proxy ====
74 // The outer global proxy is reused across navigations. It implements the
75 // security checks for same-origin/cross-origin access to the Window interface.
76 // When the check passes (i.e. the access is same-origin), the access is
77 // forwarded to the inner global object of the active Document in this
78 // WindowProxy's Frame).
79 //
80 // When the security check fails, the access is delegated to the outer global
81 // proxy's cross-origin interceptors. The cross-origin interceptors may choose
82 // to return a value (if the property is exposed cross-origin) or throw an
83 // exception otherwise.
84 //
85 // Note that the cross-origin interceptors are only used for cross-origin
86 // accesses: a same-origin access to a method that is available cross-origin,
87 // such as Window.postMessage, will be delegated to the inner global object.
88 //
89 // ====== LocalWindowProxy vs RemoteWindowProxy ======
90 // WindowProxy has two concrete subclasses:
91 // - LocalWindowProxy: implements the split window model for a frame in the same
92 // process, i.e. a LocalFrame.
93 // - RemoteWindowProxy: implements the split window model for a frame in a
94 // different process, i.e. a RemoteFrame.
95 //
96 // While having a RemoteFrame implies the frame must be cross-origin, the
97 // opposite is not true: a LocalFrame can be same-origin or cross-origin. One
98 // additional complexity (which slightly violates the HTML standard): it is
99 // possible to have SecurityOrigin::canAccess() return true for a RemoteFrame's
100 // security origin; however, it is important to still deny access as if the
101 // frame were cross-origin. This is due to complexities in the process
102 // allocation model for renderer processes. See https://crbug.com/601629.
103 //
104 // ====== LocalWindowProxy/RemoteWindowProxy ======
105 // Currently, the prototype chain for LocalWindowProxy and RemoteWindowProxy
106 // look the same:
107 //
108 // outer global proxy
109 // -- has prototype --> inner global object
110 // -- has prototype --> Window.prototype
111 // -- has prototype --> WindowProperties [1]
112 // -- has prototype --> EventTarget.prototype
113 // -- has prototype --> Object.prototype
114 // -- has prototype --> null
115 //
116 // [1] WindowProperties is the named properties object of the Window interface.
117 //
118 // There is work in progress to refactor RemoteWindowProxy to use remote v8
119 // contexts, to reduce the overhead of remote frames.
120 //
121 // ====== References ======
122 // https://wiki.mozilla.org/Gecko:SplitWindow
123 // https://whatwg.org/C/browsers.html#the-windowproxy-exotic-object
48 class WindowProxy : public GarbageCollectedFinalized<WindowProxy> { 124 class WindowProxy : public GarbageCollectedFinalized<WindowProxy> {
49 public: 125 public:
50 virtual ~WindowProxy(); 126 virtual ~WindowProxy();
51 127
52 DECLARE_TRACE(); 128 DECLARE_TRACE();
53 129
54 v8::Local<v8::Context> contextIfInitialized() const {
55 return m_scriptState ? m_scriptState->context() : v8::Local<v8::Context>();
56 }
57 void initializeIfNeeded(); 130 void initializeIfNeeded();
58 131
59 void clearForClose(); 132 void clearForClose();
60 void clearForNavigation(); 133 void clearForNavigation();
61 134
62 v8::Local<v8::Object> globalIfNotDetached(); 135 CORE_EXPORT v8::Local<v8::Object> globalIfNotDetached();
63 v8::Local<v8::Object> releaseGlobal(); 136 v8::Local<v8::Object> releaseGlobal();
64 void setGlobal(v8::Local<v8::Object>); 137 void setGlobal(v8::Local<v8::Object>);
65 138
66 // TODO(dcheng): Temporarily exposed to avoid include cycles. Remove the need 139 // TODO(dcheng): Temporarily exposed to avoid include cycles. Remove the need
67 // for this and remove this getter. 140 // for this and remove this getter.
68 DOMWrapperWorld& world() { return *m_world; } 141 DOMWrapperWorld& world() { return *m_world; }
69 142
70 protected: 143 protected:
71 // TODO(dcheng): Remove this friend declaration once LocalWindowProxyManager
72 // and ScriptController are merged.
73 friend class ScriptController;
74
75 // A valid transition is from ContextUninitialized to ContextInitialized, 144 // A valid transition is from ContextUninitialized to ContextInitialized,
76 // and then ContextDetached. Other transitions are forbidden. 145 // and then ContextDetached. Other transitions are forbidden.
77 enum class Lifecycle { 146 enum class Lifecycle {
78 ContextUninitialized, 147 ContextUninitialized,
79 ContextInitialized, 148 ContextInitialized,
80 ContextDetached, 149 ContextDetached,
81 }; 150 };
82 151
83 WindowProxy(v8::Isolate*, Frame&, RefPtr<DOMWrapperWorld>); 152 WindowProxy(v8::Isolate*, Frame&, RefPtr<DOMWrapperWorld>);
84 153
85 virtual void initialize() = 0; 154 virtual void initialize() = 0;
86 155
87 enum GlobalDetachmentBehavior { DoNotDetachGlobal, DetachGlobal }; 156 enum GlobalDetachmentBehavior { DoNotDetachGlobal, DetachGlobal };
88 virtual void disposeContext(GlobalDetachmentBehavior); 157 virtual void disposeContext(GlobalDetachmentBehavior) = 0;
89
90 // Associates the window wrapper and its prototype chain with the native
91 // DOMWindow object. Also does some more Window-specific initialization.
92 void setupWindowPrototypeChain();
93 158
94 v8::Isolate* isolate() const { return m_isolate; } 159 v8::Isolate* isolate() const { return m_isolate; }
95 Frame* frame() const { return m_frame.get(); } 160 Frame* frame() const { return m_frame.get(); }
96 ScriptState* getScriptState() const { return m_scriptState.get(); } 161
162 #if DCHECK_IS_ON()
163 void didAttachGlobalProxy() { m_isGlobalProxyAttached = true; }
164 void didDetachGlobalProxy() { m_isGlobalProxyAttached = false; }
165 #endif
97 166
98 private: 167 private:
99 v8::Isolate* const m_isolate; 168 v8::Isolate* const m_isolate;
100 const Member<Frame> m_frame; 169 const Member<Frame> m_frame;
170 #if DCHECK_IS_ON()
171 bool m_isGlobalProxyAttached = false;
172 #endif
101 173
102 protected: 174 protected:
103 // TODO(dcheng): Move this to LocalWindowProxy once RemoteWindowProxy uses
104 // remote contexts.
105 RefPtr<ScriptState> m_scriptState;
106 // TODO(dcheng): Consider making these private and using getters. 175 // TODO(dcheng): Consider making these private and using getters.
107 const RefPtr<DOMWrapperWorld> m_world; 176 const RefPtr<DOMWrapperWorld> m_world;
108 ScopedPersistent<v8::Object> m_globalProxy; 177 ScopedPersistent<v8::Object> m_globalProxy;
109 Lifecycle m_lifecycle; 178 Lifecycle m_lifecycle;
110 }; 179 };
111 180
112 } // namespace blink 181 } // namespace blink
113 182
114 #endif // WindowProxy_h 183 #endif // WindowProxy_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/V8Binding.cpp ('k') | third_party/WebKit/Source/bindings/core/v8/WindowProxy.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698