OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. |
3 * Copyright (C) 2009 Apple Inc. All rights reserved. | 3 * Copyright (C) 2009 Apple Inc. All rights reserved. |
4 * Copyright (C) 2014 Opera Software ASA. All rights reserved. | 4 * Copyright (C) 2014 Opera Software ASA. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions are | 7 * modification, are permitted provided that the following conditions are |
8 * met: | 8 * met: |
9 * | 9 * |
10 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
(...skipping 29 matching lines...) Expand all Loading... |
40 #include "bindings/core/v8/ScriptValue.h" | 40 #include "bindings/core/v8/ScriptValue.h" |
41 #include "bindings/core/v8/V8Binding.h" | 41 #include "bindings/core/v8/V8Binding.h" |
42 #include "bindings/core/v8/V8Event.h" | 42 #include "bindings/core/v8/V8Event.h" |
43 #include "bindings/core/v8/V8GCController.h" | 43 #include "bindings/core/v8/V8GCController.h" |
44 #include "bindings/core/v8/V8HTMLElement.h" | 44 #include "bindings/core/v8/V8HTMLElement.h" |
45 #include "bindings/core/v8/V8NPObject.h" | 45 #include "bindings/core/v8/V8NPObject.h" |
46 #include "bindings/core/v8/V8PerContextData.h" | 46 #include "bindings/core/v8/V8PerContextData.h" |
47 #include "bindings/core/v8/V8ScriptRunner.h" | 47 #include "bindings/core/v8/V8ScriptRunner.h" |
48 #include "bindings/core/v8/V8Window.h" | 48 #include "bindings/core/v8/V8Window.h" |
49 #include "bindings/core/v8/WindowProxy.h" | 49 #include "bindings/core/v8/WindowProxy.h" |
| 50 #include "bindings/core/v8/WindowProxyManager.h" |
50 #include "bindings/core/v8/npruntime_impl.h" | 51 #include "bindings/core/v8/npruntime_impl.h" |
51 #include "bindings/core/v8/npruntime_priv.h" | 52 #include "bindings/core/v8/npruntime_priv.h" |
52 #include "core/dom/Document.h" | 53 #include "core/dom/Document.h" |
53 #include "core/dom/Node.h" | 54 #include "core/dom/Node.h" |
54 #include "core/dom/ScriptableDocumentParser.h" | 55 #include "core/dom/ScriptableDocumentParser.h" |
55 #include "core/events/Event.h" | 56 #include "core/events/Event.h" |
56 #include "core/events/EventListener.h" | 57 #include "core/events/EventListener.h" |
57 #include "core/frame/LocalDOMWindow.h" | 58 #include "core/frame/LocalDOMWindow.h" |
58 #include "core/frame/LocalFrame.h" | |
59 #include "core/frame/Settings.h" | 59 #include "core/frame/Settings.h" |
60 #include "core/frame/UseCounter.h" | 60 #include "core/frame/UseCounter.h" |
61 #include "core/frame/csp/ContentSecurityPolicy.h" | 61 #include "core/frame/csp/ContentSecurityPolicy.h" |
62 #include "core/html/HTMLPlugInElement.h" | 62 #include "core/html/HTMLPlugInElement.h" |
63 #include "core/inspector/InspectorInstrumentation.h" | 63 #include "core/inspector/InspectorInstrumentation.h" |
64 #include "core/inspector/InspectorTraceEvents.h" | 64 #include "core/inspector/InspectorTraceEvents.h" |
65 #include "core/inspector/ScriptCallStack.h" | 65 #include "core/inspector/ScriptCallStack.h" |
66 #include "core/loader/DocumentLoader.h" | 66 #include "core/loader/DocumentLoader.h" |
67 #include "core/loader/FrameLoader.h" | 67 #include "core/loader/FrameLoader.h" |
68 #include "core/loader/FrameLoaderClient.h" | 68 #include "core/loader/FrameLoaderClient.h" |
(...skipping 16 matching lines...) Expand all Loading... |
85 | 85 |
86 bool ScriptController::canAccessFromCurrentOrigin(LocalFrame *frame) | 86 bool ScriptController::canAccessFromCurrentOrigin(LocalFrame *frame) |
87 { | 87 { |
88 if (!frame) | 88 if (!frame) |
89 return false; | 89 return false; |
90 v8::Isolate* isolate = toIsolate(frame); | 90 v8::Isolate* isolate = toIsolate(frame); |
91 return !isolate->InContext() || BindingSecurity::shouldAllowAccessToFrame(is
olate, frame); | 91 return !isolate->InContext() || BindingSecurity::shouldAllowAccessToFrame(is
olate, frame); |
92 } | 92 } |
93 | 93 |
94 ScriptController::ScriptController(LocalFrame* frame) | 94 ScriptController::ScriptController(LocalFrame* frame) |
95 : m_frame(frame) | 95 : m_windowProxyManager(WindowProxyManager::create(frame)) |
96 , m_sourceURL(0) | 96 , m_sourceURL(0) |
97 , m_isolate(v8::Isolate::GetCurrent()) | |
98 , m_windowProxy(WindowProxy::create(frame, DOMWrapperWorld::mainWorld(), m_i
solate)) | |
99 , m_windowScriptNPObject(0) | 97 , m_windowScriptNPObject(0) |
100 { | 98 { |
101 } | 99 } |
102 | 100 |
103 ScriptController::~ScriptController() | 101 ScriptController::~ScriptController() |
104 { | 102 { |
105 } | 103 } |
106 | 104 |
107 void ScriptController::trace(Visitor* visitor) | 105 void ScriptController::trace(Visitor* visitor) |
108 { | 106 { |
109 #if ENABLE(OILPAN) | 107 #if ENABLE(OILPAN) |
110 visitor->trace(m_frame); | 108 visitor->trace(m_windowProxyManager); |
111 visitor->trace(m_windowProxy); | |
112 visitor->trace(m_isolatedWorlds); | |
113 #endif | 109 #endif |
114 } | 110 } |
115 | 111 |
116 void ScriptController::clearScriptObjects() | 112 void ScriptController::clearScriptObjects() |
117 { | 113 { |
118 PluginObjectMap::iterator it = m_pluginObjects.begin(); | 114 PluginObjectMap::iterator it = m_pluginObjects.begin(); |
119 for (; it != m_pluginObjects.end(); ++it) { | 115 for (; it != m_pluginObjects.end(); ++it) { |
120 _NPN_UnregisterObject(it->value); | 116 _NPN_UnregisterObject(it->value); |
121 _NPN_ReleaseObject(it->value); | 117 _NPN_ReleaseObject(it->value); |
122 } | 118 } |
123 m_pluginObjects.clear(); | 119 m_pluginObjects.clear(); |
124 | 120 |
125 if (m_windowScriptNPObject) { | 121 if (m_windowScriptNPObject) { |
126 // Dispose of the underlying V8 object before releasing our reference | 122 // Dispose of the underlying V8 object before releasing our reference |
127 // to it, so that if a plugin fails to release it properly we will | 123 // to it, so that if a plugin fails to release it properly we will |
128 // only leak the NPObject wrapper, not the object, its document, or | 124 // only leak the NPObject wrapper, not the object, its document, or |
129 // anything else they reference. | 125 // anything else they reference. |
130 disposeUnderlyingV8Object(m_isolate, m_windowScriptNPObject); | 126 disposeUnderlyingV8Object(isolate(), m_windowScriptNPObject); |
131 _NPN_ReleaseObject(m_windowScriptNPObject); | 127 _NPN_ReleaseObject(m_windowScriptNPObject); |
132 m_windowScriptNPObject = 0; | 128 m_windowScriptNPObject = 0; |
133 } | 129 } |
134 } | 130 } |
135 | 131 |
136 void ScriptController::clearForClose() | 132 void ScriptController::clearForClose() |
137 { | 133 { |
138 double start = currentTime(); | 134 double start = currentTime(); |
139 m_windowProxy->clearForClose(); | 135 m_windowProxyManager->clearForClose(); |
140 for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin(); iter != m_i
solatedWorlds.end(); ++iter) | |
141 iter->value->clearForClose(); | |
142 blink::Platform::current()->histogramCustomCounts("WebCore.ScriptController.
clearForClose", (currentTime() - start) * 1000, 0, 10000, 50); | 136 blink::Platform::current()->histogramCustomCounts("WebCore.ScriptController.
clearForClose", (currentTime() - start) * 1000, 0, 10000, 50); |
143 } | 137 } |
144 | 138 |
145 void ScriptController::updateSecurityOrigin(SecurityOrigin* origin) | 139 void ScriptController::updateSecurityOrigin(SecurityOrigin* origin) |
146 { | 140 { |
147 m_windowProxy->updateSecurityOrigin(origin); | 141 m_windowProxyManager->mainWorldProxy()->updateSecurityOrigin(origin); |
148 } | 142 } |
149 | 143 |
150 v8::Local<v8::Value> ScriptController::callFunction(v8::Handle<v8::Function> fun
ction, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> info[]) | 144 v8::Local<v8::Value> ScriptController::callFunction(v8::Handle<v8::Function> fun
ction, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> info[]) |
151 { | 145 { |
152 // Keep LocalFrame (and therefore ScriptController) alive. | 146 // Keep LocalFrame (and therefore ScriptController) alive. |
153 RefPtrWillBeRawPtr<LocalFrame> protect(m_frame.get()); | 147 RefPtrWillBeRawPtr<LocalFrame> protect(frame()); |
154 return ScriptController::callFunction(m_frame->document(), function, receive
r, argc, info, m_isolate); | 148 return ScriptController::callFunction(frame()->document(), function, receive
r, argc, info, isolate()); |
155 } | 149 } |
156 | 150 |
157 v8::Local<v8::Value> ScriptController::callFunction(ExecutionContext* context, v
8::Handle<v8::Function> function, v8::Handle<v8::Value> receiver, int argc, v8::
Handle<v8::Value> info[], v8::Isolate* isolate) | 151 v8::Local<v8::Value> ScriptController::callFunction(ExecutionContext* context, v
8::Handle<v8::Function> function, v8::Handle<v8::Value> receiver, int argc, v8::
Handle<v8::Value> info[], v8::Isolate* isolate) |
158 { | 152 { |
159 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "FunctionCall",
"data", devToolsTraceEventData(isolate, context, function)); | 153 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "FunctionCall",
"data", devToolsTraceEventData(isolate, context, function)); |
160 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli
ne migrates to tracing. | 154 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli
ne migrates to tracing. |
161 InspectorInstrumentationCookie cookie; | 155 InspectorInstrumentationCookie cookie; |
162 if (InspectorInstrumentation::hasFrontends()) { | 156 if (InspectorInstrumentation::hasFrontends()) { |
163 int scriptId = 0; | 157 int scriptId = 0; |
164 String resourceName; | 158 String resourceName; |
165 int lineNumber = 1; | 159 int lineNumber = 1; |
166 GetDevToolsFunctionInfo(function, isolate, scriptId, resourceName, lineN
umber); | 160 GetDevToolsFunctionInfo(function, isolate, scriptId, resourceName, lineN
umber); |
167 cookie = InspectorInstrumentation::willCallFunction(context, scriptId, r
esourceName, lineNumber); | 161 cookie = InspectorInstrumentation::willCallFunction(context, scriptId, r
esourceName, lineNumber); |
168 } | 162 } |
169 | 163 |
170 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(function, context
, receiver, argc, info, isolate); | 164 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(function, context
, receiver, argc, info, isolate); |
171 | 165 |
172 InspectorInstrumentation::didCallFunction(cookie); | 166 InspectorInstrumentation::didCallFunction(cookie); |
173 return result; | 167 return result; |
174 } | 168 } |
175 | 169 |
176 v8::Local<v8::Value> ScriptController::executeScriptAndReturnValue(v8::Handle<v8
::Context> context, const ScriptSourceCode& source, AccessControlStatus corsStat
us, double* compilationFinishTime) | 170 v8::Local<v8::Value> ScriptController::executeScriptAndReturnValue(v8::Handle<v8
::Context> context, const ScriptSourceCode& source, AccessControlStatus corsStat
us, double* compilationFinishTime) |
177 { | 171 { |
178 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "EvaluateScript
", "data", InspectorEvaluateScriptEvent::data(m_frame, source.url().string(), so
urce.startLine())); | 172 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "EvaluateScript
", "data", InspectorEvaluateScriptEvent::data(frame(), source.url().string(), so
urce.startLine())); |
179 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli
ne migrates to tracing. | 173 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli
ne migrates to tracing. |
180 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvalua
teScript(m_frame, source.url().string(), source.startLine()); | 174 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvalua
teScript(frame(), source.url().string(), source.startLine()); |
181 | 175 |
182 v8::Local<v8::Value> result; | 176 v8::Local<v8::Value> result; |
183 { | 177 { |
184 V8CacheOptions v8CacheOptions(V8CacheOptionsDefault); | 178 V8CacheOptions v8CacheOptions(V8CacheOptionsDefault); |
185 if (m_frame->settings()) | 179 if (frame()->settings()) |
186 v8CacheOptions = m_frame->settings()->v8CacheOptions(); | 180 v8CacheOptions = frame()->settings()->v8CacheOptions(); |
187 | 181 |
188 // Isolate exceptions that occur when compiling and executing | 182 // Isolate exceptions that occur when compiling and executing |
189 // the code. These exceptions should not interfere with | 183 // the code. These exceptions should not interfere with |
190 // javascript code we might evaluate from C++ when returning | 184 // javascript code we might evaluate from C++ when returning |
191 // from here. | 185 // from here. |
192 v8::TryCatch tryCatch; | 186 v8::TryCatch tryCatch; |
193 tryCatch.SetVerbose(true); | 187 tryCatch.SetVerbose(true); |
194 | 188 |
195 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(source, m_
isolate, corsStatus, v8CacheOptions); | 189 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(source, is
olate(), corsStatus, v8CacheOptions); |
196 | 190 |
197 if (compilationFinishTime) { | 191 if (compilationFinishTime) { |
198 *compilationFinishTime = WTF::monotonicallyIncreasingTime(); | 192 *compilationFinishTime = WTF::monotonicallyIncreasingTime(); |
199 } | 193 } |
200 // Keep LocalFrame (and therefore ScriptController) alive. | 194 // Keep LocalFrame (and therefore ScriptController) alive. |
201 RefPtrWillBeRawPtr<LocalFrame> protect(m_frame.get()); | 195 RefPtrWillBeRawPtr<LocalFrame> protect(frame()); |
202 result = V8ScriptRunner::runCompiledScript(m_isolate, script, m_frame->d
ocument()); | 196 result = V8ScriptRunner::runCompiledScript(isolate(), script, frame()->d
ocument()); |
203 ASSERT(!tryCatch.HasCaught() || result.IsEmpty()); | 197 ASSERT(!tryCatch.HasCaught() || result.IsEmpty()); |
204 } | 198 } |
205 | 199 |
206 InspectorInstrumentation::didEvaluateScript(cookie); | 200 InspectorInstrumentation::didEvaluateScript(cookie); |
207 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update
Counters", "data", InspectorUpdateCountersEvent::data()); | 201 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update
Counters", "data", InspectorUpdateCountersEvent::data()); |
208 | 202 |
209 return result; | 203 return result; |
210 } | 204 } |
211 | 205 |
212 bool ScriptController::initializeMainWorld() | 206 bool ScriptController::initializeMainWorld() |
213 { | 207 { |
214 if (m_windowProxy->isContextInitialized()) | 208 if (m_windowProxyManager->mainWorldProxy()->isContextInitialized()) |
215 return false; | 209 return false; |
216 return windowProxy(DOMWrapperWorld::mainWorld())->isContextInitialized(); | 210 return windowProxy(DOMWrapperWorld::mainWorld())->isContextInitialized(); |
217 } | 211 } |
218 | 212 |
219 WindowProxy* ScriptController::existingWindowProxy(DOMWrapperWorld& world) | 213 WindowProxy* ScriptController::existingWindowProxy(DOMWrapperWorld& world) |
220 { | 214 { |
221 if (world.isMainWorld()) | 215 return m_windowProxyManager->existingWindowProxy(world); |
222 return m_windowProxy->isContextInitialized() ? m_windowProxy.get() : 0; | |
223 | |
224 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId()); | |
225 if (iter == m_isolatedWorlds.end()) | |
226 return 0; | |
227 return iter->value->isContextInitialized() ? iter->value.get() : 0; | |
228 } | 216 } |
229 | 217 |
230 WindowProxy* ScriptController::windowProxy(DOMWrapperWorld& world) | 218 WindowProxy* ScriptController::windowProxy(DOMWrapperWorld& world) |
231 { | 219 { |
232 WindowProxy* windowProxy = nullptr; | 220 WindowProxy* windowProxy = m_windowProxyManager->windowProxy(world); |
233 if (world.isMainWorld()) { | |
234 windowProxy = m_windowProxy.get(); | |
235 } else { | |
236 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId())
; | |
237 if (iter != m_isolatedWorlds.end()) { | |
238 windowProxy = iter->value.get(); | |
239 } else { | |
240 OwnPtrWillBeRawPtr<WindowProxy> isolatedWorldWindowProxy = WindowPro
xy::create(m_frame, world, m_isolate); | |
241 windowProxy = isolatedWorldWindowProxy.get(); | |
242 m_isolatedWorlds.set(world.worldId(), isolatedWorldWindowProxy.relea
se()); | |
243 } | |
244 } | |
245 if (!windowProxy->isContextInitialized() && windowProxy->initializeIfNeeded(
) && world.isMainWorld()) | 221 if (!windowProxy->isContextInitialized() && windowProxy->initializeIfNeeded(
) && world.isMainWorld()) |
246 m_frame->loader().dispatchDidClearWindowObjectInMainWorld(); | 222 frame()->loader().dispatchDidClearWindowObjectInMainWorld(); |
| 223 // FIXME: There are some situations where we can return an uninitialized |
| 224 // context. This is broken. |
247 return windowProxy; | 225 return windowProxy; |
248 } | 226 } |
249 | 227 |
250 bool ScriptController::shouldBypassMainWorldCSP() | 228 bool ScriptController::shouldBypassMainWorldCSP() |
251 { | 229 { |
252 v8::HandleScope handleScope(m_isolate); | 230 v8::HandleScope handleScope(isolate()); |
253 v8::Handle<v8::Context> context = m_isolate->GetCurrentContext(); | 231 v8::Handle<v8::Context> context = isolate()->GetCurrentContext(); |
254 if (context.IsEmpty() || !toDOMWindow(context)) | 232 if (context.IsEmpty() || !toDOMWindow(context)) |
255 return false; | 233 return false; |
256 DOMWrapperWorld& world = DOMWrapperWorld::current(m_isolate); | 234 DOMWrapperWorld& world = DOMWrapperWorld::current(isolate()); |
257 return world.isIsolatedWorld() ? world.isolatedWorldHasContentSecurityPolicy
() : false; | 235 return world.isIsolatedWorld() ? world.isolatedWorldHasContentSecurityPolicy
() : false; |
258 } | 236 } |
259 | 237 |
260 TextPosition ScriptController::eventHandlerPosition() const | 238 TextPosition ScriptController::eventHandlerPosition() const |
261 { | 239 { |
262 ScriptableDocumentParser* parser = m_frame->document()->scriptableDocumentPa
rser(); | 240 ScriptableDocumentParser* parser = frame()->document()->scriptableDocumentPa
rser(); |
263 if (parser) | 241 if (parser) |
264 return parser->textPosition(); | 242 return parser->textPosition(); |
265 return TextPosition::minimumPosition(); | 243 return TextPosition::minimumPosition(); |
266 } | 244 } |
267 | 245 |
268 // Create a V8 object with an interceptor of NPObjectPropertyGetter. | 246 // Create a V8 object with an interceptor of NPObjectPropertyGetter. |
269 void ScriptController::bindToWindowObject(LocalFrame* frame, const String& key,
NPObject* object) | 247 void ScriptController::bindToWindowObject(LocalFrame* frame, const String& key,
NPObject* object) |
270 { | 248 { |
271 ScriptState* scriptState = ScriptState::forMainWorld(frame); | 249 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
272 if (!scriptState->contextIsValid()) | 250 if (!scriptState->contextIsValid()) |
273 return; | 251 return; |
274 | 252 |
275 ScriptState::Scope scope(scriptState); | 253 ScriptState::Scope scope(scriptState); |
276 v8::Handle<v8::Object> value = createV8ObjectForNPObject(m_isolate, object,
0); | 254 v8::Handle<v8::Object> value = createV8ObjectForNPObject(isolate(), object,
0); |
277 | 255 |
278 // Attach to the global object. | 256 // Attach to the global object. |
279 scriptState->context()->Global()->Set(v8String(m_isolate, key), value); | 257 scriptState->context()->Global()->Set(v8String(isolate(), key), value); |
280 } | 258 } |
281 | 259 |
282 void ScriptController::enableEval() | 260 void ScriptController::enableEval() |
283 { | 261 { |
284 if (!m_windowProxy->isContextInitialized()) | 262 if (!m_windowProxyManager->mainWorldProxy()->isContextInitialized()) |
285 return; | 263 return; |
286 v8::HandleScope handleScope(m_isolate); | 264 v8::HandleScope handleScope(isolate()); |
287 m_windowProxy->context()->AllowCodeGenerationFromStrings(true); | 265 m_windowProxyManager->mainWorldProxy()->context()->AllowCodeGenerationFromSt
rings(true); |
288 } | 266 } |
289 | 267 |
290 void ScriptController::disableEval(const String& errorMessage) | 268 void ScriptController::disableEval(const String& errorMessage) |
291 { | 269 { |
292 if (!m_windowProxy->isContextInitialized()) | 270 if (!m_windowProxyManager->mainWorldProxy()->isContextInitialized()) |
293 return; | 271 return; |
294 v8::HandleScope handleScope(m_isolate); | 272 v8::HandleScope handleScope(isolate()); |
295 v8::Local<v8::Context> v8Context = m_windowProxy->context(); | 273 v8::Local<v8::Context> v8Context = m_windowProxyManager->mainWorldProxy()->c
ontext(); |
296 v8Context->AllowCodeGenerationFromStrings(false); | 274 v8Context->AllowCodeGenerationFromStrings(false); |
297 v8Context->SetErrorMessageForCodeGenerationFromStrings(v8String(m_isolate, e
rrorMessage)); | 275 v8Context->SetErrorMessageForCodeGenerationFromStrings(v8String(isolate(), e
rrorMessage)); |
298 } | 276 } |
299 | 277 |
300 PassRefPtr<SharedPersistent<v8::Object> > ScriptController::createPluginWrapper(
Widget* widget) | 278 PassRefPtr<SharedPersistent<v8::Object> > ScriptController::createPluginWrapper(
Widget* widget) |
301 { | 279 { |
302 ASSERT(widget); | 280 ASSERT(widget); |
303 | 281 |
304 if (!widget->isPluginView()) | 282 if (!widget->isPluginView()) |
305 return nullptr; | 283 return nullptr; |
306 | 284 |
307 v8::HandleScope handleScope(m_isolate); | 285 v8::HandleScope handleScope(isolate()); |
308 v8::Local<v8::Object> scriptableObject = toPluginView(widget)->scriptableObj
ect(m_isolate); | 286 v8::Local<v8::Object> scriptableObject = toPluginView(widget)->scriptableObj
ect(isolate()); |
309 | 287 |
310 if (scriptableObject.IsEmpty()) | 288 if (scriptableObject.IsEmpty()) |
311 return nullptr; | 289 return nullptr; |
312 | 290 |
313 // LocalFrame Memory Management for NPObjects | 291 // LocalFrame Memory Management for NPObjects |
314 // ------------------------------------- | 292 // ------------------------------------- |
315 // NPObjects are treated differently than other objects wrapped by JS. | 293 // NPObjects are treated differently than other objects wrapped by JS. |
316 // NPObjects can be created either by the browser (e.g. the main | 294 // NPObjects can be created either by the browser (e.g. the main |
317 // window object) or by the plugin (the main plugin object | 295 // window object) or by the plugin (the main plugin object |
318 // for a HTMLEmbedElement). Further, unlike most DOM Objects, the frame | 296 // for a HTMLEmbedElement). Further, unlike most DOM Objects, the frame |
(...skipping 13 matching lines...) Expand all Loading... |
332 // | 310 // |
333 // Inside the javascript engine, the engine can keep a reference to the | 311 // Inside the javascript engine, the engine can keep a reference to the |
334 // NPObject as part of its wrapper. However, before accessing the object | 312 // NPObject as part of its wrapper. However, before accessing the object |
335 // it must consult the _NPN_Registry. | 313 // it must consult the _NPN_Registry. |
336 | 314 |
337 if (isWrappedNPObject(scriptableObject)) { | 315 if (isWrappedNPObject(scriptableObject)) { |
338 // Track the plugin object. We've been given a reference to the object. | 316 // Track the plugin object. We've been given a reference to the object. |
339 m_pluginObjects.set(widget, v8ObjectToNPObject(scriptableObject)); | 317 m_pluginObjects.set(widget, v8ObjectToNPObject(scriptableObject)); |
340 } | 318 } |
341 | 319 |
342 return SharedPersistent<v8::Object>::create(scriptableObject, m_isolate); | 320 return SharedPersistent<v8::Object>::create(scriptableObject, isolate()); |
343 } | 321 } |
344 | 322 |
345 void ScriptController::cleanupScriptObjectsForPlugin(Widget* nativeHandle) | 323 void ScriptController::cleanupScriptObjectsForPlugin(Widget* nativeHandle) |
346 { | 324 { |
347 PluginObjectMap::iterator it = m_pluginObjects.find(nativeHandle); | 325 PluginObjectMap::iterator it = m_pluginObjects.find(nativeHandle); |
348 if (it == m_pluginObjects.end()) | 326 if (it == m_pluginObjects.end()) |
349 return; | 327 return; |
350 _NPN_UnregisterObject(it->value); | 328 _NPN_UnregisterObject(it->value); |
351 _NPN_ReleaseObject(it->value); | 329 _NPN_ReleaseObject(it->value); |
352 m_pluginObjects.remove(it); | 330 m_pluginObjects.remove(it); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 } | 367 } |
390 | 368 |
391 NPObject* ScriptController::windowScriptNPObject() | 369 NPObject* ScriptController::windowScriptNPObject() |
392 { | 370 { |
393 if (m_windowScriptNPObject) | 371 if (m_windowScriptNPObject) |
394 return m_windowScriptNPObject; | 372 return m_windowScriptNPObject; |
395 | 373 |
396 if (canExecuteScripts(NotAboutToExecuteScript)) { | 374 if (canExecuteScripts(NotAboutToExecuteScript)) { |
397 // JavaScript is enabled, so there is a JavaScript window object. | 375 // JavaScript is enabled, so there is a JavaScript window object. |
398 // Return an NPObject bound to the window object. | 376 // Return an NPObject bound to the window object. |
399 m_windowScriptNPObject = createScriptObject(m_frame, m_isolate); | 377 m_windowScriptNPObject = createScriptObject(frame(), isolate()); |
400 _NPN_RegisterObject(m_windowScriptNPObject, 0); | 378 _NPN_RegisterObject(m_windowScriptNPObject, 0); |
401 } else { | 379 } else { |
402 // JavaScript is not enabled, so we cannot bind the NPObject to the | 380 // JavaScript is not enabled, so we cannot bind the NPObject to the |
403 // JavaScript window object. Instead, we create an NPObject of a | 381 // JavaScript window object. Instead, we create an NPObject of a |
404 // different class, one which is not bound to a JavaScript object. | 382 // different class, one which is not bound to a JavaScript object. |
405 m_windowScriptNPObject = createNoScriptObject(); | 383 m_windowScriptNPObject = createNoScriptObject(); |
406 } | 384 } |
407 return m_windowScriptNPObject; | 385 return m_windowScriptNPObject; |
408 } | 386 } |
409 | 387 |
410 NPObject* ScriptController::createScriptObjectForPluginElement(HTMLPlugInElement
* plugin) | 388 NPObject* ScriptController::createScriptObjectForPluginElement(HTMLPlugInElement
* plugin) |
411 { | 389 { |
412 // Can't create NPObjects when JavaScript is disabled. | 390 // Can't create NPObjects when JavaScript is disabled. |
413 if (!canExecuteScripts(NotAboutToExecuteScript)) | 391 if (!canExecuteScripts(NotAboutToExecuteScript)) |
414 return createNoScriptObject(); | 392 return createNoScriptObject(); |
415 | 393 |
416 ScriptState* scriptState = ScriptState::forMainWorld(m_frame); | 394 ScriptState* scriptState = ScriptState::forMainWorld(frame()); |
417 if (!scriptState->contextIsValid()) | 395 if (!scriptState->contextIsValid()) |
418 return createNoScriptObject(); | 396 return createNoScriptObject(); |
419 | 397 |
420 ScriptState::Scope scope(scriptState); | 398 ScriptState::Scope scope(scriptState); |
421 LocalDOMWindow* window = m_frame->localDOMWindow(); | 399 LocalDOMWindow* window = frame()->localDOMWindow(); |
422 v8::Handle<v8::Value> v8plugin = toV8(plugin, scriptState->context()->Global
(), scriptState->isolate()); | 400 v8::Handle<v8::Value> v8plugin = toV8(plugin, scriptState->context()->Global
(), scriptState->isolate()); |
423 if (!v8plugin->IsObject()) | 401 if (!v8plugin->IsObject()) |
424 return createNoScriptObject(); | 402 return createNoScriptObject(); |
425 | 403 |
426 return npCreateV8ScriptObject(scriptState->isolate(), 0, v8::Handle<v8::Obje
ct>::Cast(v8plugin), window); | 404 return npCreateV8ScriptObject(scriptState->isolate(), 0, v8::Handle<v8::Obje
ct>::Cast(v8plugin), window); |
427 } | 405 } |
428 | 406 |
429 void ScriptController::clearWindowProxy() | 407 void ScriptController::clearWindowProxy() |
430 { | 408 { |
431 double start = currentTime(); | |
432 // V8 binding expects ScriptController::clearWindowProxy only be called | 409 // V8 binding expects ScriptController::clearWindowProxy only be called |
433 // when a frame is loading a new page. This creates a new context for the ne
w page. | 410 // when a frame is loading a new page. This creates a new context for the ne
w page. |
434 | 411 |
| 412 double start = currentTime(); |
435 // The V8 context must be available for |clearScriptObjects()|. | 413 // The V8 context must be available for |clearScriptObjects()|. |
436 // The below call must be before |clearForNavigation()| which disposes the V
8 context. | 414 // The below call must be before |clearForNavigation()| which disposes the V
8 context. |
437 clearScriptObjects(); | 415 clearScriptObjects(); |
438 m_windowProxy->clearForNavigation(); | 416 |
439 for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin(); iter != m_i
solatedWorlds.end(); ++iter) | 417 m_windowProxyManager->clearForNavigation(); |
440 iter->value->clearForNavigation(); | |
441 blink::Platform::current()->histogramCustomCounts("WebCore.ScriptController.
clearWindowProxy", (currentTime() - start) * 1000, 0, 10000, 50); | 418 blink::Platform::current()->histogramCustomCounts("WebCore.ScriptController.
clearWindowProxy", (currentTime() - start) * 1000, 0, 10000, 50); |
442 } | 419 } |
443 | 420 |
444 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool value) | 421 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool value) |
445 { | 422 { |
446 v8::V8::SetCaptureStackTraceForUncaughtExceptions(value, ScriptCallStack::ma
xCallStackSizeToCapture, stackTraceOptions); | 423 v8::V8::SetCaptureStackTraceForUncaughtExceptions(value, ScriptCallStack::ma
xCallStackSizeToCapture, stackTraceOptions); |
447 } | 424 } |
448 | 425 |
449 void ScriptController::collectIsolatedContexts(Vector<std::pair<ScriptState*, Se
curityOrigin*> >& result) | 426 void ScriptController::collectIsolatedContexts(Vector<std::pair<ScriptState*, Se
curityOrigin*> >& result) |
450 { | 427 { |
451 for (IsolatedWorldMap::iterator it = m_isolatedWorlds.begin(); it != m_isola
tedWorlds.end(); ++it) { | 428 m_windowProxyManager->collectIsolatedContexts(result); |
452 WindowProxy* isolatedWorldWindowProxy = it->value.get(); | |
453 SecurityOrigin* origin = isolatedWorldWindowProxy->world().isolatedWorld
SecurityOrigin(); | |
454 if (!isolatedWorldWindowProxy->isContextInitialized()) | |
455 continue; | |
456 result.append(std::pair<ScriptState*, SecurityOrigin*>(isolatedWorldWind
owProxy->scriptState(), origin)); | |
457 } | |
458 } | 429 } |
459 | 430 |
460 void ScriptController::setWorldDebugId(int worldId, int debuggerId) | 431 void ScriptController::setWorldDebugId(int worldId, int debuggerId) |
461 { | 432 { |
462 ASSERT(debuggerId > 0); | 433 m_windowProxyManager->setWorldDebugId(worldId, debuggerId); |
463 bool isMainWorld = worldId == MainWorldId; | |
464 WindowProxy* windowProxy = 0; | |
465 if (isMainWorld) { | |
466 windowProxy = m_windowProxy.get(); | |
467 } else { | |
468 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(worldId); | |
469 if (iter != m_isolatedWorlds.end()) | |
470 windowProxy = iter->value.get(); | |
471 } | |
472 if (!windowProxy || !windowProxy->isContextInitialized()) | |
473 return; | |
474 v8::HandleScope scope(m_isolate); | |
475 v8::Local<v8::Context> context = windowProxy->context(); | |
476 const char* worldName = isMainWorld ? "page" : "injected"; | |
477 V8PerContextDebugData::setContextDebugData(context, worldName, debuggerId); | |
478 } | 434 } |
479 | 435 |
480 void ScriptController::updateDocument() | 436 void ScriptController::updateDocument() |
481 { | 437 { |
482 // For an uninitialized main window windowProxy, do not incur the cost of co
ntext initialization. | 438 // For an uninitialized main window windowProxy, do not incur the cost of co
ntext initialization. |
483 if (!m_windowProxy->isGlobalInitialized()) | 439 if (!m_windowProxyManager->mainWorldProxy()->isGlobalInitialized()) |
484 return; | 440 return; |
485 | 441 |
486 if (!initializeMainWorld()) | 442 if (!initializeMainWorld()) |
487 windowProxy(DOMWrapperWorld::mainWorld())->updateDocument(); | 443 windowProxy(DOMWrapperWorld::mainWorld())->updateDocument(); |
488 } | 444 } |
489 | 445 |
490 void ScriptController::namedItemAdded(HTMLDocument* doc, const AtomicString& nam
e) | 446 void ScriptController::namedItemAdded(HTMLDocument* doc, const AtomicString& nam
e) |
491 { | 447 { |
492 windowProxy(DOMWrapperWorld::mainWorld())->namedItemAdded(doc, name); | 448 windowProxy(DOMWrapperWorld::mainWorld())->namedItemAdded(doc, name); |
493 } | 449 } |
494 | 450 |
495 void ScriptController::namedItemRemoved(HTMLDocument* doc, const AtomicString& n
ame) | 451 void ScriptController::namedItemRemoved(HTMLDocument* doc, const AtomicString& n
ame) |
496 { | 452 { |
497 windowProxy(DOMWrapperWorld::mainWorld())->namedItemRemoved(doc, name); | 453 windowProxy(DOMWrapperWorld::mainWorld())->namedItemRemoved(doc, name); |
498 } | 454 } |
499 | 455 |
500 static bool isInPrivateScriptIsolateWorld(v8::Isolate* isolate) | 456 static bool isInPrivateScriptIsolateWorld(v8::Isolate* isolate) |
501 { | 457 { |
502 v8::Handle<v8::Context> context = isolate->GetCurrentContext(); | 458 v8::Handle<v8::Context> context = isolate->GetCurrentContext(); |
503 return !context.IsEmpty() && toDOMWindow(context) && DOMWrapperWorld::curren
t(isolate).isPrivateScriptIsolatedWorld(); | 459 return !context.IsEmpty() && toDOMWindow(context) && DOMWrapperWorld::curren
t(isolate).isPrivateScriptIsolatedWorld(); |
504 } | 460 } |
505 | 461 |
506 bool ScriptController::canExecuteScripts(ReasonForCallingCanExecuteScripts reaso
n) | 462 bool ScriptController::canExecuteScripts(ReasonForCallingCanExecuteScripts reaso
n) |
507 { | 463 { |
508 // For performance reasons, we check isInPrivateScriptIsolateWorld() only if | 464 // For performance reasons, we check isInPrivateScriptIsolateWorld() only if |
509 // canExecuteScripts is going to return false. | 465 // canExecuteScripts is going to return false. |
510 | 466 |
511 if (m_frame->document() && m_frame->document()->isSandboxed(SandboxScripts))
{ | 467 if (frame()->document() && frame()->document()->isSandboxed(SandboxScripts))
{ |
512 if (isInPrivateScriptIsolateWorld(m_isolate)) | 468 if (isInPrivateScriptIsolateWorld(isolate())) |
513 return true; | 469 return true; |
514 // FIXME: This message should be moved off the console once a solution t
o https://bugs.webkit.org/show_bug.cgi?id=103274 exists. | 470 // FIXME: This message should be moved off the console once a solution t
o https://bugs.webkit.org/show_bug.cgi?id=103274 exists. |
515 if (reason == AboutToExecuteScript) | 471 if (reason == AboutToExecuteScript) |
516 m_frame->document()->addConsoleMessage(ConsoleMessage::create(Securi
tyMessageSource, ErrorMessageLevel, "Blocked script execution in '" + m_frame->d
ocument()->url().elidedString() + "' because the document's frame is sandboxed a
nd the 'allow-scripts' permission is not set.")); | 472 frame()->document()->addConsoleMessage(ConsoleMessage::create(Securi
tyMessageSource, ErrorMessageLevel, "Blocked script execution in '" + frame()->d
ocument()->url().elidedString() + "' because the document's frame is sandboxed a
nd the 'allow-scripts' permission is not set.")); |
517 return false; | 473 return false; |
518 } | 474 } |
519 | 475 |
520 if (m_frame->document() && m_frame->document()->isViewSource()) { | 476 if (frame()->document() && frame()->document()->isViewSource()) { |
521 ASSERT(m_frame->document()->securityOrigin()->isUnique()); | 477 ASSERT(frame()->document()->securityOrigin()->isUnique()); |
522 return true; | 478 return true; |
523 } | 479 } |
524 | 480 |
525 FrameLoaderClient* client = m_frame->loader().client(); | 481 FrameLoaderClient* client = frame()->loader().client(); |
526 if (!client) | 482 if (!client) |
527 return false; | 483 return false; |
528 Settings* settings = m_frame->settings(); | 484 Settings* settings = frame()->settings(); |
529 const bool allowed = client->allowScript(settings && settings->scriptEnabled
()) | 485 const bool allowed = client->allowScript(settings && settings->scriptEnabled
()) |
530 || isInPrivateScriptIsolateWorld(m_isolate); | 486 || isInPrivateScriptIsolateWorld(isolate()); |
531 if (!allowed && reason == AboutToExecuteScript) | 487 if (!allowed && reason == AboutToExecuteScript) |
532 client->didNotAllowScript(); | 488 client->didNotAllowScript(); |
533 return allowed; | 489 return allowed; |
534 } | 490 } |
535 | 491 |
536 bool ScriptController::executeScriptIfJavaScriptURL(const KURL& url) | 492 bool ScriptController::executeScriptIfJavaScriptURL(const KURL& url) |
537 { | 493 { |
538 if (!protocolIsJavaScript(url)) | 494 if (!protocolIsJavaScript(url)) |
539 return false; | 495 return false; |
540 | 496 |
541 bool shouldBypassMainWorldContentSecurityPolicy = ContentSecurityPolicy::sho
uldBypassMainWorld(m_frame->document()); | 497 bool shouldBypassMainWorldContentSecurityPolicy = ContentSecurityPolicy::sho
uldBypassMainWorld(frame()->document()); |
542 if (!m_frame->page() | 498 if (!frame()->page() |
543 || (!shouldBypassMainWorldContentSecurityPolicy && !m_frame->document()-
>contentSecurityPolicy()->allowJavaScriptURLs(m_frame->document()->url(), eventH
andlerPosition().m_line))) | 499 || (!shouldBypassMainWorldContentSecurityPolicy && !frame()->document()-
>contentSecurityPolicy()->allowJavaScriptURLs(frame()->document()->url(), eventH
andlerPosition().m_line))) |
544 return true; | 500 return true; |
545 | 501 |
546 if (m_frame->loader().stateMachine()->isDisplayingInitialEmptyDocument()) | 502 if (frame()->loader().stateMachine()->isDisplayingInitialEmptyDocument()) |
547 m_frame->loader().progress().progressStarted(); | 503 frame()->loader().progress().progressStarted(); |
548 | 504 |
549 // We need to hold onto the LocalFrame here because executing script can | 505 // We need to hold onto the LocalFrame here because executing script can |
550 // destroy the frame. | 506 // destroy the frame. |
551 RefPtrWillBeRawPtr<LocalFrame> protect(m_frame.get()); | 507 RefPtrWillBeRawPtr<LocalFrame> protect(frame()); |
552 RefPtrWillBeRawPtr<Document> ownerDocument(m_frame->document()); | 508 RefPtrWillBeRawPtr<Document> ownerDocument(frame()->document()); |
553 | 509 |
554 const int javascriptSchemeLength = sizeof("javascript:") - 1; | 510 const int javascriptSchemeLength = sizeof("javascript:") - 1; |
555 | 511 |
556 bool locationChangeBefore = m_frame->navigationScheduler().locationChangePen
ding(); | 512 bool locationChangeBefore = frame()->navigationScheduler().locationChangePen
ding(); |
557 | 513 |
558 String decodedURL = decodeURLEscapeSequences(url.string()); | 514 String decodedURL = decodeURLEscapeSequences(url.string()); |
559 v8::HandleScope handleScope(m_isolate); | 515 v8::HandleScope handleScope(isolate()); |
560 v8::Local<v8::Value> result = evaluateScriptInMainWorld(ScriptSourceCode(dec
odedURL.substring(javascriptSchemeLength)), NotSharableCrossOrigin, DoNotExecute
ScriptWhenScriptsDisabled); | 516 v8::Local<v8::Value> result = evaluateScriptInMainWorld(ScriptSourceCode(dec
odedURL.substring(javascriptSchemeLength)), NotSharableCrossOrigin, DoNotExecute
ScriptWhenScriptsDisabled); |
561 | 517 |
562 // If executing script caused this frame to be removed from the page, we | 518 // If executing script caused this frame to be removed from the page, we |
563 // don't want to try to replace its document! | 519 // don't want to try to replace its document! |
564 if (!m_frame->page()) | 520 if (!frame()->page()) |
565 return true; | 521 return true; |
566 | 522 |
567 if (result.IsEmpty() || !result->IsString()) | 523 if (result.IsEmpty() || !result->IsString()) |
568 return true; | 524 return true; |
569 String scriptResult = toCoreString(v8::Handle<v8::String>::Cast(result)); | 525 String scriptResult = toCoreString(v8::Handle<v8::String>::Cast(result)); |
570 | 526 |
571 // We're still in a frame, so there should be a DocumentLoader. | 527 // We're still in a frame, so there should be a DocumentLoader. |
572 ASSERT(m_frame->document()->loader()); | 528 ASSERT(frame()->document()->loader()); |
573 if (!locationChangeBefore && m_frame->navigationScheduler().locationChangePe
nding()) | 529 if (!locationChangeBefore && frame()->navigationScheduler().locationChangePe
nding()) |
574 return true; | 530 return true; |
575 | 531 |
576 m_frame->loader().replaceDocumentWhileExecutingJavaScriptURL(scriptResult, o
wnerDocument.get()); | 532 frame()->loader().replaceDocumentWhileExecutingJavaScriptURL(scriptResult, o
wnerDocument.get()); |
577 return true; | 533 return true; |
578 } | 534 } |
579 | 535 |
580 void ScriptController::executeScriptInMainWorld(const String& script, ExecuteScr
iptPolicy policy) | 536 void ScriptController::executeScriptInMainWorld(const String& script, ExecuteScr
iptPolicy policy) |
581 { | 537 { |
582 v8::HandleScope handleScope(m_isolate); | 538 v8::HandleScope handleScope(isolate()); |
583 evaluateScriptInMainWorld(ScriptSourceCode(script), NotSharableCrossOrigin,
policy); | 539 evaluateScriptInMainWorld(ScriptSourceCode(script), NotSharableCrossOrigin,
policy); |
584 } | 540 } |
585 | 541 |
586 void ScriptController::executeScriptInMainWorld(const ScriptSourceCode& sourceCo
de, AccessControlStatus corsStatus, double* compilationFinishTime) | 542 void ScriptController::executeScriptInMainWorld(const ScriptSourceCode& sourceCo
de, AccessControlStatus corsStatus, double* compilationFinishTime) |
587 { | 543 { |
588 v8::HandleScope handleScope(m_isolate); | 544 v8::HandleScope handleScope(isolate()); |
589 evaluateScriptInMainWorld(sourceCode, corsStatus, DoNotExecuteScriptWhenScri
ptsDisabled, compilationFinishTime); | 545 evaluateScriptInMainWorld(sourceCode, corsStatus, DoNotExecuteScriptWhenScri
ptsDisabled, compilationFinishTime); |
590 } | 546 } |
591 | 547 |
592 v8::Local<v8::Value> ScriptController::executeScriptInMainWorldAndReturnValue(co
nst ScriptSourceCode& sourceCode) | 548 v8::Local<v8::Value> ScriptController::executeScriptInMainWorldAndReturnValue(co
nst ScriptSourceCode& sourceCode) |
593 { | 549 { |
594 return evaluateScriptInMainWorld(sourceCode, NotSharableCrossOrigin, DoNotEx
ecuteScriptWhenScriptsDisabled); | 550 return evaluateScriptInMainWorld(sourceCode, NotSharableCrossOrigin, DoNotEx
ecuteScriptWhenScriptsDisabled); |
595 } | 551 } |
596 | 552 |
597 v8::Local<v8::Value> ScriptController::evaluateScriptInMainWorld(const ScriptSou
rceCode& sourceCode, AccessControlStatus corsStatus, ExecuteScriptPolicy policy,
double* compilationFinishTime) | 553 v8::Local<v8::Value> ScriptController::evaluateScriptInMainWorld(const ScriptSou
rceCode& sourceCode, AccessControlStatus corsStatus, ExecuteScriptPolicy policy,
double* compilationFinishTime) |
598 { | 554 { |
599 if (policy == DoNotExecuteScriptWhenScriptsDisabled && !canExecuteScripts(Ab
outToExecuteScript)) | 555 if (policy == DoNotExecuteScriptWhenScriptsDisabled && !canExecuteScripts(Ab
outToExecuteScript)) |
600 return v8::Local<v8::Value>(); | 556 return v8::Local<v8::Value>(); |
601 | 557 |
602 String sourceURL = sourceCode.url(); | 558 String sourceURL = sourceCode.url(); |
603 const String* savedSourceURL = m_sourceURL; | 559 const String* savedSourceURL = m_sourceURL; |
604 m_sourceURL = &sourceURL; | 560 m_sourceURL = &sourceURL; |
605 | 561 |
606 v8::EscapableHandleScope handleScope(m_isolate); | 562 v8::EscapableHandleScope handleScope(isolate()); |
607 v8::Handle<v8::Context> context = toV8Context(m_frame, DOMWrapperWorld::main
World()); | 563 v8::Handle<v8::Context> context = toV8Context(frame(), DOMWrapperWorld::main
World()); |
608 if (context.IsEmpty()) | 564 if (context.IsEmpty()) |
609 return v8::Local<v8::Value>(); | 565 return v8::Local<v8::Value>(); |
610 | 566 |
611 ScriptState* scriptState = ScriptState::from(context); | 567 ScriptState* scriptState = ScriptState::from(context); |
612 ScriptState::Scope scope(scriptState); | 568 ScriptState::Scope scope(scriptState); |
613 | 569 |
614 RefPtrWillBeRawPtr<LocalFrame> protect(m_frame.get()); | 570 RefPtrWillBeRawPtr<LocalFrame> protect(frame()); |
615 if (m_frame->loader().stateMachine()->isDisplayingInitialEmptyDocument()) | 571 if (frame()->loader().stateMachine()->isDisplayingInitialEmptyDocument()) |
616 m_frame->loader().didAccessInitialDocument(); | 572 frame()->loader().didAccessInitialDocument(); |
617 | 573 |
618 OwnPtr<ScriptSourceCode> maybeProcessedSourceCode = InspectorInstrumentatio
n::preprocess(m_frame, sourceCode); | 574 OwnPtr<ScriptSourceCode> maybeProcessedSourceCode = InspectorInstrumentatio
n::preprocess(frame(), sourceCode); |
619 const ScriptSourceCode& sourceCodeToCompile = maybeProcessedSourceCode ? *ma
ybeProcessedSourceCode : sourceCode; | 575 const ScriptSourceCode& sourceCodeToCompile = maybeProcessedSourceCode ? *ma
ybeProcessedSourceCode : sourceCode; |
620 | 576 |
621 v8::Local<v8::Value> object = executeScriptAndReturnValue(scriptState->conte
xt(), sourceCodeToCompile, corsStatus, compilationFinishTime); | 577 v8::Local<v8::Value> object = executeScriptAndReturnValue(scriptState->conte
xt(), sourceCodeToCompile, corsStatus, compilationFinishTime); |
622 m_sourceURL = savedSourceURL; | 578 m_sourceURL = savedSourceURL; |
623 | 579 |
624 if (object.IsEmpty()) | 580 if (object.IsEmpty()) |
625 return v8::Local<v8::Value>(); | 581 return v8::Local<v8::Value>(); |
626 | 582 |
627 return handleScope.Escape(object); | 583 return handleScope.Escape(object); |
628 } | 584 } |
629 | 585 |
630 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc
riptSourceCode>& sources, int extensionGroup, Vector<v8::Local<v8::Value> >* res
ults) | 586 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc
riptSourceCode>& sources, int extensionGroup, Vector<v8::Local<v8::Value> >* res
ults) |
631 { | 587 { |
632 ASSERT(worldID > 0); | 588 ASSERT(worldID > 0); |
633 | 589 |
634 RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(m_isola
te, worldID, extensionGroup); | 590 RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(isolate
(), worldID, extensionGroup); |
635 WindowProxy* isolatedWorldWindowProxy = windowProxy(*world); | 591 WindowProxy* isolatedWorldWindowProxy = windowProxy(*world); |
636 if (!isolatedWorldWindowProxy->isContextInitialized()) | 592 if (!isolatedWorldWindowProxy->isContextInitialized()) |
637 return; | 593 return; |
638 | 594 |
639 ScriptState* scriptState = isolatedWorldWindowProxy->scriptState(); | 595 ScriptState* scriptState = isolatedWorldWindowProxy->scriptState(); |
640 v8::Context::Scope scope(scriptState->context()); | 596 v8::Context::Scope scope(scriptState->context()); |
641 v8::Local<v8::Array> resultArray = v8::Array::New(m_isolate, sources.size())
; | 597 v8::Local<v8::Array> resultArray = v8::Array::New(isolate(), sources.size())
; |
642 | 598 |
643 for (size_t i = 0; i < sources.size(); ++i) { | 599 for (size_t i = 0; i < sources.size(); ++i) { |
644 v8::Local<v8::Value> evaluationResult = executeScriptAndReturnValue(scri
ptState->context(), sources[i]); | 600 v8::Local<v8::Value> evaluationResult = executeScriptAndReturnValue(scri
ptState->context(), sources[i]); |
645 if (evaluationResult.IsEmpty()) | 601 if (evaluationResult.IsEmpty()) |
646 evaluationResult = v8::Local<v8::Value>::New(m_isolate, v8::Undefine
d(m_isolate)); | 602 evaluationResult = v8::Local<v8::Value>::New(isolate(), v8::Undefine
d(isolate())); |
647 resultArray->Set(i, evaluationResult); | 603 resultArray->Set(i, evaluationResult); |
648 } | 604 } |
649 | 605 |
650 if (results) { | 606 if (results) { |
651 for (size_t i = 0; i < resultArray->Length(); ++i) | 607 for (size_t i = 0; i < resultArray->Length(); ++i) |
652 results->append(resultArray->Get(i)); | 608 results->append(resultArray->Get(i)); |
653 } | 609 } |
654 } | 610 } |
655 | 611 |
656 } // namespace blink | 612 } // namespace blink |
OLD | NEW |