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

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

Issue 2626183003: Switch RemoteWindowProxy to use v8::Context::NewRemoteContext. (Closed)
Patch Set: rebase 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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
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 <v8.h>
34 #include "bindings/core/v8/DOMWrapperWorld.h" 35 #include "bindings/core/v8/DOMWrapperWorld.h"
35 #include "bindings/core/v8/ScopedPersistent.h" 36 #include "bindings/core/v8/ScopedPersistent.h"
36 #include "bindings/core/v8/ScriptState.h" 37 #include "core/CoreExport.h"
37 #include "platform/heap/Handle.h" 38 #include "platform/heap/Handle.h"
38 #include "wtf/RefPtr.h" 39 #include "wtf/RefPtr.h"
39 #include <v8.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 ======
105 // Since a LocalWindowProxy can represent a same-origin or cross-origin frame,
106 // the entire prototype chain must be available:
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 // ====== RemoteWindowProxy ======
119 // Since a RemoteWindowProxy only represents a cross-origin frame, it has a much
120 // simpler prototype chain.
121 //
122 // outer global proxy
123 // -- has prototype --> inner global object
124 // -- has prototype --> null
125 //
126 // Property access to get/set attributes and methods on the outer global proxy
127 // are redirected through the cross-origin interceptors, since any access will
128 // fail the security check, by definition.
129 //
130 // However, note that method invocations still use the inner global object as
131 // the receiver object. Blink bindings use v8::Signature to perform a strict
132 // receiver check, which requires that the FunctionTemplate used to instantiate
133 // the receiver object matches exactly. However, when creating a new context,
134 // only inner global object is instantiated using Blink's global template, so by
135 // definition, it is the only receiver object in the prototype chain that will
136 // match.
137 //
138 // ====== References ======
139 // https://wiki.mozilla.org/Gecko:SplitWindow
140 // https://whatwg.org/C/browsers.html#the-windowproxy-exotic-object
48 class WindowProxy : public GarbageCollectedFinalized<WindowProxy> { 141 class WindowProxy : public GarbageCollectedFinalized<WindowProxy> {
49 public: 142 public:
50 virtual ~WindowProxy(); 143 virtual ~WindowProxy();
51 144
52 DECLARE_TRACE(); 145 DECLARE_TRACE();
53 146
54 v8::Local<v8::Context> contextIfInitialized() const {
55 return m_scriptState ? m_scriptState->context() : v8::Local<v8::Context>();
56 }
57 void initializeIfNeeded(); 147 void initializeIfNeeded();
58 148
59 void clearForClose(); 149 void clearForClose();
60 void clearForNavigation(); 150 void clearForNavigation();
61 151
62 v8::Local<v8::Object> globalIfNotDetached(); 152 CORE_EXPORT v8::Local<v8::Object> globalIfNotDetached();
63 v8::Local<v8::Object> releaseGlobal(); 153 v8::Local<v8::Object> releaseGlobal();
64 void setGlobal(v8::Local<v8::Object>); 154 void setGlobal(v8::Local<v8::Object>);
65 155
66 // TODO(dcheng): Temporarily exposed to avoid include cycles. Remove the need 156 // TODO(dcheng): Temporarily exposed to avoid include cycles. Remove the need
67 // for this and remove this getter. 157 // for this and remove this getter.
68 DOMWrapperWorld& world() { return *m_world; } 158 DOMWrapperWorld& world() { return *m_world; }
69 159
70 protected: 160 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, 161 // A valid transition is from ContextUninitialized to ContextInitialized,
76 // and then ContextDetached. Other transitions are forbidden. 162 // and then ContextDetached. Other transitions are forbidden.
77 enum class Lifecycle { 163 enum class Lifecycle {
78 ContextUninitialized, 164 ContextUninitialized,
79 ContextInitialized, 165 ContextInitialized,
80 ContextDetached, 166 ContextDetached,
81 }; 167 };
82 168
83 WindowProxy(v8::Isolate*, Frame&, RefPtr<DOMWrapperWorld>); 169 WindowProxy(v8::Isolate*, Frame&, RefPtr<DOMWrapperWorld>);
84 170
85 virtual void initialize() = 0; 171 virtual void initialize() = 0;
86 172
87 enum GlobalDetachmentBehavior { DoNotDetachGlobal, DetachGlobal }; 173 enum GlobalDetachmentBehavior { DoNotDetachGlobal, DetachGlobal };
88 virtual void disposeContext(GlobalDetachmentBehavior); 174 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 175
94 v8::Isolate* isolate() const { return m_isolate; } 176 v8::Isolate* isolate() const { return m_isolate; }
95 Frame* frame() const { return m_frame.get(); } 177 Frame* frame() const { return m_frame.get(); }
96 ScriptState* getScriptState() const { return m_scriptState.get(); } 178
179 #if DCHECK_IS_ON()
180 void didAttachGlobalProxy() { m_isGlobalProxyAttached = true; }
181 void didDetachGlobalProxy() { m_isGlobalProxyAttached = false; }
182 #endif
97 183
98 private: 184 private:
99 v8::Isolate* const m_isolate; 185 v8::Isolate* const m_isolate;
100 const Member<Frame> m_frame; 186 const Member<Frame> m_frame;
187 #if DCHECK_IS_ON()
188 bool m_isGlobalProxyAttached = false;
189 #endif
101 190
102 protected: 191 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. 192 // TODO(dcheng): Consider making these private and using getters.
107 const RefPtr<DOMWrapperWorld> m_world; 193 const RefPtr<DOMWrapperWorld> m_world;
108 ScopedPersistent<v8::Object> m_globalProxy; 194 ScopedPersistent<v8::Object> m_globalProxy;
109 Lifecycle m_lifecycle; 195 Lifecycle m_lifecycle;
110 }; 196 };
111 197
112 } // namespace blink 198 } // namespace blink
113 199
114 #endif // WindowProxy_h 200 #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