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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/LocalWindowProxy.cpp

Issue 2626183003: Switch RemoteWindowProxy to use v8::Context::NewRemoteContext. (Closed)
Patch Set: rebase 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 /* 1 /*
2 * Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2008, 2009, 2011 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 18 matching lines...) Expand all
29 */ 29 */
30 30
31 #include "bindings/core/v8/LocalWindowProxy.h" 31 #include "bindings/core/v8/LocalWindowProxy.h"
32 32
33 #include "bindings/core/v8/ConditionalFeatures.h" 33 #include "bindings/core/v8/ConditionalFeatures.h"
34 #include "bindings/core/v8/DOMWrapperWorld.h" 34 #include "bindings/core/v8/DOMWrapperWorld.h"
35 #include "bindings/core/v8/ScriptController.h" 35 #include "bindings/core/v8/ScriptController.h"
36 #include "bindings/core/v8/ToV8.h" 36 #include "bindings/core/v8/ToV8.h"
37 #include "bindings/core/v8/V8Binding.h" 37 #include "bindings/core/v8/V8Binding.h"
38 #include "bindings/core/v8/V8DOMActivityLogger.h" 38 #include "bindings/core/v8/V8DOMActivityLogger.h"
39 #include "bindings/core/v8/V8GCForContextDispose.h"
39 #include "bindings/core/v8/V8HTMLDocument.h" 40 #include "bindings/core/v8/V8HTMLDocument.h"
40 #include "bindings/core/v8/V8HiddenValue.h" 41 #include "bindings/core/v8/V8HiddenValue.h"
41 #include "bindings/core/v8/V8Initializer.h" 42 #include "bindings/core/v8/V8Initializer.h"
43 #include "bindings/core/v8/V8PagePopupControllerBinding.h"
42 #include "bindings/core/v8/V8PrivateProperty.h" 44 #include "bindings/core/v8/V8PrivateProperty.h"
43 #include "bindings/core/v8/V8Window.h" 45 #include "bindings/core/v8/V8Window.h"
44 #include "core/dom/Modulator.h" 46 #include "core/dom/Modulator.h"
45 #include "core/frame/LocalFrame.h" 47 #include "core/frame/LocalFrame.h"
46 #include "core/frame/csp/ContentSecurityPolicy.h" 48 #include "core/frame/csp/ContentSecurityPolicy.h"
47 #include "core/html/DocumentNameCollection.h" 49 #include "core/html/DocumentNameCollection.h"
48 #include "core/html/HTMLIFrameElement.h" 50 #include "core/html/HTMLIFrameElement.h"
49 #include "core/inspector/MainThreadDebugger.h" 51 #include "core/inspector/MainThreadDebugger.h"
50 #include "core/loader/FrameLoader.h" 52 #include "core/loader/FrameLoader.h"
51 #include "core/loader/FrameLoaderClient.h" 53 #include "core/loader/FrameLoaderClient.h"
52 #include "core/origin_trials/OriginTrialContext.h" 54 #include "core/origin_trials/OriginTrialContext.h"
53 #include "platform/Histogram.h" 55 #include "platform/Histogram.h"
54 #include "platform/RuntimeEnabledFeatures.h" 56 #include "platform/RuntimeEnabledFeatures.h"
55 #include "platform/ScriptForbiddenScope.h" 57 #include "platform/ScriptForbiddenScope.h"
56 #include "platform/heap/Handle.h" 58 #include "platform/heap/Handle.h"
57 #include "platform/instrumentation/tracing/TraceEvent.h" 59 #include "platform/instrumentation/tracing/TraceEvent.h"
58 #include "platform/weborigin/SecurityOrigin.h" 60 #include "platform/weborigin/SecurityOrigin.h"
61 #include "v8/include/v8.h"
59 #include "wtf/Assertions.h" 62 #include "wtf/Assertions.h"
60 #include <v8.h>
61 63
62 namespace blink { 64 namespace blink {
63 65
64 void LocalWindowProxy::disposeContext(GlobalDetachmentBehavior behavior) { 66 void LocalWindowProxy::disposeContext(GlobalDetachmentBehavior behavior) {
65 if (m_lifecycle != Lifecycle::ContextInitialized) 67 if (m_lifecycle != Lifecycle::ContextInitialized)
66 return; 68 return;
67 69
68 ScriptState::Scope scope(m_scriptState.get()); 70 ScriptState::Scope scope(m_scriptState.get());
69 v8::Local<v8::Context> context = m_scriptState->context(); 71 v8::Local<v8::Context> context = m_scriptState->context();
70 // The embedder could run arbitrary code in response to the 72 // The embedder could run arbitrary code in response to the
71 // willReleaseScriptContext callback, so all disposing should happen after 73 // willReleaseScriptContext callback, so all disposing should happen after
72 // it returns. 74 // it returns.
73 frame()->loader().client()->willReleaseScriptContext(context, 75 frame()->loader().client()->willReleaseScriptContext(context,
74 m_world->worldId()); 76 m_world->worldId());
75 MainThreadDebugger::instance()->contextWillBeDestroyed(m_scriptState.get()); 77 MainThreadDebugger::instance()->contextWillBeDestroyed(m_scriptState.get());
76 78
77 WindowProxy::disposeContext(behavior); 79 if (behavior == DetachGlobal) {
80 v8::Local<v8::Context> context = m_scriptState->context();
81 // Clean up state on the global proxy, which will be reused.
82 if (!m_globalProxy.isEmpty()) {
83 // TODO(yukishiino): This DCHECK failed on Canary (M57) and Dev (M56).
84 // We need to figure out why m_globalProxy != context->Global().
85 DCHECK(m_globalProxy == context->Global());
86 DCHECK_EQ(toScriptWrappable(context->Global()),
87 toScriptWrappable(
88 context->Global()->GetPrototype().As<v8::Object>()));
89 m_globalProxy.get().SetWrapperClassId(0);
90 }
91 V8DOMWrapper::clearNativeInfo(isolate(), context->Global());
92 m_scriptState->detachGlobalObject();
93
94 #if DCHECK_IS_ON()
95 didDetachGlobalProxy();
96 #endif
97 }
98
99 m_scriptState->disposePerContextData();
100
101 // It's likely that disposing the context has created a lot of
102 // garbage. Notify V8 about this so it'll have a chance of cleaning
103 // it up when idle.
104 V8GCForContextDispose::instance().notifyContextDisposed(
105 frame()->isMainFrame());
106
107 DCHECK(m_lifecycle == Lifecycle::ContextInitialized);
108 m_lifecycle = Lifecycle::ContextDetached;
78 } 109 }
79 110
80 void LocalWindowProxy::initialize() { 111 void LocalWindowProxy::initialize() {
81 TRACE_EVENT1("v8", "LocalWindowProxy::initialize", "isMainWindow", 112 TRACE_EVENT1("v8", "LocalWindowProxy::initialize", "isMainWindow",
82 frame()->isMainFrame()); 113 frame()->isMainFrame());
83 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( 114 SCOPED_BLINK_UMA_HISTOGRAM_TIMER(
84 frame()->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy" 115 frame()->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy"
85 : "Blink.Binding.InitializeNonMainWindowProxy"); 116 : "Blink.Binding.InitializeNonMainWindowProxy");
86 117
87 ScriptForbiddenScope::AllowUserAgentScript allowScript; 118 ScriptForbiddenScope::AllowUserAgentScript allowScript;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 // If conditional features for window have been queued before the V8 context 154 // If conditional features for window have been queued before the V8 context
124 // was ready, then inject them into the context now 155 // was ready, then inject them into the context now
125 if (m_world->isMainWorld()) { 156 if (m_world->isMainWorld()) {
126 installConditionalFeaturesOnWindow(m_scriptState.get()); 157 installConditionalFeaturesOnWindow(m_scriptState.get());
127 } 158 }
128 159
129 if (m_world->isMainWorld()) 160 if (m_world->isMainWorld())
130 frame()->loader().dispatchDidClearWindowObjectInMainWorld(); 161 frame()->loader().dispatchDidClearWindowObjectInMainWorld();
131 } 162 }
132 163
164 void LocalWindowProxy::setupWindowPrototypeChain() {
165 // Associate the window wrapper object and its prototype chain with the
166 // corresponding native DOMWindow object.
167 // The full structure of the global object's prototype chain is as follows:
168 //
169 // global proxy object [1]
170 // -- has prototype --> global object (window wrapper object) [2]
171 // -- has prototype --> Window.prototype
172 // -- has prototype --> WindowProperties [3]
173 // -- has prototype --> EventTarget.prototype
174 // -- has prototype --> Object.prototype
175 // -- has prototype --> null
176 //
177 // [1] Global proxy object is as known as "outer global object". It's an
178 // empty object and remains after navigation. When navigated, points to
179 // a different global object as the prototype object.
180 // [2] Global object is as known as "inner global object" or "window wrapper
181 // object". The prototype chain between global proxy object and global
182 // object is NOT observable from user JavaScript code. All other
183 // prototype chains are observable. Global proxy object and global object
184 // together appear to be the same single JavaScript object. See also:
185 // https://wiki.mozilla.org/Gecko:SplitWindow
186 // global object (= window wrapper object) provides most of Window's DOM
187 // attributes and operations. Also global variables defined by user
188 // JavaScript are placed on this object. When navigated, a new global
189 // object is created together with a new v8::Context, but the global proxy
190 // object doesn't change.
191 // [3] WindowProperties is a named properties object of Window interface.
192
193 LocalDOMWindow* window = frame()->domWindow();
194 const WrapperTypeInfo* wrapperTypeInfo = window->wrapperTypeInfo();
195 v8::Local<v8::Context> context = m_scriptState->context();
196
197 // The global proxy object. Note this is not the global object.
198 v8::Local<v8::Object> globalProxy = context->Global();
199 CHECK(m_globalProxy == globalProxy);
200 V8DOMWrapper::setNativeInfo(isolate(), globalProxy, wrapperTypeInfo, window);
201 // Mark the handle to be traced by Oilpan, since the global proxy has a
202 // reference to the DOMWindow.
203 m_globalProxy.get().SetWrapperClassId(wrapperTypeInfo->wrapperClassId);
204
205 #if DCHECK_IS_ON()
206 didAttachGlobalProxy();
207 #endif
208
209 // The global object, aka window wrapper object.
210 v8::Local<v8::Object> windowWrapper =
211 globalProxy->GetPrototype().As<v8::Object>();
212 V8DOMWrapper::setNativeInfo(isolate(), windowWrapper, wrapperTypeInfo,
213 window);
214
215 // The prototype object of Window interface.
216 v8::Local<v8::Object> windowPrototype =
217 windowWrapper->GetPrototype().As<v8::Object>();
218 CHECK(!windowPrototype.IsEmpty());
219 V8DOMWrapper::setNativeInfo(isolate(), windowPrototype, wrapperTypeInfo,
220 window);
221
222 // The named properties object of Window interface.
223 v8::Local<v8::Object> windowProperties =
224 windowPrototype->GetPrototype().As<v8::Object>();
225 CHECK(!windowProperties.IsEmpty());
226 V8DOMWrapper::setNativeInfo(isolate(), windowProperties, wrapperTypeInfo,
227 window);
228
229 // TODO(keishi): Remove installPagePopupController and implement
230 // PagePopupController in another way.
231 V8PagePopupControllerBinding::installPagePopupController(context,
232 windowWrapper);
233 }
234
133 void LocalWindowProxy::createContext() { 235 void LocalWindowProxy::createContext() {
134 // Create a new v8::Context with the window object as the global object 236 // Create a new v8::Context with the window object as the global object
135 // (aka the inner global). Reuse the global proxy object (aka the outer 237 // (aka the inner global). Reuse the global proxy object (aka the outer
136 // global) if it already exists. See the comments in 238 // global) if it already exists. See the comments in
137 // setupWindowPrototypeChain for the structure of the prototype chain of 239 // setupWindowPrototypeChain for the structure of the prototype chain of
138 // the global object. 240 // the global object.
139 v8::Local<v8::ObjectTemplate> globalTemplate = 241 v8::Local<v8::ObjectTemplate> globalTemplate =
140 V8Window::domTemplate(isolate(), *m_world)->InstanceTemplate(); 242 V8Window::domTemplate(isolate(), *m_world)->InstanceTemplate();
141 CHECK(!globalTemplate.IsEmpty()); 243 CHECK(!globalTemplate.IsEmpty());
142 244
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 456
355 setSecurityToken(origin); 457 setSecurityToken(origin);
356 } 458 }
357 459
358 LocalWindowProxy::LocalWindowProxy(v8::Isolate* isolate, 460 LocalWindowProxy::LocalWindowProxy(v8::Isolate* isolate,
359 LocalFrame& frame, 461 LocalFrame& frame,
360 RefPtr<DOMWrapperWorld> world) 462 RefPtr<DOMWrapperWorld> world)
361 : WindowProxy(isolate, frame, std::move(world)) {} 463 : WindowProxy(isolate, frame, std::move(world)) {}
362 464
363 } // namespace blink 465 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698