Chromium Code Reviews| Index: third_party/WebKit/Source/bindings/core/v8/RemoteWindowProxy.cpp |
| diff --git a/third_party/WebKit/Source/bindings/core/v8/WindowProxy.h b/third_party/WebKit/Source/bindings/core/v8/RemoteWindowProxy.cpp |
| similarity index 28% |
| copy from third_party/WebKit/Source/bindings/core/v8/WindowProxy.h |
| copy to third_party/WebKit/Source/bindings/core/v8/RemoteWindowProxy.cpp |
| index 9f074f2b304169e795c11e78e0145236aa167b0a..90d4e121c6fc24b07e4872ccccd537622fb61e25 100644 |
| --- a/third_party/WebKit/Source/bindings/core/v8/WindowProxy.h |
| +++ b/third_party/WebKit/Source/bindings/core/v8/RemoteWindowProxy.cpp |
| @@ -1,5 +1,5 @@ |
| /* |
| - * Copyright (C) 2009 Google Inc. All rights reserved. |
|
dcheng
2017/01/11 08:35:16
I was unable to get the diffbase on Rietveld to wo
|
| + * Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved. |
| * |
| * Redistribution and use in source and binary forms, with or without |
| * modification, are permitted provided that the following conditions are |
| @@ -28,104 +28,122 @@ |
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| -#ifndef WindowProxy_h |
| -#define WindowProxy_h |
| +#include "bindings/core/v8/WindowProxy.h" |
| +#include "bindings/core/v8/ConditionalFeatures.h" |
| #include "bindings/core/v8/DOMWrapperWorld.h" |
| -#include "bindings/core/v8/ScopedPersistent.h" |
| -#include "bindings/core/v8/ScriptState.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/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 "wtf/HashMap.h" |
| -#include "wtf/PassRefPtr.h" |
| -#include "wtf/RefPtr.h" |
| -#include "wtf/text/AtomicString.h" |
| +#include "public/platform/Platform.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 { |
| -class Frame; |
| -class HTMLDocument; |
| -class SecurityOrigin; |
| +RemoteWindowProxy::~RemoteWindowProxy() { |
| + // clearForClose() or clearForNavigation() must be invoked before destruction |
| + // starts. |
| + DCHECK(m_lifecycle != Lifecycle::ContextInitialized); |
| +} |
| -// WindowProxy represents all the per-global object state for a Frame that |
| -// persist between navigations. |
| -class WindowProxy final : public GarbageCollectedFinalized<WindowProxy> { |
| - public: |
| - static WindowProxy* create(v8::Isolate*, Frame*, DOMWrapperWorld&); |
| +RemoteWindowProxy::RemoteWindowProxy(RemoteFrame& frame, |
| + v8::Isolate* isolate, |
| + RefPtr<DOMWrapperWorld> world) |
| + : WindowProxy(frame, isolate, std::move(world)) {} |
| - ~WindowProxy(); |
| - DECLARE_TRACE(); |
| +void RemoteWindowProxy::disposeContext(GlobalDetachmentBehavior behavior) { |
| + if (m_lifecycle != Lifecycle::ContextInitialized) |
| + return; |
| - v8::Local<v8::Context> contextIfInitialized() const { |
| - return m_scriptState ? m_scriptState->context() : v8::Local<v8::Context>(); |
| - } |
| - ScriptState* getScriptState() const { return m_scriptState.get(); } |
| - |
| - // Update document object of the frame. |
| - void updateDocument(); |
| - |
| - void namedItemAdded(HTMLDocument*, const AtomicString&); |
| - void namedItemRemoved(HTMLDocument*, const AtomicString&); |
| - |
| - // Update the security origin of a document |
| - // (e.g., after setting docoument.domain). |
| - void updateSecurityOrigin(SecurityOrigin*); |
| - |
| - void initializeIfNeeded(); |
| - |
| - void clearForNavigation(); |
| - void clearForClose(); |
| + WindowProxy::disposeContext(behavior); |
| +} |
| - v8::Local<v8::Object> globalIfNotDetached(); |
| - v8::Local<v8::Object> releaseGlobal(); |
| - void setGlobal(v8::Local<v8::Object>); |
| +void RemoteWindowProxy::initialize() { |
| + TRACE_EVENT1("v8", "RemoteWindowProxy::initialize", "isMainWindow", |
| + frame()->isMainFrame()); |
| + SCOPED_BLINK_UMA_HISTOGRAM_TIMER( |
| + frame()->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy" |
| + : "Blink.Binding.InitializeNonMainWindowProxy"); |
| - DOMWrapperWorld& world() { return *m_world; } |
| + ScriptForbiddenScope::AllowUserAgentScript allowScript; |
| - private: |
| - // A valid transition is from ContextUninitialized to ContextInitialized, |
| - // and then ContextDetached. Other transitions are forbidden. |
| - enum class Lifecycle { |
| - ContextUninitialized, |
| - ContextInitialized, |
| - ContextDetached, |
| - }; |
| + v8::HandleScope handleScope(isolate()); |
| - WindowProxy(Frame*, PassRefPtr<DOMWrapperWorld>, v8::Isolate*); |
| - void initialize(); |
| + createContext(); |
| - enum GlobalDetachmentBehavior { DoNotDetachGlobal, DetachGlobal }; |
| - void disposeContext(GlobalDetachmentBehavior); |
| - |
| - void setSecurityToken(SecurityOrigin*); |
| - |
| - // The JavaScript wrapper for the document object is cached on the global |
| - // object for fast access. UpdateDocumentProperty sets the wrapper |
| - // for the current document on the global object. |
| - void updateDocumentProperty(); |
| - |
| - // Updates Activity Logger for the current context. |
| - void updateActivityLogger(); |
| + 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()); |
| + } |
| - // Creates a new v8::Context with the window wrapper object as the global |
| - // object (aka the inner global). Note that the window wrapper and its |
| - // prototype chain do not get fully initialized yet, e.g. the window |
| - // wrapper is not yet associated with the native DOMWindow object. |
| - void createContext(); |
| + setupWindowPrototypeChain(); |
| + |
| + // Remote frames always require a full canAccess() check. |
|
dcheng
2017/01/11 08:35:16
Moving this here allows us to cleanup the logic in
|
| + context->UseDefaultSecurityToken(); |
| +} |
| + |
| +void RemoteWindowProxy::createContext() { |
|
Yuki
2017/01/11 10:09:24
Can we unify the implementation between local and
dcheng
2017/01/11 10:35:28
I intentionally split this, because RemoteWindowPr
|
| + // Create a new v8::Context with the window object as the global object |
| + // (aka the inner global). Reuse the global proxy object (aka the outer |
| + // global) if it already exists. See the comments in |
| + // setupWindowPrototypeChain for the structure of the prototype chain of |
| + // the global object. |
| + v8::Local<v8::ObjectTemplate> globalTemplate = |
| + 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()); |
| - // Associates the window wrapper and its prototype chain with the native |
| - // DOMWindow object. Also does some more Window-specific initialization. |
| - void setupWindowPrototypeChain(); |
| + m_scriptState = ScriptState::create(context, m_world); |
| - Member<Frame> m_frame; |
| - v8::Isolate* m_isolate; |
| - RefPtr<ScriptState> m_scriptState; |
| - RefPtr<DOMWrapperWorld> m_world; |
| - ScopedPersistent<v8::Object> m_globalProxy; |
| - Lifecycle m_lifecycle; |
| -}; |
| + // 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()); |
| +} |
| } // namespace blink |
| - |
| -#endif // WindowProxy_h |