OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2007-2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2007-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 14 matching lines...) Expand all Loading... | |
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 "config.h" | 31 #include "config.h" |
32 #include "V8InjectedScriptHost.h" | 32 #include "V8InjectedScriptHost.h" |
33 | 33 |
34 #include "V8Database.h" | 34 #include "V8Database.h" |
35 #include "V8EventTarget.h" | |
35 #include "V8HTMLAllCollection.h" | 36 #include "V8HTMLAllCollection.h" |
36 #include "V8HTMLCollection.h" | 37 #include "V8HTMLCollection.h" |
37 #include "V8Node.h" | 38 #include "V8Node.h" |
38 #include "V8NodeList.h" | 39 #include "V8NodeList.h" |
39 #include "V8Storage.h" | 40 #include "V8Storage.h" |
41 #include "V8Window.h" | |
40 #include "bindings/v8/BindingSecurity.h" | 42 #include "bindings/v8/BindingSecurity.h" |
41 #include "bindings/v8/ExceptionState.h" | 43 #include "bindings/v8/ExceptionState.h" |
42 #include "bindings/v8/ScriptDebugServer.h" | 44 #include "bindings/v8/ScriptDebugServer.h" |
43 #include "bindings/v8/ScriptValue.h" | 45 #include "bindings/v8/ScriptValue.h" |
44 #include "bindings/v8/V8AbstractEventListener.h" | 46 #include "bindings/v8/V8AbstractEventListener.h" |
45 #include "bindings/v8/V8Binding.h" | 47 #include "bindings/v8/V8Binding.h" |
48 #include "bindings/v8/V8DOMWrapper.h" | |
46 #include "bindings/v8/V8HiddenPropertyName.h" | 49 #include "bindings/v8/V8HiddenPropertyName.h" |
47 #include "bindings/v8/V8ScriptRunner.h" | 50 #include "bindings/v8/V8ScriptRunner.h" |
48 #include "bindings/v8/custom/V8Float32ArrayCustom.h" | 51 #include "bindings/v8/custom/V8Float32ArrayCustom.h" |
49 #include "bindings/v8/custom/V8Float64ArrayCustom.h" | 52 #include "bindings/v8/custom/V8Float64ArrayCustom.h" |
50 #include "bindings/v8/custom/V8Int16ArrayCustom.h" | 53 #include "bindings/v8/custom/V8Int16ArrayCustom.h" |
51 #include "bindings/v8/custom/V8Int32ArrayCustom.h" | 54 #include "bindings/v8/custom/V8Int32ArrayCustom.h" |
52 #include "bindings/v8/custom/V8Int8ArrayCustom.h" | 55 #include "bindings/v8/custom/V8Int8ArrayCustom.h" |
53 #include "bindings/v8/custom/V8Uint16ArrayCustom.h" | 56 #include "bindings/v8/custom/V8Uint16ArrayCustom.h" |
54 #include "bindings/v8/custom/V8Uint32ArrayCustom.h" | 57 #include "bindings/v8/custom/V8Uint32ArrayCustom.h" |
55 #include "bindings/v8/custom/V8Uint8ArrayCustom.h" | 58 #include "bindings/v8/custom/V8Uint8ArrayCustom.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 if (info.Length() < 1) | 237 if (info.Length() < 1) |
235 return; | 238 return; |
236 | 239 |
237 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(info[0]); | 240 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(info[0]); |
238 | 241 |
239 InjectedScriptHost* host = V8InjectedScriptHost::toNative(info.Holder()); | 242 InjectedScriptHost* host = V8InjectedScriptHost::toNative(info.Holder()); |
240 ScriptDebugServer& debugServer = host->scriptDebugServer(); | 243 ScriptDebugServer& debugServer = host->scriptDebugServer(); |
241 v8SetReturnValue(info, debugServer.getInternalProperties(object)); | 244 v8SetReturnValue(info, debugServer.getInternalProperties(object)); |
242 } | 245 } |
243 | 246 |
244 static v8::Handle<v8::Array> getJSListenerFunctions(Document* document, const Ev entListenerInfo& listenerInfo, v8::Isolate* isolate) | 247 static v8::Handle<v8::Array> getJSListenerFunctions(ExecutionContext* executionC ontext, const EventListenerInfo& listenerInfo, v8::Isolate* isolate) |
245 { | 248 { |
246 v8::Local<v8::Array> result = v8::Array::New(isolate); | 249 v8::Local<v8::Array> result = v8::Array::New(isolate); |
247 size_t handlersCount = listenerInfo.eventListenerVector.size(); | 250 size_t handlersCount = listenerInfo.eventListenerVector.size(); |
248 for (size_t i = 0, outputIndex = 0; i < handlersCount; ++i) { | 251 for (size_t i = 0, outputIndex = 0; i < handlersCount; ++i) { |
249 RefPtr<EventListener> listener = listenerInfo.eventListenerVector[i].lis tener; | 252 RefPtr<EventListener> listener = listenerInfo.eventListenerVector[i].lis tener; |
250 if (listener->type() != EventListener::JSEventListenerType) { | 253 if (listener->type() != EventListener::JSEventListenerType) { |
251 ASSERT_NOT_REACHED(); | 254 ASSERT_NOT_REACHED(); |
252 continue; | 255 continue; |
253 } | 256 } |
254 V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListene r*>(listener.get()); | 257 V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListene r*>(listener.get()); |
255 v8::Local<v8::Context> context = toV8Context(document, v8Listener->world ()); | 258 v8::Local<v8::Context> context = toV8Context(executionContext, v8Listene r->world()); |
256 // Hide listeners from other contexts. | 259 // Hide listeners from other contexts. |
257 if (context != isolate->GetCurrentContext()) | 260 if (context != isolate->GetCurrentContext()) |
258 continue; | 261 continue; |
259 v8::Local<v8::Object> function; | 262 v8::Local<v8::Object> function; |
260 { | 263 { |
261 // getListenerObject() may cause JS in the event attribute to get co mpiled, potentially unsuccessfully. | 264 // getListenerObject() may cause JS in the event attribute to get co mpiled, potentially unsuccessfully. |
262 v8::TryCatch block; | 265 v8::TryCatch block; |
263 function = v8Listener->getListenerObject(document); | 266 function = v8Listener->getListenerObject(executionContext); |
264 if (block.HasCaught()) | 267 if (block.HasCaught()) |
265 continue; | 268 continue; |
266 } | 269 } |
267 ASSERT(!function.IsEmpty()); | 270 ASSERT(!function.IsEmpty()); |
268 v8::Local<v8::Object> listenerEntry = v8::Object::New(isolate); | 271 v8::Local<v8::Object> listenerEntry = v8::Object::New(isolate); |
269 listenerEntry->Set(v8AtomicString(isolate, "listener"), function); | 272 listenerEntry->Set(v8AtomicString(isolate, "listener"), function); |
270 listenerEntry->Set(v8AtomicString(isolate, "useCapture"), v8::Boolean::N ew(isolate, listenerInfo.eventListenerVector[i].useCapture)); | 273 listenerEntry->Set(v8AtomicString(isolate, "useCapture"), v8::Boolean::N ew(isolate, listenerInfo.eventListenerVector[i].useCapture)); |
271 result->Set(v8::Number::New(isolate, outputIndex++), listenerEntry); | 274 result->Set(v8::Number::New(isolate, outputIndex++), listenerEntry); |
272 } | 275 } |
273 return result; | 276 return result; |
274 } | 277 } |
275 | 278 |
276 void V8InjectedScriptHost::getEventListenersMethodCustom(const v8::FunctionCallb ackInfo<v8::Value>& info) | 279 void V8InjectedScriptHost::getEventListenersMethodCustom(const v8::FunctionCallb ackInfo<v8::Value>& info) |
277 { | 280 { |
278 if (info.Length() < 1) | 281 if (info.Length() < 1) |
279 return; | 282 return; |
280 | 283 |
284 EventTarget* target = 0; | |
281 v8::Local<v8::Value> value = info[0]; | 285 v8::Local<v8::Value> value = info[0]; |
282 if (!V8Node::hasInstance(value, info.GetIsolate(), worldType(info.GetIsolate ()))) | 286 |
283 return; | 287 if (V8EventTarget::hasInstance(value, info.GetIsolate(), worldType(info.GetI solate()))) |
284 Node* node = V8Node::toNative(value->ToObject()); | 288 target = V8EventTarget::toNative(value->ToObject()); |
285 if (!node) | 289 |
290 // We need to handle a DOMWindow specially, because a DOMWindow wrapper exis ts on a prototype chain. | |
291 if (!target && value->IsObject()) { | |
292 v8::Handle<v8::Object> wrapper = v8::Handle<v8::Object>::Cast(value); | |
293 v8::Handle<v8::Object> window = wrapper->FindInstanceInPrototypeChain(V8 Window::domTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate())) ); | |
yurys
2014/01/23 15:45:49
What if it is called on Worker thread? If it's sup
aandrey
2014/01/24 05:55:29
Done.
| |
294 if (!window.IsEmpty()) | |
295 target = toWrapperTypeInfo(window)->toEventTarget(window); | |
296 } | |
297 | |
298 if (!target && V8DOMWrapper::isDOMWrapper(value)) { | |
299 v8::Handle<v8::Object> wrapper = v8::Handle<v8::Object>::Cast(value); | |
300 target = toWrapperTypeInfo(wrapper)->toEventTarget(wrapper); | |
301 } | |
302 | |
303 if (!target || !target->executionContext()) | |
286 return; | 304 return; |
287 | 305 |
288 InjectedScriptHost* host = V8InjectedScriptHost::toNative(info.Holder()); | 306 InjectedScriptHost* host = V8InjectedScriptHost::toNative(info.Holder()); |
289 Vector<EventListenerInfo> listenersArray; | 307 Vector<EventListenerInfo> listenersArray; |
290 host->getEventListenersImpl(node, listenersArray); | 308 host->getEventListenersImpl(target, listenersArray); |
291 | 309 |
292 v8::Local<v8::Object> result = v8::Object::New(info.GetIsolate()); | 310 v8::Local<v8::Object> result = v8::Object::New(info.GetIsolate()); |
293 for (size_t i = 0; i < listenersArray.size(); ++i) { | 311 for (size_t i = 0; i < listenersArray.size(); ++i) { |
294 v8::Handle<v8::Array> listeners = getJSListenerFunctions(&node->document (), listenersArray[i], info.GetIsolate()); | 312 v8::Handle<v8::Array> listeners = getJSListenerFunctions(target->executi onContext(), listenersArray[i], info.GetIsolate()); |
295 if (!listeners->Length()) | 313 if (!listeners->Length()) |
296 continue; | 314 continue; |
297 AtomicString eventType = listenersArray[i].eventType; | 315 AtomicString eventType = listenersArray[i].eventType; |
298 result->Set(v8String(info.GetIsolate(), eventType), listeners); | 316 result->Set(v8String(info.GetIsolate(), eventType), listeners); |
299 } | 317 } |
300 | 318 |
301 v8SetReturnValue(info, result); | 319 v8SetReturnValue(info, result); |
302 } | 320 } |
303 | 321 |
304 void V8InjectedScriptHost::inspectMethodCustom(const v8::FunctionCallbackInfo<v8 ::Value>& info) | 322 void V8InjectedScriptHost::inspectMethodCustom(const v8::FunctionCallbackInfo<v8 ::Value>& info) |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
439 int lineNumber; | 457 int lineNumber; |
440 int columnNumber; | 458 int columnNumber; |
441 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) | 459 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) |
442 return; | 460 return; |
443 | 461 |
444 InjectedScriptHost* host = V8InjectedScriptHost::toNative(info.Holder()); | 462 InjectedScriptHost* host = V8InjectedScriptHost::toNative(info.Holder()); |
445 host->unmonitorFunction(scriptId, lineNumber, columnNumber); | 463 host->unmonitorFunction(scriptId, lineNumber, columnNumber); |
446 } | 464 } |
447 | 465 |
448 } // namespace WebCore | 466 } // namespace WebCore |
OLD | NEW |