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

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

Issue 2721693002: Revert of Switch RemoteWindowProxy to use 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) 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 19 matching lines...) Expand all
30 30
31 #include "bindings/core/v8/LocalWindowProxy.h" 31 #include "bindings/core/v8/LocalWindowProxy.h"
32 32
33 #include <v8.h> 33 #include <v8.h>
34 #include "bindings/core/v8/ConditionalFeaturesForCore.h" 34 #include "bindings/core/v8/ConditionalFeaturesForCore.h"
35 #include "bindings/core/v8/DOMWrapperWorld.h" 35 #include "bindings/core/v8/DOMWrapperWorld.h"
36 #include "bindings/core/v8/ScriptController.h" 36 #include "bindings/core/v8/ScriptController.h"
37 #include "bindings/core/v8/ToV8.h" 37 #include "bindings/core/v8/ToV8.h"
38 #include "bindings/core/v8/V8Binding.h" 38 #include "bindings/core/v8/V8Binding.h"
39 #include "bindings/core/v8/V8DOMActivityLogger.h" 39 #include "bindings/core/v8/V8DOMActivityLogger.h"
40 #include "bindings/core/v8/V8GCForContextDispose.h"
41 #include "bindings/core/v8/V8HTMLDocument.h" 40 #include "bindings/core/v8/V8HTMLDocument.h"
42 #include "bindings/core/v8/V8HiddenValue.h" 41 #include "bindings/core/v8/V8HiddenValue.h"
43 #include "bindings/core/v8/V8Initializer.h" 42 #include "bindings/core/v8/V8Initializer.h"
44 #include "bindings/core/v8/V8PagePopupControllerBinding.h"
45 #include "bindings/core/v8/V8PrivateProperty.h" 43 #include "bindings/core/v8/V8PrivateProperty.h"
46 #include "bindings/core/v8/V8Window.h" 44 #include "bindings/core/v8/V8Window.h"
47 #include "core/dom/Modulator.h" 45 #include "core/dom/Modulator.h"
48 #include "core/frame/LocalFrame.h" 46 #include "core/frame/LocalFrame.h"
49 #include "core/frame/LocalFrameClient.h" 47 #include "core/frame/LocalFrameClient.h"
50 #include "core/frame/csp/ContentSecurityPolicy.h" 48 #include "core/frame/csp/ContentSecurityPolicy.h"
51 #include "core/html/DocumentNameCollection.h" 49 #include "core/html/DocumentNameCollection.h"
52 #include "core/html/HTMLIFrameElement.h" 50 #include "core/html/HTMLIFrameElement.h"
53 #include "core/inspector/MainThreadDebugger.h" 51 #include "core/inspector/MainThreadDebugger.h"
54 #include "core/loader/FrameLoader.h" 52 #include "core/loader/FrameLoader.h"
55 #include "core/origin_trials/OriginTrialContext.h" 53 #include "core/origin_trials/OriginTrialContext.h"
56 #include "platform/Histogram.h" 54 #include "platform/Histogram.h"
57 #include "platform/RuntimeEnabledFeatures.h" 55 #include "platform/RuntimeEnabledFeatures.h"
58 #include "platform/ScriptForbiddenScope.h" 56 #include "platform/ScriptForbiddenScope.h"
59 #include "platform/heap/Handle.h" 57 #include "platform/heap/Handle.h"
60 #include "platform/instrumentation/tracing/TraceEvent.h" 58 #include "platform/instrumentation/tracing/TraceEvent.h"
61 #include "platform/weborigin/SecurityOrigin.h" 59 #include "platform/weborigin/SecurityOrigin.h"
62 #include "v8/include/v8.h"
63 #include "wtf/Assertions.h" 60 #include "wtf/Assertions.h"
64 61
65 namespace blink { 62 namespace blink {
66 63
67 void LocalWindowProxy::disposeContext(GlobalDetachmentBehavior behavior) { 64 void LocalWindowProxy::disposeContext(GlobalDetachmentBehavior behavior) {
68 if (m_lifecycle != Lifecycle::ContextInitialized) 65 if (m_lifecycle != Lifecycle::ContextInitialized)
69 return; 66 return;
70 67
71 ScriptState::Scope scope(m_scriptState.get()); 68 ScriptState::Scope scope(m_scriptState.get());
72 v8::Local<v8::Context> context = m_scriptState->context(); 69 v8::Local<v8::Context> context = m_scriptState->context();
73 // The embedder could run arbitrary code in response to the 70 // The embedder could run arbitrary code in response to the
74 // willReleaseScriptContext callback, so all disposing should happen after 71 // willReleaseScriptContext callback, so all disposing should happen after
75 // it returns. 72 // it returns.
76 frame()->loader().client()->willReleaseScriptContext(context, 73 frame()->loader().client()->willReleaseScriptContext(context,
77 m_world->worldId()); 74 m_world->worldId());
78 MainThreadDebugger::instance()->contextWillBeDestroyed(m_scriptState.get()); 75 MainThreadDebugger::instance()->contextWillBeDestroyed(m_scriptState.get());
79 76
80 if (behavior == DetachGlobal) { 77 WindowProxy::disposeContext(behavior);
81 v8::Local<v8::Context> context = m_scriptState->context();
82 // Clean up state on the global proxy, which will be reused.
83 if (!m_globalProxy.isEmpty()) {
84 // TODO(yukishiino): This DCHECK failed on Canary (M57) and Dev (M56).
85 // We need to figure out why m_globalProxy != context->Global().
86 DCHECK(m_globalProxy == context->Global());
87 DCHECK_EQ(toScriptWrappable(context->Global()),
88 toScriptWrappable(
89 context->Global()->GetPrototype().As<v8::Object>()));
90 m_globalProxy.get().SetWrapperClassId(0);
91 }
92 V8DOMWrapper::clearNativeInfo(isolate(), context->Global());
93 m_scriptState->detachGlobalObject();
94
95 #if DCHECK_IS_ON()
96 didDetachGlobalProxy();
97 #endif
98 }
99
100 m_scriptState->disposePerContextData();
101
102 // It's likely that disposing the context has created a lot of
103 // garbage. Notify V8 about this so it'll have a chance of cleaning
104 // it up when idle.
105 V8GCForContextDispose::instance().notifyContextDisposed(
106 frame()->isMainFrame());
107
108 DCHECK(m_lifecycle == Lifecycle::ContextInitialized);
109 m_lifecycle = Lifecycle::ContextDetached;
110 } 78 }
111 79
112 void LocalWindowProxy::initialize() { 80 void LocalWindowProxy::initialize() {
113 TRACE_EVENT1("v8", "LocalWindowProxy::initialize", "isMainWindow", 81 TRACE_EVENT1("v8", "LocalWindowProxy::initialize", "isMainWindow",
114 frame()->isMainFrame()); 82 frame()->isMainFrame());
115 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( 83 SCOPED_BLINK_UMA_HISTOGRAM_TIMER(
116 frame()->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy" 84 frame()->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy"
117 : "Blink.Binding.InitializeNonMainWindowProxy"); 85 : "Blink.Binding.InitializeNonMainWindowProxy");
118 86
119 ScriptForbiddenScope::AllowUserAgentScript allowScript; 87 ScriptForbiddenScope::AllowUserAgentScript allowScript;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // If conditional features for window have been queued before the V8 context 123 // If conditional features for window have been queued before the V8 context
156 // was ready, then inject them into the context now 124 // was ready, then inject them into the context now
157 if (m_world->isMainWorld()) { 125 if (m_world->isMainWorld()) {
158 installConditionalFeaturesOnWindow(m_scriptState.get()); 126 installConditionalFeaturesOnWindow(m_scriptState.get());
159 } 127 }
160 128
161 if (m_world->isMainWorld()) 129 if (m_world->isMainWorld())
162 frame()->loader().dispatchDidClearWindowObjectInMainWorld(); 130 frame()->loader().dispatchDidClearWindowObjectInMainWorld();
163 } 131 }
164 132
165 void LocalWindowProxy::setupWindowPrototypeChain() {
166 // Associate the window wrapper object and its prototype chain with the
167 // corresponding native DOMWindow object.
168 LocalDOMWindow* window = frame()->domWindow();
169 const WrapperTypeInfo* wrapperTypeInfo = window->wrapperTypeInfo();
170 v8::Local<v8::Context> context = m_scriptState->context();
171
172 // The global proxy object. Note this is not the global object.
173 v8::Local<v8::Object> globalProxy = context->Global();
174 CHECK(m_globalProxy == globalProxy);
175 V8DOMWrapper::setNativeInfo(isolate(), globalProxy, wrapperTypeInfo, window);
176 // Mark the handle to be traced by Oilpan, since the global proxy has a
177 // reference to the DOMWindow.
178 m_globalProxy.get().SetWrapperClassId(wrapperTypeInfo->wrapperClassId);
179
180 #if DCHECK_IS_ON()
181 didAttachGlobalProxy();
182 #endif
183
184 // The global object, aka window wrapper object.
185 v8::Local<v8::Object> windowWrapper =
186 globalProxy->GetPrototype().As<v8::Object>();
187 V8DOMWrapper::setNativeInfo(isolate(), windowWrapper, wrapperTypeInfo,
188 window);
189
190 // The prototype object of Window interface.
191 v8::Local<v8::Object> windowPrototype =
192 windowWrapper->GetPrototype().As<v8::Object>();
193 CHECK(!windowPrototype.IsEmpty());
194 V8DOMWrapper::setNativeInfo(isolate(), windowPrototype, wrapperTypeInfo,
195 window);
196
197 // The named properties object of Window interface.
198 v8::Local<v8::Object> windowProperties =
199 windowPrototype->GetPrototype().As<v8::Object>();
200 CHECK(!windowProperties.IsEmpty());
201 V8DOMWrapper::setNativeInfo(isolate(), windowProperties, wrapperTypeInfo,
202 window);
203
204 // TODO(keishi): Remove installPagePopupController and implement
205 // PagePopupController in another way.
206 V8PagePopupControllerBinding::installPagePopupController(context,
207 windowWrapper);
208 }
209
210 void LocalWindowProxy::createContext() { 133 void LocalWindowProxy::createContext() {
211 // Create a new v8::Context with the window object as the global object 134 // Create a new v8::Context with the window object as the global object
212 // (aka the inner global). Reuse the outer global proxy if it already exists. 135 // (aka the inner global). Reuse the global proxy object (aka the outer
136 // global) if it already exists. See the comments in
137 // setupWindowPrototypeChain for the structure of the prototype chain of
138 // the global object.
213 v8::Local<v8::ObjectTemplate> globalTemplate = 139 v8::Local<v8::ObjectTemplate> globalTemplate =
214 V8Window::domTemplate(isolate(), *m_world)->InstanceTemplate(); 140 V8Window::domTemplate(isolate(), *m_world)->InstanceTemplate();
215 CHECK(!globalTemplate.IsEmpty()); 141 CHECK(!globalTemplate.IsEmpty());
216 142
217 Vector<const char*> extensionNames; 143 Vector<const char*> extensionNames;
218 // Dynamically tell v8 about our extensions now. 144 // Dynamically tell v8 about our extensions now.
219 if (frame()->loader().client()->allowScriptExtensions()) { 145 if (frame()->loader().client()->allowScriptExtensions()) {
220 const V8Extensions& extensions = ScriptController::registeredExtensions(); 146 const V8Extensions& extensions = ScriptController::registeredExtensions();
221 extensionNames.reserveInitialCapacity(extensions.size()); 147 extensionNames.reserveInitialCapacity(extensions.size());
222 for (const auto* extension : extensions) 148 for (const auto* extension : extensions)
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 354
429 setSecurityToken(origin); 355 setSecurityToken(origin);
430 } 356 }
431 357
432 LocalWindowProxy::LocalWindowProxy(v8::Isolate* isolate, 358 LocalWindowProxy::LocalWindowProxy(v8::Isolate* isolate,
433 LocalFrame& frame, 359 LocalFrame& frame,
434 RefPtr<DOMWrapperWorld> world) 360 RefPtr<DOMWrapperWorld> world)
435 : WindowProxy(isolate, frame, std::move(world)) {} 361 : WindowProxy(isolate, frame, std::move(world)) {}
436 362
437 } // namespace blink 363 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698