| 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 19 matching lines...) Expand all Loading... |
| 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" |
| 40 #include "bindings/core/v8/V8HTMLDocument.h" | 41 #include "bindings/core/v8/V8HTMLDocument.h" |
| 41 #include "bindings/core/v8/V8HiddenValue.h" | 42 #include "bindings/core/v8/V8HiddenValue.h" |
| 42 #include "bindings/core/v8/V8Initializer.h" | 43 #include "bindings/core/v8/V8Initializer.h" |
| 44 #include "bindings/core/v8/V8PagePopupControllerBinding.h" |
| 43 #include "bindings/core/v8/V8PrivateProperty.h" | 45 #include "bindings/core/v8/V8PrivateProperty.h" |
| 44 #include "bindings/core/v8/V8Window.h" | 46 #include "bindings/core/v8/V8Window.h" |
| 45 #include "core/dom/Modulator.h" | 47 #include "core/dom/Modulator.h" |
| 46 #include "core/frame/LocalFrame.h" | 48 #include "core/frame/LocalFrame.h" |
| 47 #include "core/frame/LocalFrameClient.h" | 49 #include "core/frame/LocalFrameClient.h" |
| 48 #include "core/frame/csp/ContentSecurityPolicy.h" | 50 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 49 #include "core/html/DocumentNameCollection.h" | 51 #include "core/html/DocumentNameCollection.h" |
| 50 #include "core/html/HTMLIFrameElement.h" | 52 #include "core/html/HTMLIFrameElement.h" |
| 51 #include "core/inspector/MainThreadDebugger.h" | 53 #include "core/inspector/MainThreadDebugger.h" |
| 52 #include "core/loader/FrameLoader.h" | 54 #include "core/loader/FrameLoader.h" |
| 53 #include "core/origin_trials/OriginTrialContext.h" | 55 #include "core/origin_trials/OriginTrialContext.h" |
| 54 #include "platform/Histogram.h" | 56 #include "platform/Histogram.h" |
| 55 #include "platform/RuntimeEnabledFeatures.h" | 57 #include "platform/RuntimeEnabledFeatures.h" |
| 56 #include "platform/ScriptForbiddenScope.h" | 58 #include "platform/ScriptForbiddenScope.h" |
| 57 #include "platform/heap/Handle.h" | 59 #include "platform/heap/Handle.h" |
| 58 #include "platform/instrumentation/tracing/TraceEvent.h" | 60 #include "platform/instrumentation/tracing/TraceEvent.h" |
| 59 #include "platform/weborigin/SecurityOrigin.h" | 61 #include "platform/weborigin/SecurityOrigin.h" |
| 62 #include "v8/include/v8.h" |
| 60 #include "wtf/Assertions.h" | 63 #include "wtf/Assertions.h" |
| 61 | 64 |
| 62 namespace blink { | 65 namespace blink { |
| 63 | 66 |
| 64 void LocalWindowProxy::disposeContext(GlobalDetachmentBehavior behavior) { | 67 void LocalWindowProxy::disposeContext(GlobalDetachmentBehavior behavior) { |
| 65 if (m_lifecycle != Lifecycle::ContextInitialized) | 68 if (m_lifecycle != Lifecycle::ContextInitialized) |
| 66 return; | 69 return; |
| 67 | 70 |
| 68 ScriptState::Scope scope(m_scriptState.get()); | 71 ScriptState::Scope scope(m_scriptState.get()); |
| 69 v8::Local<v8::Context> context = m_scriptState->context(); | 72 v8::Local<v8::Context> context = m_scriptState->context(); |
| 70 // The embedder could run arbitrary code in response to the | 73 // The embedder could run arbitrary code in response to the |
| 71 // willReleaseScriptContext callback, so all disposing should happen after | 74 // willReleaseScriptContext callback, so all disposing should happen after |
| 72 // it returns. | 75 // it returns. |
| 73 frame()->loader().client()->willReleaseScriptContext(context, | 76 frame()->loader().client()->willReleaseScriptContext(context, |
| 74 m_world->worldId()); | 77 m_world->worldId()); |
| 75 MainThreadDebugger::instance()->contextWillBeDestroyed(m_scriptState.get()); | 78 MainThreadDebugger::instance()->contextWillBeDestroyed(m_scriptState.get()); |
| 76 | 79 |
| 77 WindowProxy::disposeContext(behavior); | 80 if (behavior == DetachGlobal) { |
| 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; |
| 78 } | 110 } |
| 79 | 111 |
| 80 void LocalWindowProxy::initialize() { | 112 void LocalWindowProxy::initialize() { |
| 81 TRACE_EVENT1("v8", "LocalWindowProxy::initialize", "isMainWindow", | 113 TRACE_EVENT1("v8", "LocalWindowProxy::initialize", "isMainWindow", |
| 82 frame()->isMainFrame()); | 114 frame()->isMainFrame()); |
| 83 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( | 115 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( |
| 84 frame()->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy" | 116 frame()->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy" |
| 85 : "Blink.Binding.InitializeNonMainWindowProxy"); | 117 : "Blink.Binding.InitializeNonMainWindowProxy"); |
| 86 | 118 |
| 87 ScriptForbiddenScope::AllowUserAgentScript allowScript; | 119 ScriptForbiddenScope::AllowUserAgentScript allowScript; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // If conditional features for window have been queued before the V8 context | 155 // If conditional features for window have been queued before the V8 context |
| 124 // was ready, then inject them into the context now | 156 // was ready, then inject them into the context now |
| 125 if (m_world->isMainWorld()) { | 157 if (m_world->isMainWorld()) { |
| 126 installConditionalFeaturesOnWindow(m_scriptState.get()); | 158 installConditionalFeaturesOnWindow(m_scriptState.get()); |
| 127 } | 159 } |
| 128 | 160 |
| 129 if (m_world->isMainWorld()) | 161 if (m_world->isMainWorld()) |
| 130 frame()->loader().dispatchDidClearWindowObjectInMainWorld(); | 162 frame()->loader().dispatchDidClearWindowObjectInMainWorld(); |
| 131 } | 163 } |
| 132 | 164 |
| 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 |
| 133 void LocalWindowProxy::createContext() { | 210 void LocalWindowProxy::createContext() { |
| 134 // Create a new v8::Context with the window object as the global object | 211 // 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 | 212 // (aka the inner global). Reuse the outer global proxy if it already exists. |
| 136 // global) if it already exists. See the comments in | |
| 137 // setupWindowPrototypeChain for the structure of the prototype chain of | |
| 138 // the global object. | |
| 139 v8::Local<v8::ObjectTemplate> globalTemplate = | 213 v8::Local<v8::ObjectTemplate> globalTemplate = |
| 140 V8Window::domTemplate(isolate(), *m_world)->InstanceTemplate(); | 214 V8Window::domTemplate(isolate(), *m_world)->InstanceTemplate(); |
| 141 CHECK(!globalTemplate.IsEmpty()); | 215 CHECK(!globalTemplate.IsEmpty()); |
| 142 | 216 |
| 143 Vector<const char*> extensionNames; | 217 Vector<const char*> extensionNames; |
| 144 // Dynamically tell v8 about our extensions now. | 218 // Dynamically tell v8 about our extensions now. |
| 145 if (frame()->loader().client()->allowScriptExtensions()) { | 219 if (frame()->loader().client()->allowScriptExtensions()) { |
| 146 const V8Extensions& extensions = ScriptController::registeredExtensions(); | 220 const V8Extensions& extensions = ScriptController::registeredExtensions(); |
| 147 extensionNames.reserveInitialCapacity(extensions.size()); | 221 extensionNames.reserveInitialCapacity(extensions.size()); |
| 148 for (const auto* extension : extensions) | 222 for (const auto* extension : extensions) |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 | 428 |
| 355 setSecurityToken(origin); | 429 setSecurityToken(origin); |
| 356 } | 430 } |
| 357 | 431 |
| 358 LocalWindowProxy::LocalWindowProxy(v8::Isolate* isolate, | 432 LocalWindowProxy::LocalWindowProxy(v8::Isolate* isolate, |
| 359 LocalFrame& frame, | 433 LocalFrame& frame, |
| 360 RefPtr<DOMWrapperWorld> world) | 434 RefPtr<DOMWrapperWorld> world) |
| 361 : WindowProxy(isolate, frame, std::move(world)) {} | 435 : WindowProxy(isolate, frame, std::move(world)) {} |
| 362 | 436 |
| 363 } // namespace blink | 437 } // namespace blink |
| OLD | NEW |