Skip to content

Commit

Permalink
Revert "Prepare WindowProxy for using v8::Context::NewRemoteContext()."
Browse files Browse the repository at this point in the history
This reverts commit 1ffffb4.

[email protected],[email protected]
BUG=696528

Review-Url: https://codereview.chromium.org/2739533002 .
Cr-Commit-Position: refs/branch-heads/3029@{#31}
Cr-Branched-From: 939b32e-refs/heads/master@{#454471}
  • Loading branch information
zetafunction committed Mar 6, 2017
1 parent 52dc59e commit 1ba2e2f
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 288 deletions.
83 changes: 5 additions & 78 deletions third_party/WebKit/Source/bindings/core/v8/LocalWindowProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@
#include "bindings/core/v8/ToV8.h"
#include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8DOMActivityLogger.h"
#include "bindings/core/v8/V8GCForContextDispose.h"
#include "bindings/core/v8/V8HTMLDocument.h"
#include "bindings/core/v8/V8HiddenValue.h"
#include "bindings/core/v8/V8Initializer.h"
#include "bindings/core/v8/V8PagePopupControllerBinding.h"
#include "bindings/core/v8/V8PrivateProperty.h"
#include "bindings/core/v8/V8Window.h"
#include "core/dom/Modulator.h"
Expand Down Expand Up @@ -77,36 +75,7 @@ void LocalWindowProxy::disposeContext(GlobalDetachmentBehavior behavior) {
m_world->worldId());
MainThreadDebugger::instance()->contextWillBeDestroyed(m_scriptState.get());

if (behavior == DetachGlobal) {
v8::Local<v8::Context> context = m_scriptState->context();
// Clean up state on the global proxy, which will be reused.
if (!m_globalProxy.isEmpty()) {
// TODO(yukishiino): This DCHECK failed on Canary (M57) and Dev (M56).
// We need to figure out why m_globalProxy != context->Global().
DCHECK(m_globalProxy == context->Global());
DCHECK_EQ(toScriptWrappable(context->Global()),
toScriptWrappable(
context->Global()->GetPrototype().As<v8::Object>()));
m_globalProxy.get().SetWrapperClassId(0);
}
V8DOMWrapper::clearNativeInfo(isolate(), context->Global());
m_scriptState->detachGlobalObject();

#if DCHECK_IS_ON()
didDetachGlobalProxy();
#endif
}

m_scriptState->disposePerContextData();

// It's likely that disposing the context has created a lot of
// garbage. Notify V8 about this so it'll have a chance of cleaning
// it up when idle.
V8GCForContextDispose::instance().notifyContextDisposed(
frame()->isMainFrame());

DCHECK(m_lifecycle == Lifecycle::ContextInitialized);
m_lifecycle = Lifecycle::ContextDetached;
WindowProxy::disposeContext(behavior);
}

void LocalWindowProxy::initialize() {
Expand Down Expand Up @@ -162,54 +131,12 @@ void LocalWindowProxy::initialize() {
frame()->loader().dispatchDidClearWindowObjectInMainWorld();
}

void LocalWindowProxy::setupWindowPrototypeChain() {
// Associate the window wrapper object and its prototype chain with the
// corresponding native DOMWindow object.
LocalDOMWindow* window = frame()->domWindow();
const WrapperTypeInfo* wrapperTypeInfo = window->wrapperTypeInfo();
v8::Local<v8::Context> context = m_scriptState->context();

// The global proxy object. Note this is not the global object.
v8::Local<v8::Object> globalProxy = context->Global();
CHECK(m_globalProxy == globalProxy);
V8DOMWrapper::setNativeInfo(isolate(), globalProxy, 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

// The global object, aka window wrapper object.
v8::Local<v8::Object> windowWrapper =
globalProxy->GetPrototype().As<v8::Object>();
V8DOMWrapper::setNativeInfo(isolate(), windowWrapper, wrapperTypeInfo,
window);

// The prototype object of Window interface.
v8::Local<v8::Object> windowPrototype =
windowWrapper->GetPrototype().As<v8::Object>();
CHECK(!windowPrototype.IsEmpty());
V8DOMWrapper::setNativeInfo(isolate(), windowPrototype, wrapperTypeInfo,
window);

// The named properties object of Window interface.
v8::Local<v8::Object> windowProperties =
windowPrototype->GetPrototype().As<v8::Object>();
CHECK(!windowProperties.IsEmpty());
V8DOMWrapper::setNativeInfo(isolate(), windowProperties, wrapperTypeInfo,
window);

// TODO(keishi): Remove installPagePopupController and implement
// PagePopupController in another way.
V8PagePopupControllerBinding::installPagePopupController(context,
windowWrapper);
}

void LocalWindowProxy::createContext() {
// Create a new v8::Context with the window object as the global object
// (aka the inner global). Reuse the outer global proxy if it already exists.
// (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());
Expand Down
11 changes: 0 additions & 11 deletions third_party/WebKit/Source/bindings/core/v8/LocalWindowProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ class LocalWindowProxy final : public WindowProxy {
// (e.g., after setting docoument.domain).
void updateSecurityOrigin(SecurityOrigin*);

ScriptState* getScriptState() const { return m_scriptState.get(); }
v8::Local<v8::Context> contextIfInitialized() const {
return m_scriptState ? m_scriptState->context() : v8::Local<v8::Context>();
}

private:
LocalWindowProxy(v8::Isolate*, LocalFrame&, RefPtr<DOMWrapperWorld>);

Expand All @@ -79,10 +74,6 @@ class LocalWindowProxy final : public WindowProxy {
// wrapper is not yet associated with the native DOMWindow object.
void createContext();

// Associates the window wrapper and its prototype chain with the native
// DOMWindow object. Also does some more Window-specific initialization.
void setupWindowPrototypeChain();

void setSecurityToken(SecurityOrigin*);

// The JavaScript wrapper for the document object is cached on the global
Expand All @@ -94,8 +85,6 @@ class LocalWindowProxy final : public WindowProxy {
void updateActivityLogger();

LocalFrame* frame() const { return toLocalFrame(WindowProxy::frame()); }

RefPtr<ScriptState> m_scriptState;
};

} // namespace blink
Expand Down
108 changes: 36 additions & 72 deletions third_party/WebKit/Source/bindings/core/v8/RemoteWindowProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,50 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "bindings/core/v8/RemoteWindowProxy.h"
#include "bindings/core/v8/WindowProxy.h"

#include <algorithm>
#include <utility>

#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/V8Window.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/LocalFrameClient.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/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-debug.h"
#include "v8/include/v8.h"
#include "wtf/Assertions.h"
#include "wtf/StringExtras.h"
#include "wtf/text/CString.h"

namespace blink {

Expand All @@ -54,36 +84,7 @@ void RemoteWindowProxy::disposeContext(GlobalDetachmentBehavior behavior) {
if (m_lifecycle != Lifecycle::ContextInitialized)
return;

if (behavior == DetachGlobal) {
v8::Local<v8::Context> context = m_scriptState->context();
// Clean up state on the global proxy, which will be reused.
if (!m_globalProxy.isEmpty()) {
// TODO(yukishiino): This DCHECK failed on Canary (M57) and Dev (M56).
// We need to figure out why m_globalProxy != context->Global().
DCHECK(m_globalProxy == context->Global());
DCHECK_EQ(toScriptWrappable(context->Global()),
toScriptWrappable(
context->Global()->GetPrototype().As<v8::Object>()));
m_globalProxy.get().SetWrapperClassId(0);
}
V8DOMWrapper::clearNativeInfo(isolate(), context->Global());
m_scriptState->detachGlobalObject();

#if DCHECK_IS_ON()
didDetachGlobalProxy();
#endif
}

m_scriptState->disposePerContextData();

// It's likely that disposing the context has created a lot of
// garbage. Notify V8 about this so it'll have a chance of cleaning
// it up when idle.
V8GCForContextDispose::instance().notifyContextDisposed(
frame()->isMainFrame());

DCHECK(m_lifecycle == Lifecycle::ContextInitialized);
m_lifecycle = Lifecycle::ContextDetached;
WindowProxy::disposeContext(behavior);
}

void RemoteWindowProxy::initialize() {
Expand Down Expand Up @@ -112,49 +113,12 @@ void RemoteWindowProxy::initialize() {
context->UseDefaultSecurityToken();
}

void RemoteWindowProxy::setupWindowPrototypeChain() {
// Associate the window wrapper object and its prototype chain with the
// corresponding native DOMWindow object.
DOMWindow* window = frame()->domWindow();
const WrapperTypeInfo* wrapperTypeInfo = window->wrapperTypeInfo();
v8::Local<v8::Context> context = m_scriptState->context();

// The global proxy object. Note this is not the global object.
v8::Local<v8::Object> globalProxy = context->Global();
CHECK(m_globalProxy == globalProxy);
V8DOMWrapper::setNativeInfo(isolate(), globalProxy, 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

// The global object, aka window wrapper object.
v8::Local<v8::Object> windowWrapper =
globalProxy->GetPrototype().As<v8::Object>();
V8DOMWrapper::setNativeInfo(isolate(), windowWrapper, wrapperTypeInfo,
window);

// The prototype object of Window interface.
v8::Local<v8::Object> windowPrototype =
windowWrapper->GetPrototype().As<v8::Object>();
CHECK(!windowPrototype.IsEmpty());
V8DOMWrapper::setNativeInfo(isolate(), windowPrototype, wrapperTypeInfo,
window);

// The named properties object of Window interface.
v8::Local<v8::Object> windowProperties =
windowPrototype->GetPrototype().As<v8::Object>();
CHECK(!windowProperties.IsEmpty());
V8DOMWrapper::setNativeInfo(isolate(), windowProperties, wrapperTypeInfo,
window);
}

void RemoteWindowProxy::createContext() {
// Create a new v8::Context with the window object as the global object
// (aka the inner global). Reuse the outer global proxy if it already exists.
// (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());
Expand Down
23 changes: 0 additions & 23 deletions third_party/WebKit/Source/bindings/core/v8/RemoteWindowProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,12 @@
#define RemoteWindowProxy_h

#include "bindings/core/v8/DOMWrapperWorld.h"
#include "bindings/core/v8/ScriptState.h"
#include "bindings/core/v8/WindowProxy.h"
#include "core/frame/RemoteFrame.h"
#include "v8/include/v8.h"
#include "wtf/RefPtr.h"

namespace blink {

// Subclass of WindowProxy that only handles RemoteFrame.
// TODO(dcheng): This class currently duplicates a lot of logic from
// LocalWindowPoxy:
// - contextIfInitialized
// - initialize
// - disposeContext
// - setupWindowPrototypeChain
// - createContext
// This is currently duplicated to make it easier to stage the switch to using
// v8::RemoteContext::NewRemoteContext, and will be removed once the switch
// is complete.
class RemoteWindowProxy final : public WindowProxy {
public:
static RemoteWindowProxy* create(v8::Isolate* isolate,
Expand All @@ -60,27 +47,17 @@ class RemoteWindowProxy final : public WindowProxy {
return new RemoteWindowProxy(isolate, frame, std::move(world));
}

v8::Local<v8::Context> contextIfInitialized() const {
return m_scriptState ? m_scriptState->context() : v8::Local<v8::Context>();
}

private:
RemoteWindowProxy(v8::Isolate*, RemoteFrame&, RefPtr<DOMWrapperWorld>);

void initialize() override;
void disposeContext(GlobalDetachmentBehavior) override;

// Associates the window wrapper and its prototype chain with the native
// DOMWindow object. Also does some more Window-specific initialization.
void setupWindowPrototypeChain();

// 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();

RefPtr<ScriptState> m_scriptState;
};

} // namespace blink
Expand Down
6 changes: 5 additions & 1 deletion third_party/WebKit/Source/bindings/core/v8/ScriptState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ ScriptState::ScriptState(v8::Local<v8::Context> context,
: m_isolate(context->GetIsolate()),
m_context(m_isolate, context),
m_world(world),
m_perContextData(V8PerContextData::create(context)) {
m_perContextData(V8PerContextData::create(context))
{
DCHECK(m_world);
m_context.setWeak(this, &contextCollectedCallback);
context->SetAlignedPointerInEmbedderData(v8ContextPerContextDataIndex, this);
Expand All @@ -50,6 +51,9 @@ ScriptState::~ScriptState() {
void ScriptState::detachGlobalObject() {
ASSERT(!m_context.isEmpty());
context()->DetachGlobal();
#if DCHECK_IS_ON()
m_globalObjectDetached = true;
#endif
}

void ScriptState::disposePerContextData() {
Expand Down
7 changes: 7 additions & 0 deletions third_party/WebKit/Source/bindings/core/v8/ScriptState.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ class CORE_EXPORT ScriptState : public RefCounted<ScriptState> {
}
void detachGlobalObject();
void clearContext() { return m_context.clear(); }
#if DCHECK_IS_ON()
bool isGlobalObjectDetached() const { return m_globalObjectDetached; }
#endif

V8PerContextData* perContextData() const { return m_perContextData.get(); }
void disposePerContextData();
Expand All @@ -181,6 +184,10 @@ class CORE_EXPORT ScriptState : public RefCounted<ScriptState> {
// disposePerContextData() once you no longer need V8PerContextData.
// Otherwise, the v8::Context will leak.
std::unique_ptr<V8PerContextData> m_perContextData;

#if DCHECK_IS_ON()
bool m_globalObjectDetached = false;
#endif
};

// ScriptStateProtectingContext keeps the context associated with the
Expand Down
Loading

0 comments on commit 1ba2e2f

Please sign in to comment.