Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 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 <algorithm> | |
| 34 #include <utility> | 33 #include <utility> |
| 35 | 34 |
| 36 #include "bindings/core/v8/ConditionalFeatures.h" | |
| 37 #include "bindings/core/v8/DOMWrapperWorld.h" | 35 #include "bindings/core/v8/DOMWrapperWorld.h" |
| 38 #include "bindings/core/v8/ScriptController.h" | |
| 39 #include "bindings/core/v8/ToV8.h" | |
| 40 #include "bindings/core/v8/V8Binding.h" | |
| 41 #include "bindings/core/v8/V8DOMActivityLogger.h" | |
| 42 #include "bindings/core/v8/V8Document.h" | |
| 43 #include "bindings/core/v8/V8GCForContextDispose.h" | 36 #include "bindings/core/v8/V8GCForContextDispose.h" |
| 44 #include "bindings/core/v8/V8HTMLCollection.h" | |
| 45 #include "bindings/core/v8/V8HTMLDocument.h" | |
| 46 #include "bindings/core/v8/V8HiddenValue.h" | |
| 47 #include "bindings/core/v8/V8Initializer.h" | |
| 48 #include "bindings/core/v8/V8ObjectConstructor.h" | |
| 49 #include "bindings/core/v8/V8PagePopupControllerBinding.h" | |
| 50 #include "bindings/core/v8/V8PrivateProperty.h" | |
| 51 #include "bindings/core/v8/V8Window.h" | 37 #include "bindings/core/v8/V8Window.h" |
| 52 #include "core/frame/LocalFrame.h" | |
| 53 #include "core/frame/LocalFrameClient.h" | |
| 54 #include "core/frame/csp/ContentSecurityPolicy.h" | |
| 55 #include "core/html/DocumentNameCollection.h" | |
| 56 #include "core/html/HTMLCollection.h" | |
| 57 #include "core/html/HTMLIFrameElement.h" | |
| 58 #include "core/inspector/InspectorInstrumentation.h" | |
| 59 #include "core/inspector/MainThreadDebugger.h" | |
| 60 #include "core/loader/DocumentLoader.h" | |
| 61 #include "core/loader/FrameLoader.h" | |
| 62 #include "core/origin_trials/OriginTrialContext.h" | |
| 63 #include "platform/Histogram.h" | 38 #include "platform/Histogram.h" |
| 64 #include "platform/RuntimeEnabledFeatures.h" | 39 #include "platform/RuntimeEnabledFeatures.h" |
| 65 #include "platform/ScriptForbiddenScope.h" | 40 #include "platform/ScriptForbiddenScope.h" |
| 66 #include "platform/heap/Handle.h" | 41 #include "platform/heap/Handle.h" |
| 67 #include "platform/instrumentation/tracing/TraceEvent.h" | 42 #include "platform/instrumentation/tracing/TraceEvent.h" |
| 68 #include "platform/weborigin/SecurityOrigin.h" | |
| 69 #include "public/platform/Platform.h" | |
| 70 #include "v8/include/v8-debug.h" | |
| 71 #include "v8/include/v8.h" | 43 #include "v8/include/v8.h" |
| 72 #include "wtf/Assertions.h" | 44 #include "wtf/Assertions.h" |
| 73 #include "wtf/StringExtras.h" | |
| 74 #include "wtf/text/CString.h" | |
| 75 | 45 |
| 76 namespace blink { | 46 namespace blink { |
| 77 | 47 |
| 78 RemoteWindowProxy::RemoteWindowProxy(v8::Isolate* isolate, | 48 RemoteWindowProxy::RemoteWindowProxy(v8::Isolate* isolate, |
| 79 RemoteFrame& frame, | 49 RemoteFrame& frame, |
| 80 RefPtr<DOMWrapperWorld> world) | 50 RefPtr<DOMWrapperWorld> world) |
| 81 : WindowProxy(isolate, frame, std::move(world)) {} | 51 : WindowProxy(isolate, frame, std::move(world)) {} |
| 82 | 52 |
| 83 void RemoteWindowProxy::disposeContext(GlobalDetachmentBehavior behavior) { | 53 void RemoteWindowProxy::disposeContext(GlobalDetachmentBehavior behavior) { |
| 84 if (m_lifecycle != Lifecycle::ContextInitialized) | 54 if (m_lifecycle != Lifecycle::ContextInitialized) |
| 85 return; | 55 return; |
| 86 | 56 |
| 87 WindowProxy::disposeContext(behavior); | 57 if (behavior == DetachGlobal) { |
| 58 v8::Local<v8::Context> context = m_scriptState->context(); | |
| 59 // Clean up state on the global proxy, which will be reused. | |
| 60 if (!m_globalProxy.isEmpty()) { | |
| 61 // TODO(yukishiino): This DCHECK failed on Canary (M57) and Dev (M56). | |
| 62 // We need to figure out why m_globalProxy != context->Global(). | |
| 63 DCHECK(m_globalProxy == context->Global()); | |
| 64 DCHECK_EQ(toScriptWrappable(context->Global()), | |
| 65 toScriptWrappable( | |
| 66 context->Global()->GetPrototype().As<v8::Object>())); | |
| 67 m_globalProxy.get().SetWrapperClassId(0); | |
| 68 } | |
| 69 V8DOMWrapper::clearNativeInfo(isolate(), context->Global()); | |
| 70 m_scriptState->detachGlobalObject(); | |
| 71 | |
| 72 #if DCHECK_IS_ON() | |
| 73 didDetachGlobalProxy(); | |
| 74 #endif | |
| 75 } | |
| 76 | |
| 77 m_scriptState->disposePerContextData(); | |
| 78 | |
| 79 // It's likely that disposing the context has created a lot of | |
| 80 // garbage. Notify V8 about this so it'll have a chance of cleaning | |
| 81 // it up when idle. | |
| 82 V8GCForContextDispose::instance().notifyContextDisposed( | |
| 83 frame()->isMainFrame()); | |
| 84 | |
| 85 DCHECK(m_lifecycle == Lifecycle::ContextInitialized); | |
| 86 m_lifecycle = Lifecycle::ContextDetached; | |
| 88 } | 87 } |
| 89 | 88 |
| 90 void RemoteWindowProxy::initialize() { | 89 void RemoteWindowProxy::initialize() { |
| 91 TRACE_EVENT1("v8", "RemoteWindowProxy::initialize", "isMainWindow", | 90 TRACE_EVENT1("v8", "RemoteWindowProxy::initialize", "isMainWindow", |
| 92 frame()->isMainFrame()); | 91 frame()->isMainFrame()); |
| 93 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( | 92 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( |
| 94 frame()->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy" | 93 frame()->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy" |
| 95 : "Blink.Binding.InitializeNonMainWindowProxy"); | 94 : "Blink.Binding.InitializeNonMainWindowProxy"); |
| 96 | 95 |
| 97 ScriptForbiddenScope::AllowUserAgentScript allowScript; | 96 ScriptForbiddenScope::AllowUserAgentScript allowScript; |
| 98 | 97 |
| 99 v8::HandleScope handleScope(isolate()); | 98 v8::HandleScope handleScope(isolate()); |
| 100 | 99 |
| 101 createContext(); | 100 createContext(); |
| 102 | 101 |
| 103 ScriptState::Scope scope(m_scriptState.get()); | 102 ScriptState::Scope scope(m_scriptState.get()); |
| 104 v8::Local<v8::Context> context = m_scriptState->context(); | 103 v8::Local<v8::Context> context = m_scriptState->context(); |
| 105 if (m_globalProxy.isEmpty()) { | 104 if (m_globalProxy.isEmpty()) { |
| 106 m_globalProxy.set(isolate(), context->Global()); | 105 m_globalProxy.set(isolate(), context->Global()); |
| 107 CHECK(!m_globalProxy.isEmpty()); | 106 CHECK(!m_globalProxy.isEmpty()); |
| 108 } | 107 } |
| 109 | 108 |
| 110 setupWindowPrototypeChain(); | 109 setupWindowPrototypeChain(); |
| 111 | 110 |
| 112 // Remote frames always require a full canAccess() check. | 111 // Remote frames always require a full canAccess() check. |
| 113 context->UseDefaultSecurityToken(); | 112 context->UseDefaultSecurityToken(); |
| 114 } | 113 } |
| 115 | 114 |
| 115 void RemoteWindowProxy::setupWindowPrototypeChain() { | |
|
haraken
2017/02/28 09:19:09
Add a comment and mention why this is duplicated b
dcheng
2017/02/28 09:22:39
I added the TODO to the header file.
| |
| 116 // Associate the window wrapper object and its prototype chain with the | |
| 117 // corresponding native DOMWindow object. | |
| 118 DOMWindow* window = frame()->domWindow(); | |
| 119 const WrapperTypeInfo* wrapperTypeInfo = window->wrapperTypeInfo(); | |
| 120 v8::Local<v8::Context> context = m_scriptState->context(); | |
| 121 | |
| 122 // The global proxy object. Note this is not the global object. | |
| 123 v8::Local<v8::Object> globalProxy = context->Global(); | |
| 124 CHECK(m_globalProxy == globalProxy); | |
| 125 V8DOMWrapper::setNativeInfo(isolate(), globalProxy, wrapperTypeInfo, window); | |
| 126 // Mark the handle to be traced by Oilpan, since the global proxy has a | |
| 127 // reference to the DOMWindow. | |
| 128 m_globalProxy.get().SetWrapperClassId(wrapperTypeInfo->wrapperClassId); | |
| 129 | |
| 130 #if DCHECK_IS_ON() | |
| 131 didAttachGlobalProxy(); | |
| 132 #endif | |
| 133 | |
| 134 // The global object, aka window wrapper object. | |
| 135 v8::Local<v8::Object> windowWrapper = | |
| 136 globalProxy->GetPrototype().As<v8::Object>(); | |
| 137 V8DOMWrapper::setNativeInfo(isolate(), windowWrapper, wrapperTypeInfo, | |
| 138 window); | |
| 139 | |
| 140 // The prototype object of Window interface. | |
| 141 v8::Local<v8::Object> windowPrototype = | |
| 142 windowWrapper->GetPrototype().As<v8::Object>(); | |
| 143 CHECK(!windowPrototype.IsEmpty()); | |
| 144 V8DOMWrapper::setNativeInfo(isolate(), windowPrototype, wrapperTypeInfo, | |
| 145 window); | |
| 146 | |
| 147 // The named properties object of Window interface. | |
| 148 v8::Local<v8::Object> windowProperties = | |
| 149 windowPrototype->GetPrototype().As<v8::Object>(); | |
| 150 CHECK(!windowProperties.IsEmpty()); | |
| 151 V8DOMWrapper::setNativeInfo(isolate(), windowProperties, wrapperTypeInfo, | |
| 152 window); | |
| 153 } | |
| 154 | |
| 116 void RemoteWindowProxy::createContext() { | 155 void RemoteWindowProxy::createContext() { |
| 117 // Create a new v8::Context with the window object as the global object | 156 // Create a new v8::Context with the window object as the global object |
| 118 // (aka the inner global). Reuse the global proxy object (aka the outer | 157 // (aka the inner global). Reuse the outer global proxy if it already exists. |
| 119 // global) if it already exists. See the comments in | |
| 120 // setupWindowPrototypeChain for the structure of the prototype chain of | |
| 121 // the global object. | |
| 122 v8::Local<v8::ObjectTemplate> globalTemplate = | 158 v8::Local<v8::ObjectTemplate> globalTemplate = |
| 123 V8Window::domTemplate(isolate(), *m_world)->InstanceTemplate(); | 159 V8Window::domTemplate(isolate(), *m_world)->InstanceTemplate(); |
| 124 CHECK(!globalTemplate.IsEmpty()); | 160 CHECK(!globalTemplate.IsEmpty()); |
| 125 | 161 |
| 126 v8::Local<v8::Context> context; | 162 v8::Local<v8::Context> context; |
| 127 { | 163 { |
| 128 V8PerIsolateData::UseCounterDisabledScope useCounterDisabled( | 164 V8PerIsolateData::UseCounterDisabledScope useCounterDisabled( |
| 129 V8PerIsolateData::from(isolate())); | 165 V8PerIsolateData::from(isolate())); |
| 130 context = v8::Context::New(isolate(), nullptr, globalTemplate, | 166 context = v8::Context::New(isolate(), nullptr, globalTemplate, |
| 131 m_globalProxy.newLocal(isolate())); | 167 m_globalProxy.newLocal(isolate())); |
| 132 } | 168 } |
| 133 CHECK(!context.IsEmpty()); | 169 CHECK(!context.IsEmpty()); |
| 134 | 170 |
| 135 m_scriptState = ScriptState::create(context, m_world); | 171 m_scriptState = ScriptState::create(context, m_world); |
| 136 | 172 |
| 137 // TODO(haraken): Currently we cannot enable the following DCHECK because | 173 // TODO(haraken): Currently we cannot enable the following DCHECK because |
| 138 // an already detached window proxy can be re-initialized. This is wrong. | 174 // an already detached window proxy can be re-initialized. This is wrong. |
| 139 // DCHECK(m_lifecycle == Lifecycle::ContextUninitialized); | 175 // DCHECK(m_lifecycle == Lifecycle::ContextUninitialized); |
| 140 m_lifecycle = Lifecycle::ContextInitialized; | 176 m_lifecycle = Lifecycle::ContextInitialized; |
| 141 DCHECK(m_scriptState->contextIsValid()); | 177 DCHECK(m_scriptState->contextIsValid()); |
| 142 } | 178 } |
| 143 | 179 |
| 144 } // namespace blink | 180 } // namespace blink |
| OLD | NEW |