| 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" |
| 40 #include "bindings/v8/BindingSecurity.h" | 41 #include "bindings/v8/BindingSecurity.h" |
| 41 #include "bindings/v8/ExceptionState.h" | 42 #include "bindings/v8/ExceptionState.h" |
| 42 #include "bindings/v8/ScriptDebugServer.h" | 43 #include "bindings/v8/ScriptDebugServer.h" |
| 43 #include "bindings/v8/ScriptValue.h" | 44 #include "bindings/v8/ScriptValue.h" |
| 44 #include "bindings/v8/V8AbstractEventListener.h" | 45 #include "bindings/v8/V8AbstractEventListener.h" |
| 45 #include "bindings/v8/V8Binding.h" | 46 #include "bindings/v8/V8Binding.h" |
| 46 #include "bindings/v8/V8HiddenPropertyName.h" | 47 #include "bindings/v8/V8HiddenPropertyName.h" |
| 47 #include "bindings/v8/V8ScriptRunner.h" | 48 #include "bindings/v8/V8ScriptRunner.h" |
| 48 #include "bindings/v8/custom/V8Float32ArrayCustom.h" | 49 #include "bindings/v8/custom/V8Float32ArrayCustom.h" |
| 49 #include "bindings/v8/custom/V8Float64ArrayCustom.h" | 50 #include "bindings/v8/custom/V8Float64ArrayCustom.h" |
| 50 #include "bindings/v8/custom/V8Int16ArrayCustom.h" | 51 #include "bindings/v8/custom/V8Int16ArrayCustom.h" |
| 51 #include "bindings/v8/custom/V8Int32ArrayCustom.h" | 52 #include "bindings/v8/custom/V8Int32ArrayCustom.h" |
| 52 #include "bindings/v8/custom/V8Int8ArrayCustom.h" | 53 #include "bindings/v8/custom/V8Int8ArrayCustom.h" |
| 53 #include "bindings/v8/custom/V8Uint16ArrayCustom.h" | 54 #include "bindings/v8/custom/V8Uint16ArrayCustom.h" |
| 54 #include "bindings/v8/custom/V8Uint32ArrayCustom.h" | 55 #include "bindings/v8/custom/V8Uint32ArrayCustom.h" |
| 55 #include "bindings/v8/custom/V8Uint8ArrayCustom.h" | 56 #include "bindings/v8/custom/V8Uint8ArrayCustom.h" |
| 56 #include "bindings/v8/custom/V8Uint8ClampedArrayCustom.h" | 57 #include "bindings/v8/custom/V8Uint8ClampedArrayCustom.h" |
| 58 #include "core/events/EventTarget.h" |
| 59 #include "core/frame/DOMWindow.h" |
| 57 #include "core/inspector/InjectedScript.h" | 60 #include "core/inspector/InjectedScript.h" |
| 58 #include "core/inspector/InjectedScriptHost.h" | 61 #include "core/inspector/InjectedScriptHost.h" |
| 59 #include "core/inspector/InspectorDOMAgent.h" | 62 #include "core/inspector/InspectorDOMAgent.h" |
| 60 #include "modules/webdatabase/Database.h" | 63 #include "modules/webdatabase/Database.h" |
| 61 #include "platform/JSONValues.h" | 64 #include "platform/JSONValues.h" |
| 62 | 65 |
| 63 namespace WebCore { | 66 namespace WebCore { |
| 64 | 67 |
| 65 Node* InjectedScriptHost::scriptValueAsNode(ScriptValue value) | 68 Node* InjectedScriptHost::scriptValueAsNode(ScriptValue value) |
| 66 { | 69 { |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 if (info.Length() < 1) | 236 if (info.Length() < 1) |
| 234 return; | 237 return; |
| 235 | 238 |
| 236 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(info[0]); | 239 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(info[0]); |
| 237 | 240 |
| 238 InjectedScriptHost* host = V8InjectedScriptHost::toNative(info.Holder()); | 241 InjectedScriptHost* host = V8InjectedScriptHost::toNative(info.Holder()); |
| 239 ScriptDebugServer& debugServer = host->scriptDebugServer(); | 242 ScriptDebugServer& debugServer = host->scriptDebugServer(); |
| 240 v8SetReturnValue(info, debugServer.getInternalProperties(object)); | 243 v8SetReturnValue(info, debugServer.getInternalProperties(object)); |
| 241 } | 244 } |
| 242 | 245 |
| 243 static v8::Handle<v8::Array> getJSListenerFunctions(Document* document, const Ev
entListenerInfo& listenerInfo, v8::Isolate* isolate) | 246 static v8::Handle<v8::Array> getJSListenerFunctions(ExecutionContext* executionC
ontext, const EventListenerInfo& listenerInfo, v8::Isolate* isolate) |
| 244 { | 247 { |
| 245 v8::Local<v8::Array> result = v8::Array::New(isolate); | 248 v8::Local<v8::Array> result = v8::Array::New(isolate); |
| 246 size_t handlersCount = listenerInfo.eventListenerVector.size(); | 249 size_t handlersCount = listenerInfo.eventListenerVector.size(); |
| 247 for (size_t i = 0, outputIndex = 0; i < handlersCount; ++i) { | 250 for (size_t i = 0, outputIndex = 0; i < handlersCount; ++i) { |
| 248 RefPtr<EventListener> listener = listenerInfo.eventListenerVector[i].lis
tener; | 251 RefPtr<EventListener> listener = listenerInfo.eventListenerVector[i].lis
tener; |
| 249 if (listener->type() != EventListener::JSEventListenerType) { | 252 if (listener->type() != EventListener::JSEventListenerType) { |
| 250 ASSERT_NOT_REACHED(); | 253 ASSERT_NOT_REACHED(); |
| 251 continue; | 254 continue; |
| 252 } | 255 } |
| 253 V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListene
r*>(listener.get()); | 256 V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListene
r*>(listener.get()); |
| 254 v8::Local<v8::Context> context = toV8Context(document, v8Listener->world
()); | 257 v8::Local<v8::Context> context = toV8Context(executionContext, v8Listene
r->world()); |
| 255 // Hide listeners from other contexts. | 258 // Hide listeners from other contexts. |
| 256 if (context != isolate->GetCurrentContext()) | 259 if (context != isolate->GetCurrentContext()) |
| 257 continue; | 260 continue; |
| 258 v8::Local<v8::Object> function; | 261 v8::Local<v8::Object> function; |
| 259 { | 262 { |
| 260 // getListenerObject() may cause JS in the event attribute to get co
mpiled, potentially unsuccessfully. | 263 // getListenerObject() may cause JS in the event attribute to get co
mpiled, potentially unsuccessfully. |
| 261 v8::TryCatch block; | 264 v8::TryCatch block; |
| 262 function = v8Listener->getListenerObject(document); | 265 function = v8Listener->getListenerObject(executionContext); |
| 263 if (block.HasCaught()) | 266 if (block.HasCaught()) |
| 264 continue; | 267 continue; |
| 265 } | 268 } |
| 266 ASSERT(!function.IsEmpty()); | 269 ASSERT(!function.IsEmpty()); |
| 267 v8::Local<v8::Object> listenerEntry = v8::Object::New(isolate); | 270 v8::Local<v8::Object> listenerEntry = v8::Object::New(isolate); |
| 268 listenerEntry->Set(v8AtomicString(isolate, "listener"), function); | 271 listenerEntry->Set(v8AtomicString(isolate, "listener"), function); |
| 269 listenerEntry->Set(v8AtomicString(isolate, "useCapture"), v8::Boolean::N
ew(isolate, listenerInfo.eventListenerVector[i].useCapture)); | 272 listenerEntry->Set(v8AtomicString(isolate, "useCapture"), v8::Boolean::N
ew(isolate, listenerInfo.eventListenerVector[i].useCapture)); |
| 270 result->Set(v8::Number::New(isolate, outputIndex++), listenerEntry); | 273 result->Set(v8::Number::New(isolate, outputIndex++), listenerEntry); |
| 271 } | 274 } |
| 272 return result; | 275 return result; |
| 273 } | 276 } |
| 274 | 277 |
| 275 void V8InjectedScriptHost::getEventListenersMethodCustom(const v8::FunctionCallb
ackInfo<v8::Value>& info) | 278 void V8InjectedScriptHost::getEventListenersMethodCustom(const v8::FunctionCallb
ackInfo<v8::Value>& info) |
| 276 { | 279 { |
| 277 if (info.Length() < 1) | 280 if (info.Length() < 1) |
| 278 return; | 281 return; |
| 279 | 282 |
| 283 EventTarget* target = 0; |
| 280 v8::Local<v8::Value> value = info[0]; | 284 v8::Local<v8::Value> value = info[0]; |
| 281 if (!V8Node::hasInstance(value, info.GetIsolate())) | 285 |
| 282 return; | 286 if (V8EventTarget::hasInstance(value, info.GetIsolate())) |
| 283 Node* node = V8Node::toNative(value->ToObject()); | 287 target = V8EventTarget::toNative(value->ToObject()); |
| 284 if (!node) | 288 |
| 289 // We need to handle a DOMWindow specially, because a DOMWindow wrapper exis
ts on a prototype chain. |
| 290 if (!target) |
| 291 target = toNativeDOMWindow(value, info.GetIsolate()); |
| 292 |
| 293 if (!target || !target->executionContext()) |
| 285 return; | 294 return; |
| 286 | 295 |
| 287 InjectedScriptHost* host = V8InjectedScriptHost::toNative(info.Holder()); | 296 InjectedScriptHost* host = V8InjectedScriptHost::toNative(info.Holder()); |
| 288 Vector<EventListenerInfo> listenersArray; | 297 Vector<EventListenerInfo> listenersArray; |
| 289 host->getEventListenersImpl(node, listenersArray); | 298 host->getEventListenersImpl(target, listenersArray); |
| 290 | 299 |
| 291 v8::Local<v8::Object> result = v8::Object::New(info.GetIsolate()); | 300 v8::Local<v8::Object> result = v8::Object::New(info.GetIsolate()); |
| 292 for (size_t i = 0; i < listenersArray.size(); ++i) { | 301 for (size_t i = 0; i < listenersArray.size(); ++i) { |
| 293 v8::Handle<v8::Array> listeners = getJSListenerFunctions(&node->document
(), listenersArray[i], info.GetIsolate()); | 302 v8::Handle<v8::Array> listeners = getJSListenerFunctions(target->executi
onContext(), listenersArray[i], info.GetIsolate()); |
| 294 if (!listeners->Length()) | 303 if (!listeners->Length()) |
| 295 continue; | 304 continue; |
| 296 AtomicString eventType = listenersArray[i].eventType; | 305 AtomicString eventType = listenersArray[i].eventType; |
| 297 result->Set(v8String(info.GetIsolate(), eventType), listeners); | 306 result->Set(v8String(info.GetIsolate(), eventType), listeners); |
| 298 } | 307 } |
| 299 | 308 |
| 300 v8SetReturnValue(info, result); | 309 v8SetReturnValue(info, result); |
| 301 } | 310 } |
| 302 | 311 |
| 303 void V8InjectedScriptHost::inspectMethodCustom(const v8::FunctionCallbackInfo<v8
::Value>& info) | 312 void V8InjectedScriptHost::inspectMethodCustom(const v8::FunctionCallbackInfo<v8
::Value>& info) |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 int lineNumber; | 447 int lineNumber; |
| 439 int columnNumber; | 448 int columnNumber; |
| 440 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) | 449 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) |
| 441 return; | 450 return; |
| 442 | 451 |
| 443 InjectedScriptHost* host = V8InjectedScriptHost::toNative(info.Holder()); | 452 InjectedScriptHost* host = V8InjectedScriptHost::toNative(info.Holder()); |
| 444 host->unmonitorFunction(scriptId, lineNumber, columnNumber); | 453 host->unmonitorFunction(scriptId, lineNumber, columnNumber); |
| 445 } | 454 } |
| 446 | 455 |
| 447 } // namespace WebCore | 456 } // namespace WebCore |
| OLD | NEW |