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

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

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) 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 10 matching lines...) Expand all
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
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 #include "bindings/core/v8/WindowProxy.h" 31 #include "bindings/core/v8/RemoteWindowProxy.h"
32 32
33 #include <v8-debug.h>
34 #include <v8.h>
35 #include <algorithm>
36 #include <utility>
37 #include "bindings/core/v8/ConditionalFeatures.h"
38 #include "bindings/core/v8/DOMWrapperWorld.h" 33 #include "bindings/core/v8/DOMWrapperWorld.h"
39 #include "bindings/core/v8/ScriptController.h" 34 #include "bindings/core/v8/V8DOMWrapper.h"
40 #include "bindings/core/v8/ToV8.h"
41 #include "bindings/core/v8/V8Binding.h"
42 #include "bindings/core/v8/V8DOMActivityLogger.h"
43 #include "bindings/core/v8/V8Document.h"
44 #include "bindings/core/v8/V8GCForContextDispose.h"
45 #include "bindings/core/v8/V8HTMLCollection.h"
46 #include "bindings/core/v8/V8HTMLDocument.h"
47 #include "bindings/core/v8/V8HiddenValue.h"
48 #include "bindings/core/v8/V8Initializer.h"
49 #include "bindings/core/v8/V8ObjectConstructor.h"
50 #include "bindings/core/v8/V8PagePopupControllerBinding.h"
51 #include "bindings/core/v8/V8PrivateProperty.h"
52 #include "bindings/core/v8/V8Window.h" 35 #include "bindings/core/v8/V8Window.h"
53 #include "core/frame/LocalFrame.h"
54 #include "core/frame/LocalFrameClient.h"
55 #include "core/frame/csp/ContentSecurityPolicy.h"
56 #include "core/html/DocumentNameCollection.h"
57 #include "core/html/HTMLCollection.h"
58 #include "core/html/HTMLIFrameElement.h"
59 #include "core/inspector/InspectorInstrumentation.h"
60 #include "core/inspector/MainThreadDebugger.h"
61 #include "core/loader/DocumentLoader.h"
62 #include "core/loader/FrameLoader.h"
63 #include "core/origin_trials/OriginTrialContext.h"
64 #include "platform/Histogram.h" 36 #include "platform/Histogram.h"
65 #include "platform/RuntimeEnabledFeatures.h"
66 #include "platform/ScriptForbiddenScope.h"
67 #include "platform/heap/Handle.h"
68 #include "platform/instrumentation/tracing/TraceEvent.h" 37 #include "platform/instrumentation/tracing/TraceEvent.h"
69 #include "platform/weborigin/SecurityOrigin.h" 38 #include "v8/include/v8.h"
70 #include "public/platform/Platform.h"
71 #include "wtf/Assertions.h" 39 #include "wtf/Assertions.h"
72 #include "wtf/StringExtras.h"
73 #include "wtf/text/CString.h"
74 40
75 namespace blink { 41 namespace blink {
76 42
77 RemoteWindowProxy::RemoteWindowProxy(v8::Isolate* isolate, 43 RemoteWindowProxy::RemoteWindowProxy(v8::Isolate* isolate,
78 RemoteFrame& frame, 44 RemoteFrame& frame,
79 RefPtr<DOMWrapperWorld> world) 45 RefPtr<DOMWrapperWorld> world)
80 : WindowProxy(isolate, frame, std::move(world)) {} 46 : WindowProxy(isolate, frame, std::move(world)) {}
81 47
82 void RemoteWindowProxy::disposeContext(GlobalDetachmentBehavior behavior) { 48 void RemoteWindowProxy::disposeContext(GlobalDetachmentBehavior behavior) {
83 if (m_lifecycle != Lifecycle::ContextInitialized) 49 if (m_lifecycle != Lifecycle::ContextInitialized)
84 return; 50 return;
85 51
86 WindowProxy::disposeContext(behavior); 52 if (behavior == DetachGlobal && !m_globalProxy.isEmpty()) {
53 m_globalProxy.get().SetWrapperClassId(0);
54 V8DOMWrapper::clearNativeInfo(isolate(), m_globalProxy.newLocal(isolate()));
55 #if DCHECK_IS_ON()
56 didDetachGlobalProxy();
57 #endif
58 }
59
60 DCHECK_EQ(Lifecycle::ContextInitialized, m_lifecycle);
61 m_lifecycle = Lifecycle::ContextDetached;
87 } 62 }
88 63
89 void RemoteWindowProxy::initialize() { 64 void RemoteWindowProxy::initialize() {
90 TRACE_EVENT1("v8", "RemoteWindowProxy::initialize", "isMainWindow", 65 TRACE_EVENT1("v8", "RemoteWindowProxy::initialize", "isMainWindow",
91 frame()->isMainFrame()); 66 frame()->isMainFrame());
92 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( 67 SCOPED_BLINK_UMA_HISTOGRAM_TIMER(
93 frame()->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy" 68 frame()->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy"
94 : "Blink.Binding.InitializeNonMainWindowProxy"); 69 : "Blink.Binding.InitializeNonMainWindowProxy");
95 70
96 ScriptForbiddenScope::AllowUserAgentScript allowScript;
97
98 v8::HandleScope handleScope(isolate()); 71 v8::HandleScope handleScope(isolate());
99 72
100 createContext(); 73 createContext();
101 74
102 ScriptState::Scope scope(m_scriptState.get());
103 v8::Local<v8::Context> context = m_scriptState->context();
104 if (m_globalProxy.isEmpty()) {
105 m_globalProxy.set(isolate(), context->Global());
106 CHECK(!m_globalProxy.isEmpty());
107 }
108
109 setupWindowPrototypeChain(); 75 setupWindowPrototypeChain();
110
111 // Remote frames always require a full canAccess() check.
112 context->UseDefaultSecurityToken();
113 } 76 }
114 77
115 void RemoteWindowProxy::createContext() { 78 void RemoteWindowProxy::createContext() {
116 // Create a new v8::Context with the window object as the global object 79 // Create a new v8::Context with the window object as the global object
117 // (aka the inner global). Reuse the global proxy object (aka the outer 80 // (aka the inner global). Reuse the global proxy object (aka the outer
118 // global) if it already exists. See the comments in 81 // global) if it already exists. See the comments in
119 // setupWindowPrototypeChain for the structure of the prototype chain of 82 // setupWindowPrototypeChain for the structure of the prototype chain of
120 // the global object. 83 // the global object.
121 v8::Local<v8::ObjectTemplate> globalTemplate = 84 v8::Local<v8::ObjectTemplate> globalTemplate =
122 V8Window::domTemplate(isolate(), *m_world)->InstanceTemplate(); 85 V8Window::domTemplate(isolate(), *m_world)->InstanceTemplate();
123 CHECK(!globalTemplate.IsEmpty()); 86 CHECK(!globalTemplate.IsEmpty());
124 87
125 v8::Local<v8::Context> context; 88 v8::Local<v8::Object> globalProxy =
126 { 89 v8::Context::NewRemoteContext(isolate(), globalTemplate,
127 V8PerIsolateData::UseCounterDisabledScope useCounterDisabled( 90 m_globalProxy.newLocal(isolate()))
128 V8PerIsolateData::from(isolate())); 91 .ToLocalChecked();
129 context = v8::Context::New(isolate(), nullptr, globalTemplate, 92 if (m_globalProxy.isEmpty())
130 m_globalProxy.newLocal(isolate())); 93 m_globalProxy.set(isolate(), globalProxy);
131 } 94 else
132 CHECK(!context.IsEmpty()); 95 DCHECK(m_globalProxy.get() == globalProxy);
133 96 CHECK(!m_globalProxy.isEmpty());
134 m_scriptState = ScriptState::create(context, m_world);
135 97
136 // TODO(haraken): Currently we cannot enable the following DCHECK because 98 // TODO(haraken): Currently we cannot enable the following DCHECK because
137 // an already detached window proxy can be re-initialized. This is wrong. 99 // an already detached window proxy can be re-initialized. This is wrong.
138 // DCHECK(m_lifecycle == Lifecycle::ContextUninitialized); 100 // DCHECK(m_lifecycle == Lifecycle::ContextUninitialized);
139 m_lifecycle = Lifecycle::ContextInitialized; 101 m_lifecycle = Lifecycle::ContextInitialized;
140 DCHECK(m_scriptState->contextIsValid()); 102 }
103
104 void RemoteWindowProxy::setupWindowPrototypeChain() {
105 DOMWindow* window = frame()->domWindow();
106 const WrapperTypeInfo* wrapperTypeInfo = window->wrapperTypeInfo();
107 // The global proxy object. Note this is not the global object.
108 v8::Local<v8::Object> globalProxy = m_globalProxy.newLocal(isolate());
109 V8DOMWrapper::setNativeInfo(isolate(), globalProxy, wrapperTypeInfo, window);
110 // Mark the handle to be traced by Oilpan, since the global proxy has a
111 // reference to the DOMWindow.
112 m_globalProxy.get().SetWrapperClassId(wrapperTypeInfo->wrapperClassId);
113
114 #if DCHECK_IS_ON()
115 didAttachGlobalProxy();
116 #endif
117
118 // The global object, aka window wrapper object.
119 v8::Local<v8::Object> windowWrapper =
120 globalProxy->GetPrototype().As<v8::Object>();
121 V8DOMWrapper::setNativeInfo(isolate(), windowWrapper, wrapperTypeInfo,
122 window);
141 } 123 }
142 124
143 } // namespace blink 125 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698