OLD | NEW |
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 Loading... |
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/ConditionalFeaturesForCore.h" | 33 #include "bindings/core/v8/ConditionalFeaturesForCore.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" | |
40 #include "bindings/core/v8/V8HTMLDocument.h" | 39 #include "bindings/core/v8/V8HTMLDocument.h" |
41 #include "bindings/core/v8/V8HiddenValue.h" | 40 #include "bindings/core/v8/V8HiddenValue.h" |
42 #include "bindings/core/v8/V8Initializer.h" | 41 #include "bindings/core/v8/V8Initializer.h" |
43 #include "bindings/core/v8/V8PagePopupControllerBinding.h" | |
44 #include "bindings/core/v8/V8PrivateProperty.h" | 42 #include "bindings/core/v8/V8PrivateProperty.h" |
45 #include "bindings/core/v8/V8Window.h" | 43 #include "bindings/core/v8/V8Window.h" |
46 #include "core/dom/Modulator.h" | 44 #include "core/dom/Modulator.h" |
47 #include "core/frame/LocalFrame.h" | 45 #include "core/frame/LocalFrame.h" |
48 #include "core/frame/LocalFrameClient.h" | 46 #include "core/frame/LocalFrameClient.h" |
49 #include "core/frame/csp/ContentSecurityPolicy.h" | 47 #include "core/frame/csp/ContentSecurityPolicy.h" |
50 #include "core/html/DocumentNameCollection.h" | 48 #include "core/html/DocumentNameCollection.h" |
51 #include "core/html/HTMLIFrameElement.h" | 49 #include "core/html/HTMLIFrameElement.h" |
52 #include "core/inspector/MainThreadDebugger.h" | 50 #include "core/inspector/MainThreadDebugger.h" |
53 #include "core/loader/FrameLoader.h" | 51 #include "core/loader/FrameLoader.h" |
(...skipping 15 matching lines...) Expand all Loading... |
69 | 67 |
70 ScriptState::Scope scope(m_scriptState.get()); | 68 ScriptState::Scope scope(m_scriptState.get()); |
71 v8::Local<v8::Context> context = m_scriptState->context(); | 69 v8::Local<v8::Context> context = m_scriptState->context(); |
72 // The embedder could run arbitrary code in response to the | 70 // The embedder could run arbitrary code in response to the |
73 // willReleaseScriptContext callback, so all disposing should happen after | 71 // willReleaseScriptContext callback, so all disposing should happen after |
74 // it returns. | 72 // it returns. |
75 frame()->loader().client()->willReleaseScriptContext(context, | 73 frame()->loader().client()->willReleaseScriptContext(context, |
76 m_world->worldId()); | 74 m_world->worldId()); |
77 MainThreadDebugger::instance()->contextWillBeDestroyed(m_scriptState.get()); | 75 MainThreadDebugger::instance()->contextWillBeDestroyed(m_scriptState.get()); |
78 | 76 |
79 if (behavior == DetachGlobal) { | 77 WindowProxy::disposeContext(behavior); |
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; | |
109 } | 78 } |
110 | 79 |
111 void LocalWindowProxy::initialize() { | 80 void LocalWindowProxy::initialize() { |
112 TRACE_EVENT1("v8", "LocalWindowProxy::initialize", "isMainWindow", | 81 TRACE_EVENT1("v8", "LocalWindowProxy::initialize", "isMainWindow", |
113 frame()->isMainFrame()); | 82 frame()->isMainFrame()); |
114 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( | 83 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( |
115 frame()->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy" | 84 frame()->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy" |
116 : "Blink.Binding.InitializeNonMainWindowProxy"); | 85 : "Blink.Binding.InitializeNonMainWindowProxy"); |
117 | 86 |
118 ScriptForbiddenScope::AllowUserAgentScript allowScript; | 87 ScriptForbiddenScope::AllowUserAgentScript allowScript; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 // 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 |
155 // was ready, then inject them into the context now | 124 // was ready, then inject them into the context now |
156 if (m_world->isMainWorld()) { | 125 if (m_world->isMainWorld()) { |
157 installConditionalFeaturesOnWindow(m_scriptState.get()); | 126 installConditionalFeaturesOnWindow(m_scriptState.get()); |
158 } | 127 } |
159 | 128 |
160 if (m_world->isMainWorld()) | 129 if (m_world->isMainWorld()) |
161 frame()->loader().dispatchDidClearWindowObjectInMainWorld(); | 130 frame()->loader().dispatchDidClearWindowObjectInMainWorld(); |
162 } | 131 } |
163 | 132 |
164 void LocalWindowProxy::setupWindowPrototypeChain() { | |
165 // Associate the window wrapper object and its prototype chain with the | |
166 // corresponding native DOMWindow object. | |
167 LocalDOMWindow* window = frame()->domWindow(); | |
168 const WrapperTypeInfo* wrapperTypeInfo = window->wrapperTypeInfo(); | |
169 v8::Local<v8::Context> context = m_scriptState->context(); | |
170 | |
171 // The global proxy object. Note this is not the global object. | |
172 v8::Local<v8::Object> globalProxy = context->Global(); | |
173 CHECK(m_globalProxy == globalProxy); | |
174 V8DOMWrapper::setNativeInfo(isolate(), globalProxy, wrapperTypeInfo, window); | |
175 // Mark the handle to be traced by Oilpan, since the global proxy has a | |
176 // reference to the DOMWindow. | |
177 m_globalProxy.get().SetWrapperClassId(wrapperTypeInfo->wrapperClassId); | |
178 | |
179 #if DCHECK_IS_ON() | |
180 didAttachGlobalProxy(); | |
181 #endif | |
182 | |
183 // The global object, aka window wrapper object. | |
184 v8::Local<v8::Object> windowWrapper = | |
185 globalProxy->GetPrototype().As<v8::Object>(); | |
186 V8DOMWrapper::setNativeInfo(isolate(), windowWrapper, wrapperTypeInfo, | |
187 window); | |
188 | |
189 // The prototype object of Window interface. | |
190 v8::Local<v8::Object> windowPrototype = | |
191 windowWrapper->GetPrototype().As<v8::Object>(); | |
192 CHECK(!windowPrototype.IsEmpty()); | |
193 V8DOMWrapper::setNativeInfo(isolate(), windowPrototype, wrapperTypeInfo, | |
194 window); | |
195 | |
196 // The named properties object of Window interface. | |
197 v8::Local<v8::Object> windowProperties = | |
198 windowPrototype->GetPrototype().As<v8::Object>(); | |
199 CHECK(!windowProperties.IsEmpty()); | |
200 V8DOMWrapper::setNativeInfo(isolate(), windowProperties, wrapperTypeInfo, | |
201 window); | |
202 | |
203 // TODO(keishi): Remove installPagePopupController and implement | |
204 // PagePopupController in another way. | |
205 V8PagePopupControllerBinding::installPagePopupController(context, | |
206 windowWrapper); | |
207 } | |
208 | |
209 void LocalWindowProxy::createContext() { | 133 void LocalWindowProxy::createContext() { |
210 // 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 |
211 // (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. |
212 v8::Local<v8::ObjectTemplate> globalTemplate = | 139 v8::Local<v8::ObjectTemplate> globalTemplate = |
213 V8Window::domTemplate(isolate(), *m_world)->InstanceTemplate(); | 140 V8Window::domTemplate(isolate(), *m_world)->InstanceTemplate(); |
214 CHECK(!globalTemplate.IsEmpty()); | 141 CHECK(!globalTemplate.IsEmpty()); |
215 | 142 |
216 Vector<const char*> extensionNames; | 143 Vector<const char*> extensionNames; |
217 // Dynamically tell v8 about our extensions now. | 144 // Dynamically tell v8 about our extensions now. |
218 if (frame()->loader().client()->allowScriptExtensions()) { | 145 if (frame()->loader().client()->allowScriptExtensions()) { |
219 const V8Extensions& extensions = ScriptController::registeredExtensions(); | 146 const V8Extensions& extensions = ScriptController::registeredExtensions(); |
220 extensionNames.reserveInitialCapacity(extensions.size()); | 147 extensionNames.reserveInitialCapacity(extensions.size()); |
221 for (const auto* extension : extensions) | 148 for (const auto* extension : extensions) |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 | 354 |
428 setSecurityToken(origin); | 355 setSecurityToken(origin); |
429 } | 356 } |
430 | 357 |
431 LocalWindowProxy::LocalWindowProxy(v8::Isolate* isolate, | 358 LocalWindowProxy::LocalWindowProxy(v8::Isolate* isolate, |
432 LocalFrame& frame, | 359 LocalFrame& frame, |
433 RefPtr<DOMWrapperWorld> world) | 360 RefPtr<DOMWrapperWorld> world) |
434 : WindowProxy(isolate, frame, std::move(world)) {} | 361 : WindowProxy(isolate, frame, std::move(world)) {} |
435 | 362 |
436 } // namespace blink | 363 } // namespace blink |
OLD | NEW |