Chromium Code Reviews| Index: third_party/WebKit/Source/bindings/core/v8/RemoteWindowProxy.cpp |
| diff --git a/third_party/WebKit/Source/bindings/core/v8/RemoteWindowProxy.cpp b/third_party/WebKit/Source/bindings/core/v8/RemoteWindowProxy.cpp |
| index 2bbdba30a46b62d2e403ef57e45e83b5f0e06349..a34f068706b5d9383fc845bdd16277f5a5233dac 100644 |
| --- a/third_party/WebKit/Source/bindings/core/v8/RemoteWindowProxy.cpp |
| +++ b/third_party/WebKit/Source/bindings/core/v8/RemoteWindowProxy.cpp |
| @@ -28,49 +28,15 @@ |
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| -#include "bindings/core/v8/WindowProxy.h" |
| +#include "bindings/core/v8/RemoteWindowProxy.h" |
| -#include "bindings/core/v8/ConditionalFeatures.h" |
| #include "bindings/core/v8/DOMWrapperWorld.h" |
| -#include "bindings/core/v8/ScriptController.h" |
| -#include "bindings/core/v8/ToV8.h" |
| -#include "bindings/core/v8/V8Binding.h" |
| -#include "bindings/core/v8/V8DOMActivityLogger.h" |
| -#include "bindings/core/v8/V8Document.h" |
| -#include "bindings/core/v8/V8GCForContextDispose.h" |
| -#include "bindings/core/v8/V8HTMLCollection.h" |
| -#include "bindings/core/v8/V8HTMLDocument.h" |
| -#include "bindings/core/v8/V8HiddenValue.h" |
| -#include "bindings/core/v8/V8Initializer.h" |
| -#include "bindings/core/v8/V8ObjectConstructor.h" |
| -#include "bindings/core/v8/V8PagePopupControllerBinding.h" |
| -#include "bindings/core/v8/V8PrivateProperty.h" |
| +#include "bindings/core/v8/V8DOMWrapper.h" |
| #include "bindings/core/v8/V8Window.h" |
| -#include "core/frame/LocalFrame.h" |
| -#include "core/frame/csp/ContentSecurityPolicy.h" |
| -#include "core/html/DocumentNameCollection.h" |
| -#include "core/html/HTMLCollection.h" |
| -#include "core/html/HTMLIFrameElement.h" |
| -#include "core/inspector/InspectorInstrumentation.h" |
| -#include "core/inspector/MainThreadDebugger.h" |
| -#include "core/loader/DocumentLoader.h" |
| -#include "core/loader/FrameLoader.h" |
| -#include "core/loader/FrameLoaderClient.h" |
| -#include "core/origin_trials/OriginTrialContext.h" |
| #include "platform/Histogram.h" |
| -#include "platform/RuntimeEnabledFeatures.h" |
| -#include "platform/ScriptForbiddenScope.h" |
| -#include "platform/heap/Handle.h" |
| #include "platform/instrumentation/tracing/TraceEvent.h" |
| -#include "platform/weborigin/SecurityOrigin.h" |
| -#include "public/platform/Platform.h" |
| +#include "v8/include/v8.h" |
| #include "wtf/Assertions.h" |
| -#include "wtf/StringExtras.h" |
| -#include "wtf/text/CString.h" |
| -#include <algorithm> |
| -#include <utility> |
| -#include <v8-debug.h> |
| -#include <v8.h> |
| namespace blink { |
| @@ -83,7 +49,16 @@ void RemoteWindowProxy::disposeContext(GlobalDetachmentBehavior behavior) { |
| if (m_lifecycle != Lifecycle::ContextInitialized) |
| return; |
| - WindowProxy::disposeContext(behavior); |
| + if (behavior == DetachGlobal && !m_globalProxy.isEmpty()) { |
| + m_globalProxy.get().SetWrapperClassId(0); |
| + V8DOMWrapper::clearNativeInfo(isolate(), m_globalProxy.newLocal(isolate())); |
| +#if DCHECK_IS_ON() |
| + didDetachGlobalProxy(); |
| +#endif |
| + } |
| + |
| + DCHECK_EQ(Lifecycle::ContextInitialized, m_lifecycle); |
| + m_lifecycle = Lifecycle::ContextDetached; |
| } |
| void RemoteWindowProxy::initialize() { |
| @@ -93,23 +68,11 @@ void RemoteWindowProxy::initialize() { |
| frame()->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy" |
| : "Blink.Binding.InitializeNonMainWindowProxy"); |
| - ScriptForbiddenScope::AllowUserAgentScript allowScript; |
| - |
| v8::HandleScope handleScope(isolate()); |
| createContext(); |
| - ScriptState::Scope scope(m_scriptState.get()); |
| - v8::Local<v8::Context> context = m_scriptState->context(); |
| - if (m_globalProxy.isEmpty()) { |
| - m_globalProxy.set(isolate(), context->Global()); |
| - CHECK(!m_globalProxy.isEmpty()); |
| - } |
| - |
| setupWindowPrototypeChain(); |
| - |
| - // Remote frames always require a full canAccess() check. |
| - context->UseDefaultSecurityToken(); |
| } |
| void RemoteWindowProxy::createContext() { |
| @@ -122,22 +85,45 @@ void RemoteWindowProxy::createContext() { |
| V8Window::domTemplate(isolate(), *m_world)->InstanceTemplate(); |
| CHECK(!globalTemplate.IsEmpty()); |
| - v8::Local<v8::Context> context; |
| - { |
| - V8PerIsolateData::UseCounterDisabledScope useCounterDisabled( |
| - V8PerIsolateData::from(isolate())); |
| - context = v8::Context::New(isolate(), nullptr, globalTemplate, |
| - m_globalProxy.newLocal(isolate())); |
| - } |
| - CHECK(!context.IsEmpty()); |
| - |
| - m_scriptState = ScriptState::create(context, m_world); |
| + v8::Local<v8::Object> globalProxy = |
| + v8::Context::NewRemoteContext(isolate(), globalTemplate, |
| + m_globalProxy.newLocal(isolate())) |
| + .ToLocalChecked(); |
| + if (m_globalProxy.isEmpty()) |
|
haraken
2017/02/16 01:11:19
As discussed before, shall we remove this branch a
dcheng
2017/02/16 03:14:07
I'm going to add a comment to WindowProxy describi
|
| + m_globalProxy.set(isolate(), globalProxy); |
| + CHECK(!m_globalProxy.isEmpty()); |
| // TODO(haraken): Currently we cannot enable the following DCHECK because |
| // an already detached window proxy can be re-initialized. This is wrong. |
| // DCHECK(m_lifecycle == Lifecycle::ContextUninitialized); |
| m_lifecycle = Lifecycle::ContextInitialized; |
| - DCHECK(m_scriptState->contextIsValid()); |
| +} |
| + |
| +void RemoteWindowProxy::setupWindowPrototypeChain() { |
| + // Unlike a LocalWindowProxy, there's no actual chain here: the only object is |
| + // the outer global proxy. A LocalWindowProxy needs both an outer global proxy |
| + // and an inner global object to implement the split object model: |
| + // https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Split_object#The_window_object |
| + // |
| + // However, because: |
| + // 1. Scripts are never executed in a remote context |
| + // 2. Thus there's no need for an inner global object to detach previous |
| + // global state when navigating. |
| + // a RemoteWindowProxy simply needs the outer global proxy to forward accesses |
| + // to cross-origin properties. |
| + |
| + DOMWindow* window = frame()->domWindow(); |
| + const WrapperTypeInfo* wrapperTypeInfo = window->wrapperTypeInfo(); |
| + // The global proxy object. Note this is not the global object. |
| + V8DOMWrapper::setNativeInfo(isolate(), m_globalProxy.newLocal(isolate()), |
| + wrapperTypeInfo, window); |
| + // Mark the handle to be traced by Oilpan, since the global proxy has a |
| + // reference to the DOMWindow. |
| + m_globalProxy.get().SetWrapperClassId(wrapperTypeInfo->wrapperClassId); |
| + |
| +#if DCHECK_IS_ON() |
| + didAttachGlobalProxy(); |
| +#endif |
| } |
| } // namespace blink |