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 <v8-debug.h> |
| 34 #include <v8.h> |
| 35 #include <algorithm> |
| 36 #include <utility> |
| 37 #include "bindings/core/v8/ConditionalFeatures.h" |
33 #include "bindings/core/v8/DOMWrapperWorld.h" | 38 #include "bindings/core/v8/DOMWrapperWorld.h" |
34 #include "bindings/core/v8/V8DOMWrapper.h" | 39 #include "bindings/core/v8/ScriptController.h" |
| 40 #include "bindings/core/v8/ToV8.h" |
| 41 #include "bindings/core/v8/V8Binding.h" |
| 42 #include "bindings/core/v8/V8DOMActivityLogger.h" |
| 43 #include "bindings/core/v8/V8Document.h" |
| 44 #include "bindings/core/v8/V8GCForContextDispose.h" |
| 45 #include "bindings/core/v8/V8HTMLCollection.h" |
| 46 #include "bindings/core/v8/V8HTMLDocument.h" |
| 47 #include "bindings/core/v8/V8HiddenValue.h" |
| 48 #include "bindings/core/v8/V8Initializer.h" |
| 49 #include "bindings/core/v8/V8ObjectConstructor.h" |
| 50 #include "bindings/core/v8/V8PagePopupControllerBinding.h" |
| 51 #include "bindings/core/v8/V8PrivateProperty.h" |
35 #include "bindings/core/v8/V8Window.h" | 52 #include "bindings/core/v8/V8Window.h" |
| 53 #include "core/frame/LocalFrame.h" |
| 54 #include "core/frame/LocalFrameClient.h" |
| 55 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 56 #include "core/html/DocumentNameCollection.h" |
| 57 #include "core/html/HTMLCollection.h" |
| 58 #include "core/html/HTMLIFrameElement.h" |
| 59 #include "core/inspector/InspectorInstrumentation.h" |
| 60 #include "core/inspector/MainThreadDebugger.h" |
| 61 #include "core/loader/DocumentLoader.h" |
| 62 #include "core/loader/FrameLoader.h" |
| 63 #include "core/origin_trials/OriginTrialContext.h" |
36 #include "platform/Histogram.h" | 64 #include "platform/Histogram.h" |
| 65 #include "platform/RuntimeEnabledFeatures.h" |
| 66 #include "platform/ScriptForbiddenScope.h" |
| 67 #include "platform/heap/Handle.h" |
37 #include "platform/instrumentation/tracing/TraceEvent.h" | 68 #include "platform/instrumentation/tracing/TraceEvent.h" |
38 #include "v8/include/v8.h" | 69 #include "platform/weborigin/SecurityOrigin.h" |
| 70 #include "public/platform/Platform.h" |
39 #include "wtf/Assertions.h" | 71 #include "wtf/Assertions.h" |
| 72 #include "wtf/StringExtras.h" |
| 73 #include "wtf/text/CString.h" |
40 | 74 |
41 namespace blink { | 75 namespace blink { |
42 | 76 |
43 RemoteWindowProxy::RemoteWindowProxy(v8::Isolate* isolate, | 77 RemoteWindowProxy::RemoteWindowProxy(v8::Isolate* isolate, |
44 RemoteFrame& frame, | 78 RemoteFrame& frame, |
45 RefPtr<DOMWrapperWorld> world) | 79 RefPtr<DOMWrapperWorld> world) |
46 : WindowProxy(isolate, frame, std::move(world)) {} | 80 : WindowProxy(isolate, frame, std::move(world)) {} |
47 | 81 |
48 void RemoteWindowProxy::disposeContext(GlobalDetachmentBehavior behavior) { | 82 void RemoteWindowProxy::disposeContext(GlobalDetachmentBehavior behavior) { |
49 if (m_lifecycle != Lifecycle::ContextInitialized) | 83 if (m_lifecycle != Lifecycle::ContextInitialized) |
50 return; | 84 return; |
51 | 85 |
52 if (behavior == DetachGlobal && !m_globalProxy.isEmpty()) { | 86 WindowProxy::disposeContext(behavior); |
53 m_globalProxy.get().SetWrapperClassId(0); | |
54 V8DOMWrapper::clearNativeInfo(isolate(), m_globalProxy.newLocal(isolate())); | |
55 #if DCHECK_IS_ON() | |
56 didDetachGlobalProxy(); | |
57 #endif | |
58 } | |
59 | |
60 DCHECK_EQ(Lifecycle::ContextInitialized, m_lifecycle); | |
61 m_lifecycle = Lifecycle::ContextDetached; | |
62 } | 87 } |
63 | 88 |
64 void RemoteWindowProxy::initialize() { | 89 void RemoteWindowProxy::initialize() { |
65 TRACE_EVENT1("v8", "RemoteWindowProxy::initialize", "isMainWindow", | 90 TRACE_EVENT1("v8", "RemoteWindowProxy::initialize", "isMainWindow", |
66 frame()->isMainFrame()); | 91 frame()->isMainFrame()); |
67 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( | 92 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( |
68 frame()->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy" | 93 frame()->isMainFrame() ? "Blink.Binding.InitializeMainWindowProxy" |
69 : "Blink.Binding.InitializeNonMainWindowProxy"); | 94 : "Blink.Binding.InitializeNonMainWindowProxy"); |
70 | 95 |
| 96 ScriptForbiddenScope::AllowUserAgentScript allowScript; |
| 97 |
71 v8::HandleScope handleScope(isolate()); | 98 v8::HandleScope handleScope(isolate()); |
72 | 99 |
73 createContext(); | 100 createContext(); |
74 | 101 |
| 102 ScriptState::Scope scope(m_scriptState.get()); |
| 103 v8::Local<v8::Context> context = m_scriptState->context(); |
| 104 if (m_globalProxy.isEmpty()) { |
| 105 m_globalProxy.set(isolate(), context->Global()); |
| 106 CHECK(!m_globalProxy.isEmpty()); |
| 107 } |
| 108 |
75 setupWindowPrototypeChain(); | 109 setupWindowPrototypeChain(); |
| 110 |
| 111 // Remote frames always require a full canAccess() check. |
| 112 context->UseDefaultSecurityToken(); |
76 } | 113 } |
77 | 114 |
78 void RemoteWindowProxy::createContext() { | 115 void RemoteWindowProxy::createContext() { |
79 // Create a new v8::Context with the window object as the global object | 116 // Create a new v8::Context with the window object as the global object |
80 // (aka the inner global). Reuse the global proxy object (aka the outer | 117 // (aka the inner global). Reuse the global proxy object (aka the outer |
81 // global) if it already exists. See the comments in | 118 // global) if it already exists. See the comments in |
82 // setupWindowPrototypeChain for the structure of the prototype chain of | 119 // setupWindowPrototypeChain for the structure of the prototype chain of |
83 // the global object. | 120 // the global object. |
84 v8::Local<v8::ObjectTemplate> globalTemplate = | 121 v8::Local<v8::ObjectTemplate> globalTemplate = |
85 V8Window::domTemplate(isolate(), *m_world)->InstanceTemplate(); | 122 V8Window::domTemplate(isolate(), *m_world)->InstanceTemplate(); |
86 CHECK(!globalTemplate.IsEmpty()); | 123 CHECK(!globalTemplate.IsEmpty()); |
87 | 124 |
88 v8::Local<v8::Object> globalProxy = | 125 v8::Local<v8::Context> context; |
89 v8::Context::NewRemoteContext(isolate(), globalTemplate, | 126 { |
90 m_globalProxy.newLocal(isolate())) | 127 V8PerIsolateData::UseCounterDisabledScope useCounterDisabled( |
91 .ToLocalChecked(); | 128 V8PerIsolateData::from(isolate())); |
92 if (m_globalProxy.isEmpty()) | 129 context = v8::Context::New(isolate(), nullptr, globalTemplate, |
93 m_globalProxy.set(isolate(), globalProxy); | 130 m_globalProxy.newLocal(isolate())); |
94 else | 131 } |
95 DCHECK(m_globalProxy.get() == globalProxy); | 132 CHECK(!context.IsEmpty()); |
96 CHECK(!m_globalProxy.isEmpty()); | 133 |
| 134 m_scriptState = ScriptState::create(context, m_world); |
97 | 135 |
98 // TODO(haraken): Currently we cannot enable the following DCHECK because | 136 // TODO(haraken): Currently we cannot enable the following DCHECK because |
99 // an already detached window proxy can be re-initialized. This is wrong. | 137 // an already detached window proxy can be re-initialized. This is wrong. |
100 // DCHECK(m_lifecycle == Lifecycle::ContextUninitialized); | 138 // DCHECK(m_lifecycle == Lifecycle::ContextUninitialized); |
101 m_lifecycle = Lifecycle::ContextInitialized; | 139 m_lifecycle = Lifecycle::ContextInitialized; |
102 } | 140 DCHECK(m_scriptState->contextIsValid()); |
103 | |
104 void RemoteWindowProxy::setupWindowPrototypeChain() { | |
105 DOMWindow* window = frame()->domWindow(); | |
106 const WrapperTypeInfo* wrapperTypeInfo = window->wrapperTypeInfo(); | |
107 // The global proxy object. Note this is not the global object. | |
108 v8::Local<v8::Object> globalProxy = m_globalProxy.newLocal(isolate()); | |
109 V8DOMWrapper::setNativeInfo(isolate(), globalProxy, wrapperTypeInfo, window); | |
110 // Mark the handle to be traced by Oilpan, since the global proxy has a | |
111 // reference to the DOMWindow. | |
112 m_globalProxy.get().SetWrapperClassId(wrapperTypeInfo->wrapperClassId); | |
113 | |
114 #if DCHECK_IS_ON() | |
115 didAttachGlobalProxy(); | |
116 #endif | |
117 | |
118 // The global object, aka window wrapper object. | |
119 v8::Local<v8::Object> windowWrapper = | |
120 globalProxy->GetPrototype().As<v8::Object>(); | |
121 V8DOMWrapper::setNativeInfo(isolate(), windowWrapper, wrapperTypeInfo, | |
122 window); | |
123 } | 141 } |
124 | 142 |
125 } // namespace blink | 143 } // namespace blink |
OLD | NEW |