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..b6dbf0a8af24b39d6cfe4810acec24ebd5304306 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(m_lifecycle == Lifecycle::ContextInitialized); |
Yuki
2017/02/14 11:24:37
nit: DCHECK_EQ?
|
+ 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,44 @@ 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()) |
+ 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() { |
+ // For a remote window, only the global proxy (the outer global object) needs |
+ // to have its internal fields set to point at the DOMWindow. |
+ DOMWindow* window = frame()->domWindow(); |
+ const WrapperTypeInfo* wrapperTypeInfo = window->wrapperTypeInfo(); |
+ // The global proxy object. Note this is not the global object. |
+#if 1 |
+ V8DOMWrapper::setNativeInfo(isolate(), m_globalProxy.newLocal(isolate()), |
dcheng
2017/02/14 10:02:02
Note: this recently changed in https://codereview.
|
+ wrapperTypeInfo, window); |
+#else |
+ v8::Local<v8::Object> globalProxy = m_globalProxy.newLocal(isolate()); |
+ CHECK(m_globalProxy == globalProxy); |
Yuki
2017/02/14 11:24:37
nit: This CHECK doesn't make much sense just after
|
+ v8::Local<v8::Object> associatedWrapper = |
+ V8DOMWrapper::associateObjectWithWrapper(isolate(), window, |
+ wrapperTypeInfo, globalProxy); |
+ CHECK(globalProxy == associatedWrapper); |
+#endif |
+ // 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 |