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/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/frame/LocalFrame.h" | 46 #include "core/frame/LocalFrame.h" |
45 #include "core/frame/csp/ContentSecurityPolicy.h" | 47 #include "core/frame/csp/ContentSecurityPolicy.h" |
46 #include "core/html/DocumentNameCollection.h" | 48 #include "core/html/DocumentNameCollection.h" |
47 #include "core/html/HTMLIFrameElement.h" | 49 #include "core/html/HTMLIFrameElement.h" |
48 #include "core/inspector/MainThreadDebugger.h" | 50 #include "core/inspector/MainThreadDebugger.h" |
49 #include "core/loader/FrameLoader.h" | 51 #include "core/loader/FrameLoader.h" |
50 #include "core/loader/FrameLoaderClient.h" | 52 #include "core/loader/FrameLoaderClient.h" |
51 #include "core/origin_trials/OriginTrialContext.h" | 53 #include "core/origin_trials/OriginTrialContext.h" |
(...skipping 14 matching lines...) Expand all Loading... |
66 | 68 |
67 ScriptState::Scope scope(m_scriptState.get()); | 69 ScriptState::Scope scope(m_scriptState.get()); |
68 v8::Local<v8::Context> context = m_scriptState->context(); | 70 v8::Local<v8::Context> context = m_scriptState->context(); |
69 // The embedder could run arbitrary code in response to the | 71 // The embedder could run arbitrary code in response to the |
70 // willReleaseScriptContext callback, so all disposing should happen after | 72 // willReleaseScriptContext callback, so all disposing should happen after |
71 // it returns. | 73 // it returns. |
72 frame()->loader().client()->willReleaseScriptContext(context, | 74 frame()->loader().client()->willReleaseScriptContext(context, |
73 m_world->worldId()); | 75 m_world->worldId()); |
74 MainThreadDebugger::instance()->contextWillBeDestroyed(m_scriptState.get()); | 76 MainThreadDebugger::instance()->contextWillBeDestroyed(m_scriptState.get()); |
75 | 77 |
76 WindowProxy::disposeContext(behavior); | 78 if (behavior == DetachGlobal) { |
| 79 v8::Local<v8::Context> context = m_scriptState->context(); |
| 80 // Clean up state on the global proxy, which will be reused. |
| 81 if (!m_globalProxy.isEmpty()) { |
| 82 // TODO(yukishiino): This DCHECK failed on Canary (M57) and Dev (M56). |
| 83 // We need to figure out why m_globalProxy != context->Global(). |
| 84 DCHECK(m_globalProxy == context->Global()); |
| 85 DCHECK_EQ(toScriptWrappable(context->Global()), |
| 86 toScriptWrappable( |
| 87 context->Global()->GetPrototype().As<v8::Object>())); |
| 88 m_globalProxy.get().SetWrapperClassId(0); |
| 89 } |
| 90 V8DOMWrapper::clearNativeInfo(isolate(), context->Global()); |
| 91 m_scriptState->detachGlobalObject(); |
| 92 } |
| 93 |
| 94 m_scriptState->disposePerContextData(); |
| 95 |
| 96 // It's likely that disposing the context has created a lot of |
| 97 // garbage. Notify V8 about this so it'll have a chance of cleaning |
| 98 // it up when idle. |
| 99 V8GCForContextDispose::instance().notifyContextDisposed( |
| 100 frame()->isMainFrame()); |
| 101 |
| 102 DCHECK(m_lifecycle == Lifecycle::ContextInitialized); |
| 103 m_lifecycle = Lifecycle::ContextDetached; |
77 } | 104 } |
78 | 105 |
79 void LocalWindowProxy::initialize() { | 106 void LocalWindowProxy::initialize() { |
80 TRACE_EVENT1("v8", "LocalWindowProxy::initialize", "isMainWindow", | 107 TRACE_EVENT1("v8", "LocalWindowProxy::initialize", "isMainWindow", |
81 frame()->isMainFrame()); | 108 frame()->isMainFrame()); |
82 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( | 109 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( |
83 frame()->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy" | 110 frame()->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy" |
84 : "Blink.Binding.InitializeNonMainWindowProxy"); | 111 : "Blink.Binding.InitializeNonMainWindowProxy"); |
85 | 112 |
86 ScriptForbiddenScope::AllowUserAgentScript allowScript; | 113 ScriptForbiddenScope::AllowUserAgentScript allowScript; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // If conditional features for window have been queued before the V8 context | 149 // If conditional features for window have been queued before the V8 context |
123 // was ready, then inject them into the context now | 150 // was ready, then inject them into the context now |
124 if (m_world->isMainWorld()) { | 151 if (m_world->isMainWorld()) { |
125 installPendingConditionalFeaturesOnWindow(m_scriptState.get()); | 152 installPendingConditionalFeaturesOnWindow(m_scriptState.get()); |
126 } | 153 } |
127 | 154 |
128 if (m_world->isMainWorld()) | 155 if (m_world->isMainWorld()) |
129 frame()->loader().dispatchDidClearWindowObjectInMainWorld(); | 156 frame()->loader().dispatchDidClearWindowObjectInMainWorld(); |
130 } | 157 } |
131 | 158 |
| 159 void LocalWindowProxy::setupWindowPrototypeChain() { |
| 160 // Associate the window wrapper object and its prototype chain with the |
| 161 // corresponding native DOMWindow object. |
| 162 // The full structure of the global object's prototype chain is as follows: |
| 163 // |
| 164 // global proxy object [1] |
| 165 // -- has prototype --> global object (window wrapper object) [2] |
| 166 // -- has prototype --> Window.prototype |
| 167 // -- has prototype --> WindowProperties [3] |
| 168 // -- has prototype --> EventTarget.prototype |
| 169 // -- has prototype --> Object.prototype |
| 170 // -- has prototype --> null |
| 171 // |
| 172 // [1] Global proxy object is as known as "outer global object". It's an |
| 173 // empty object and remains after navigation. When navigated, points to |
| 174 // a different global object as the prototype object. |
| 175 // [2] Global object is as known as "inner global object" or "window wrapper |
| 176 // object". The prototype chain between global proxy object and global |
| 177 // object is NOT observable from user JavaScript code. All other |
| 178 // prototype chains are observable. Global proxy object and global object |
| 179 // together appear to be the same single JavaScript object. See also: |
| 180 // https://wiki.mozilla.org/Gecko:SplitWindow |
| 181 // global object (= window wrapper object) provides most of Window's DOM |
| 182 // attributes and operations. Also global variables defined by user |
| 183 // JavaScript are placed on this object. When navigated, a new global |
| 184 // object is created together with a new v8::Context, but the global proxy |
| 185 // object doesn't change. |
| 186 // [3] WindowProperties is a named properties object of Window interface. |
| 187 |
| 188 LocalDOMWindow* window = frame()->domWindow(); |
| 189 const WrapperTypeInfo* wrapperTypeInfo = window->wrapperTypeInfo(); |
| 190 v8::Local<v8::Context> context = m_scriptState->context(); |
| 191 |
| 192 // The global proxy object. Note this is not the global object. |
| 193 v8::Local<v8::Object> globalProxy = context->Global(); |
| 194 CHECK(m_globalProxy == globalProxy); |
| 195 V8DOMWrapper::setNativeInfo(isolate(), globalProxy, wrapperTypeInfo, window); |
| 196 // Mark the handle to be traced by Oilpan, since the global proxy has a |
| 197 // reference to the DOMWindow. |
| 198 m_globalProxy.get().SetWrapperClassId(wrapperTypeInfo->wrapperClassId); |
| 199 |
| 200 // The global object, aka window wrapper object. |
| 201 v8::Local<v8::Object> windowWrapper = |
| 202 globalProxy->GetPrototype().As<v8::Object>(); |
| 203 windowWrapper = V8DOMWrapper::associateObjectWithWrapper( |
| 204 isolate(), window, wrapperTypeInfo, windowWrapper); |
| 205 |
| 206 // The prototype object of Window interface. |
| 207 v8::Local<v8::Object> windowPrototype = |
| 208 windowWrapper->GetPrototype().As<v8::Object>(); |
| 209 CHECK(!windowPrototype.IsEmpty()); |
| 210 V8DOMWrapper::setNativeInfo(isolate(), windowPrototype, wrapperTypeInfo, |
| 211 window); |
| 212 |
| 213 // The named properties object of Window interface. |
| 214 v8::Local<v8::Object> windowProperties = |
| 215 windowPrototype->GetPrototype().As<v8::Object>(); |
| 216 CHECK(!windowProperties.IsEmpty()); |
| 217 V8DOMWrapper::setNativeInfo(isolate(), windowProperties, wrapperTypeInfo, |
| 218 window); |
| 219 |
| 220 // TODO(keishi): Remove installPagePopupController and implement |
| 221 // PagePopupController in another way. |
| 222 V8PagePopupControllerBinding::installPagePopupController(context, |
| 223 windowWrapper); |
| 224 } |
| 225 |
132 void LocalWindowProxy::createContext() { | 226 void LocalWindowProxy::createContext() { |
133 // Create a new v8::Context with the window object as the global object | 227 // Create a new v8::Context with the window object as the global object |
134 // (aka the inner global). Reuse the global proxy object (aka the outer | 228 // (aka the inner global). Reuse the global proxy object (aka the outer |
135 // global) if it already exists. See the comments in | 229 // global) if it already exists. See the comments in |
136 // setupWindowPrototypeChain for the structure of the prototype chain of | 230 // setupWindowPrototypeChain for the structure of the prototype chain of |
137 // the global object. | 231 // the global object. |
138 v8::Local<v8::ObjectTemplate> globalTemplate = | 232 v8::Local<v8::ObjectTemplate> globalTemplate = |
139 V8Window::domTemplate(isolate(), *m_world)->InstanceTemplate(); | 233 V8Window::domTemplate(isolate(), *m_world)->InstanceTemplate(); |
140 CHECK(!globalTemplate.IsEmpty()); | 234 CHECK(!globalTemplate.IsEmpty()); |
141 | 235 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 | 447 |
354 setSecurityToken(origin); | 448 setSecurityToken(origin); |
355 } | 449 } |
356 | 450 |
357 LocalWindowProxy::LocalWindowProxy(v8::Isolate* isolate, | 451 LocalWindowProxy::LocalWindowProxy(v8::Isolate* isolate, |
358 LocalFrame& frame, | 452 LocalFrame& frame, |
359 RefPtr<DOMWrapperWorld> world) | 453 RefPtr<DOMWrapperWorld> world) |
360 : WindowProxy(isolate, frame, std::move(world)) {} | 454 : WindowProxy(isolate, frame, std::move(world)) {} |
361 | 455 |
362 } // namespace blink | 456 } // namespace blink |
OLD | NEW |