| 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/RemoteWindowProxy.h" | 31 #include "bindings/core/v8/WindowProxy.h" |
| 32 | 32 |
| 33 #include <algorithm> |
| 33 #include <utility> | 34 #include <utility> |
| 34 | 35 |
| 36 #include "bindings/core/v8/ConditionalFeatures.h" |
| 35 #include "bindings/core/v8/DOMWrapperWorld.h" | 37 #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" |
| 36 #include "bindings/core/v8/V8GCForContextDispose.h" | 43 #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" |
| 37 #include "bindings/core/v8/V8Window.h" | 51 #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" |
| 38 #include "platform/Histogram.h" | 63 #include "platform/Histogram.h" |
| 39 #include "platform/RuntimeEnabledFeatures.h" | 64 #include "platform/RuntimeEnabledFeatures.h" |
| 40 #include "platform/ScriptForbiddenScope.h" | 65 #include "platform/ScriptForbiddenScope.h" |
| 41 #include "platform/heap/Handle.h" | 66 #include "platform/heap/Handle.h" |
| 42 #include "platform/instrumentation/tracing/TraceEvent.h" | 67 #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" |
| 43 #include "v8/include/v8.h" | 71 #include "v8/include/v8.h" |
| 44 #include "wtf/Assertions.h" | 72 #include "wtf/Assertions.h" |
| 73 #include "wtf/StringExtras.h" |
| 74 #include "wtf/text/CString.h" |
| 45 | 75 |
| 46 namespace blink { | 76 namespace blink { |
| 47 | 77 |
| 48 RemoteWindowProxy::RemoteWindowProxy(v8::Isolate* isolate, | 78 RemoteWindowProxy::RemoteWindowProxy(v8::Isolate* isolate, |
| 49 RemoteFrame& frame, | 79 RemoteFrame& frame, |
| 50 RefPtr<DOMWrapperWorld> world) | 80 RefPtr<DOMWrapperWorld> world) |
| 51 : WindowProxy(isolate, frame, std::move(world)) {} | 81 : WindowProxy(isolate, frame, std::move(world)) {} |
| 52 | 82 |
| 53 void RemoteWindowProxy::disposeContext(GlobalDetachmentBehavior behavior) { | 83 void RemoteWindowProxy::disposeContext(GlobalDetachmentBehavior behavior) { |
| 54 if (m_lifecycle != Lifecycle::ContextInitialized) | 84 if (m_lifecycle != Lifecycle::ContextInitialized) |
| 55 return; | 85 return; |
| 56 | 86 |
| 57 if (behavior == DetachGlobal) { | 87 WindowProxy::disposeContext(behavior); |
| 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; | |
| 87 } | 88 } |
| 88 | 89 |
| 89 void RemoteWindowProxy::initialize() { | 90 void RemoteWindowProxy::initialize() { |
| 90 TRACE_EVENT1("v8", "RemoteWindowProxy::initialize", "isMainWindow", | 91 TRACE_EVENT1("v8", "RemoteWindowProxy::initialize", "isMainWindow", |
| 91 frame()->isMainFrame()); | 92 frame()->isMainFrame()); |
| 92 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( | 93 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( |
| 93 frame()->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy" | 94 frame()->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy" |
| 94 : "Blink.Binding.InitializeNonMainWindowProxy"); | 95 : "Blink.Binding.InitializeNonMainWindowProxy"); |
| 95 | 96 |
| 96 ScriptForbiddenScope::AllowUserAgentScript allowScript; | 97 ScriptForbiddenScope::AllowUserAgentScript allowScript; |
| 97 | 98 |
| 98 v8::HandleScope handleScope(isolate()); | 99 v8::HandleScope handleScope(isolate()); |
| 99 | 100 |
| 100 createContext(); | 101 createContext(); |
| 101 | 102 |
| 102 ScriptState::Scope scope(m_scriptState.get()); | 103 ScriptState::Scope scope(m_scriptState.get()); |
| 103 v8::Local<v8::Context> context = m_scriptState->context(); | 104 v8::Local<v8::Context> context = m_scriptState->context(); |
| 104 if (m_globalProxy.isEmpty()) { | 105 if (m_globalProxy.isEmpty()) { |
| 105 m_globalProxy.set(isolate(), context->Global()); | 106 m_globalProxy.set(isolate(), context->Global()); |
| 106 CHECK(!m_globalProxy.isEmpty()); | 107 CHECK(!m_globalProxy.isEmpty()); |
| 107 } | 108 } |
| 108 | 109 |
| 109 setupWindowPrototypeChain(); | 110 setupWindowPrototypeChain(); |
| 110 | 111 |
| 111 // Remote frames always require a full canAccess() check. | 112 // Remote frames always require a full canAccess() check. |
| 112 context->UseDefaultSecurityToken(); | 113 context->UseDefaultSecurityToken(); |
| 113 } | 114 } |
| 114 | 115 |
| 115 void RemoteWindowProxy::setupWindowPrototypeChain() { | |
| 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 | |
| 155 void RemoteWindowProxy::createContext() { | 116 void RemoteWindowProxy::createContext() { |
| 156 // Create a new v8::Context with the window object as the global object | 117 // Create a new v8::Context with the window object as the global object |
| 157 // (aka the inner global). Reuse the outer global proxy if it already exists. | 118 // (aka the inner global). Reuse the global proxy object (aka the outer |
| 119 // global) if it already exists. See the comments in |
| 120 // setupWindowPrototypeChain for the structure of the prototype chain of |
| 121 // the global object. |
| 158 v8::Local<v8::ObjectTemplate> globalTemplate = | 122 v8::Local<v8::ObjectTemplate> globalTemplate = |
| 159 V8Window::domTemplate(isolate(), *m_world)->InstanceTemplate(); | 123 V8Window::domTemplate(isolate(), *m_world)->InstanceTemplate(); |
| 160 CHECK(!globalTemplate.IsEmpty()); | 124 CHECK(!globalTemplate.IsEmpty()); |
| 161 | 125 |
| 162 v8::Local<v8::Context> context; | 126 v8::Local<v8::Context> context; |
| 163 { | 127 { |
| 164 V8PerIsolateData::UseCounterDisabledScope useCounterDisabled( | 128 V8PerIsolateData::UseCounterDisabledScope useCounterDisabled( |
| 165 V8PerIsolateData::from(isolate())); | 129 V8PerIsolateData::from(isolate())); |
| 166 context = v8::Context::New(isolate(), nullptr, globalTemplate, | 130 context = v8::Context::New(isolate(), nullptr, globalTemplate, |
| 167 m_globalProxy.newLocal(isolate())); | 131 m_globalProxy.newLocal(isolate())); |
| 168 } | 132 } |
| 169 CHECK(!context.IsEmpty()); | 133 CHECK(!context.IsEmpty()); |
| 170 | 134 |
| 171 m_scriptState = ScriptState::create(context, m_world); | 135 m_scriptState = ScriptState::create(context, m_world); |
| 172 | 136 |
| 173 // TODO(haraken): Currently we cannot enable the following DCHECK because | 137 // TODO(haraken): Currently we cannot enable the following DCHECK because |
| 174 // an already detached window proxy can be re-initialized. This is wrong. | 138 // an already detached window proxy can be re-initialized. This is wrong. |
| 175 // DCHECK(m_lifecycle == Lifecycle::ContextUninitialized); | 139 // DCHECK(m_lifecycle == Lifecycle::ContextUninitialized); |
| 176 m_lifecycle = Lifecycle::ContextInitialized; | 140 m_lifecycle = Lifecycle::ContextInitialized; |
| 177 DCHECK(m_scriptState->contextIsValid()); | 141 DCHECK(m_scriptState->contextIsValid()); |
| 178 } | 142 } |
| 179 | 143 |
| 180 } // namespace blink | 144 } // namespace blink |
| OLD | NEW |