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

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: . 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 "v8/include/v8.h" 39 #include "v8/include/v8.h"
39 #include "wtf/RefPtr.h" 40 #include "wtf/RefPtr.h"
40 41
41 namespace blink { 42 namespace blink {
42 43
43 class Frame; 44 class Frame;
44 class ScriptController;
45 45
46 // WindowProxy represents all the per-global object state for a Frame that 46 // WindowProxy implements the split window model of a window for a frame. In the
47 // persist between navigations. 47 // HTML standard, the split window model is composed of the Window interface
48 // (the inner global object) and the WindowProxy interface (the outer global
49 // proxy).
50 //
51 // The Window interface is backed by the Blink DOMWindow C++ implementation.
52 // In contrast, the WindowProxy interface does not have a corresponding
53 // C++ implementation in Blink: the WindowProxy class defined here only manages
54 // context initialization and detach. Instead, the behavior of the WindowProxy
55 // interface is defined by JSGlobalProxy in v8 and the prototype chain set up
56 // during context initialization.
57 //
58 // ====== Inner Global Object ======
59 // The inner global object is the global for the script environment of a Frame.
60 // Since Window and Document also have a 1:1 relationship, this means that each
61 // inner global object has an associated Document which does not change. On
62 // navigation, the new Document receives a new inner global object.
63 //
64 // However, there is one exception to the 1:1 DOMWindow:Document rule. If:
65 // - the previous Document is the initial empty document
66 // - the new Document is same-origin to the previous Document
67 // then the inner global object will be reused for the new Document. This is the
68 // only case where the associated Document of an inner global object can change.
69 //
70 // All methods and attributes defined on the Window interface are exposed via
71 // the inner global object. Global variables defined by script running in the
72 // Document also live on the inner global object.
73 //
74 // ====== Outer Global Proxy ====
75 // The outer global proxy is reused across navigations. It implements the
76 // security checks for same-origin/cross-origin access to the Window interface.
77 // When the check passes (i.e. the access is same-origin), the access is
78 // forwarded to the inner global object of the active Document in this
79 // WindowProxy's Frame).
80 //
81 // When the security check fails, the access is delegated to the outer global
82 // proxy's cross-origin interceptors. The cross-origin interceptors may choose
83 // to return a value (if the property is exposed cross-origin) or throw an
84 // exception otherwise.
85 //
86 // Note that the cross-origin interceptors are only used for cross-origin
87 // accesses: a same-origin access to a method that is available cross-origin,
88 // such as Window.postMessage, will be delegated to the inner global object.
89 //
90 // ====== LocalWindowProxy vs RemoteWindowProxy ======
91 // WindowProxy has two concrete subclasses:
92 // - LocalWindowProxy: implements the split window model for a frame in the same
93 // process, i.e. a LocalFrame.
94 // - RemoteWindowProxy: implements the split window model for a frame in a
95 // different process, i.e. a RemoteFrame.
96 //
97 // While having a RemoteFrame implies the frame must be cross-origin, the
98 // opposite is not true: a LocalFrame can be same-origin or cross-origin. One
99 // additional complexity (which slightly violates the HTML standard): it is
100 // possible to have SecurityOrigin::canAccess() return true for a RemoteFrame's
101 // security origin; however, it is important to still deny access as if the
102 // frame were cross-origin. This is due to complexities in the process
103 // allocation model for renderer processes. See https://crbug.com/601629.
104 //
105 // ====== LocalWindowProxy/RemoteWindowProxy ======
106 // Currently, the prototype chain for LocalWindowProxy and RemoteWindowProxy
107 // look the same:
108 //
109 // outer global proxy
110 // -- has prototype --> inner global object
111 // -- has prototype --> Window.prototype
112 // -- has prototype --> WindowProperties [1]
113 // -- has prototype --> EventTarget.prototype
114 // -- has prototype --> Object.prototype
115 // -- has prototype --> null
116 //
117 // [1] WindowProperties is the named properties object of the Window interface.
118 //
119 // There is work in progress to refactor RemoteWindowProxy to use remote v8
120 // contexts, to reduce the overhead of remote frames.
121 //
122 // ====== References ======
123 // https://wiki.mozilla.org/Gecko:SplitWindow
124 // https://whatwg.org/C/browsers.html#the-windowproxy-exotic-object
48 class WindowProxy : public GarbageCollectedFinalized<WindowProxy> { 125 class WindowProxy : public GarbageCollectedFinalized<WindowProxy> {
49 public: 126 public:
50 virtual ~WindowProxy(); 127 virtual ~WindowProxy();
51 128
52 DECLARE_TRACE(); 129 DECLARE_TRACE();
53 130
54 v8::Local<v8::Context> contextIfInitialized() const {
55 return m_scriptState ? m_scriptState->context() : v8::Local<v8::Context>();
56 }
57 void initializeIfNeeded(); 131 void initializeIfNeeded();
58 132
59 void clearForClose(); 133 void clearForClose();
60 void clearForNavigation(); 134 void clearForNavigation();
61 135
62 v8::Local<v8::Object> globalIfNotDetached(); 136 CORE_EXPORT v8::Local<v8::Object> globalIfNotDetached();
63 v8::Local<v8::Object> releaseGlobal(); 137 v8::Local<v8::Object> releaseGlobal();
64 void setGlobal(v8::Local<v8::Object>); 138 void setGlobal(v8::Local<v8::Object>);
65 139
66 // TODO(dcheng): Temporarily exposed to avoid include cycles. Remove the need 140 // TODO(dcheng): Temporarily exposed to avoid include cycles. Remove the need
67 // for this and remove this getter. 141 // for this and remove this getter.
68 DOMWrapperWorld& world() { return *m_world; } 142 DOMWrapperWorld& world() { return *m_world; }
69 143
70 protected: 144 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, 145 // A valid transition is from ContextUninitialized to ContextInitialized,
76 // and then ContextDetached. Other transitions are forbidden. 146 // and then ContextDetached. Other transitions are forbidden.
77 enum class Lifecycle { 147 enum class Lifecycle {
78 ContextUninitialized, 148 ContextUninitialized,
79 ContextInitialized, 149 ContextInitialized,
80 ContextDetached, 150 ContextDetached,
81 }; 151 };
82 152
83 WindowProxy(v8::Isolate*, Frame&, RefPtr<DOMWrapperWorld>); 153 WindowProxy(v8::Isolate*, Frame&, RefPtr<DOMWrapperWorld>);
84 154
85 virtual void initialize() = 0; 155 virtual void initialize() = 0;
86 156
87 enum GlobalDetachmentBehavior { DoNotDetachGlobal, DetachGlobal }; 157 enum GlobalDetachmentBehavior { DoNotDetachGlobal, DetachGlobal };
88 virtual void disposeContext(GlobalDetachmentBehavior); 158 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 159
94 v8::Isolate* isolate() const { return m_isolate; } 160 v8::Isolate* isolate() const { return m_isolate; }
95 Frame* frame() const { return m_frame.get(); } 161 Frame* frame() const { return m_frame.get(); }
96 ScriptState* getScriptState() const { return m_scriptState.get(); } 162
163 #if DCHECK_IS_ON()
164 void didAttachGlobalProxy() { m_isGlobalProxyAttached = true; }
165 void didDetachGlobalProxy() { m_isGlobalProxyAttached = false; }
166 #endif
97 167
98 private: 168 private:
99 v8::Isolate* const m_isolate; 169 v8::Isolate* const m_isolate;
100 const Member<Frame> m_frame; 170 const Member<Frame> m_frame;
171 #if DCHECK_IS_ON()
172 bool m_isGlobalProxyAttached = false;
173 #endif
101 174
102 protected: 175 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. 176 // TODO(dcheng): Consider making these private and using getters.
107 const RefPtr<DOMWrapperWorld> m_world; 177 const RefPtr<DOMWrapperWorld> m_world;
108 ScopedPersistent<v8::Object> m_globalProxy; 178 ScopedPersistent<v8::Object> m_globalProxy;
109 Lifecycle m_lifecycle; 179 Lifecycle m_lifecycle;
110 }; 180 };
111 181
112 } // namespace blink 182 } // namespace blink
113 183
114 #endif // WindowProxy_h 184 #endif // WindowProxy_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698