| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009 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 20 matching lines...) Expand all Loading... |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "bindings/v8/V8EventListener.h" | 32 #include "bindings/v8/V8EventListener.h" |
| 33 | 33 |
| 34 #include "bindings/v8/ScriptController.h" | 34 #include "bindings/v8/ScriptController.h" |
| 35 #include "bindings/v8/V8Binding.h" | 35 #include "bindings/v8/V8Binding.h" |
| 36 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
| 37 #include "core/frame/LocalFrame.h" | 37 #include "core/frame/LocalFrame.h" |
| 38 | 38 |
| 39 namespace WebCore { | 39 namespace WebCore { |
| 40 | 40 |
| 41 V8EventListener::V8EventListener(v8::Local<v8::Object> listener, bool isAttribut
e, v8::Isolate* isolate) | 41 V8EventListener::V8EventListener(v8::Local<v8::Object> listener, bool isAttribut
e, ScriptState* scriptState) |
| 42 : V8AbstractEventListener(isAttribute, DOMWrapperWorld::current(isolate), is
olate) | 42 : V8AbstractEventListener(isAttribute, scriptState) |
| 43 { | 43 { |
| 44 setListenerObject(listener); | 44 setListenerObject(listener); |
| 45 } | 45 } |
| 46 | 46 |
| 47 v8::Local<v8::Function> V8EventListener::getListenerFunction(ExecutionContext* c
ontext) | 47 v8::Local<v8::Function> V8EventListener::getListenerFunction(ExecutionContext*) |
| 48 { | 48 { |
| 49 v8::Local<v8::Object> listener = getListenerObject(context); | 49 v8::Local<v8::Object> listener = getListenerObject(scriptState()->executionC
ontext()); |
| 50 | 50 |
| 51 // Has the listener been disposed? | 51 // Has the listener been disposed? |
| 52 if (listener.IsEmpty()) | 52 if (listener.IsEmpty()) |
| 53 return v8::Local<v8::Function>(); | 53 return v8::Local<v8::Function>(); |
| 54 | 54 |
| 55 if (listener->IsFunction()) | 55 if (listener->IsFunction()) |
| 56 return v8::Local<v8::Function>::Cast(listener); | 56 return v8::Local<v8::Function>::Cast(listener); |
| 57 | 57 |
| 58 if (listener->IsObject()) { | 58 if (listener->IsObject()) { |
| 59 ASSERT_WITH_MESSAGE(!isAttribute(), "EventHandler attributes should only
accept JS Functions as input."); | 59 ASSERT_WITH_MESSAGE(!isAttribute(), "EventHandler attributes should only
accept JS Functions as input."); |
| 60 v8::Local<v8::Value> property = listener->Get(v8AtomicString(isolate(),
"handleEvent")); | 60 v8::Local<v8::Value> property = listener->Get(v8AtomicString(isolate(),
"handleEvent")); |
| 61 // Check that no exceptions were thrown when getting the | 61 // Check that no exceptions were thrown when getting the |
| 62 // handleEvent property and that the value is a function. | 62 // handleEvent property and that the value is a function. |
| 63 if (!property.IsEmpty() && property->IsFunction()) | 63 if (!property.IsEmpty() && property->IsFunction()) |
| 64 return v8::Local<v8::Function>::Cast(property); | 64 return v8::Local<v8::Function>::Cast(property); |
| 65 } | 65 } |
| 66 | 66 |
| 67 return v8::Local<v8::Function>(); | 67 return v8::Local<v8::Function>(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 v8::Local<v8::Value> V8EventListener::callListenerFunction(ExecutionContext* con
text, v8::Handle<v8::Value> jsEvent, Event* event) | 70 v8::Local<v8::Value> V8EventListener::callListenerFunction(ExecutionContext*, v8
::Handle<v8::Value> jsEvent, Event* event) |
| 71 { | 71 { |
| 72 | 72 |
| 73 v8::Local<v8::Function> handlerFunction = getListenerFunction(context); | 73 v8::Local<v8::Function> handlerFunction = getListenerFunction(scriptState()-
>executionContext()); |
| 74 v8::Local<v8::Object> receiver = getReceiverObject(context, event); | 74 v8::Local<v8::Object> receiver = getReceiverObject(event); |
| 75 if (handlerFunction.IsEmpty() || receiver.IsEmpty()) | 75 if (handlerFunction.IsEmpty() || receiver.IsEmpty()) |
| 76 return v8::Local<v8::Value>(); | 76 return v8::Local<v8::Value>(); |
| 77 | 77 |
| 78 // FIXME: Can |context| be 0 here? | 78 if (!scriptState()->executionContext()->isDocument()) |
| 79 if (!context) | |
| 80 return v8::Local<v8::Value>(); | 79 return v8::Local<v8::Value>(); |
| 81 | 80 |
| 82 if (!context->isDocument()) | 81 LocalFrame* frame = toDocument(scriptState()->executionContext())->frame(); |
| 83 return v8::Local<v8::Value>(); | |
| 84 | |
| 85 LocalFrame* frame = toDocument(context)->frame(); | |
| 86 if (!frame) | 82 if (!frame) |
| 87 return v8::Local<v8::Value>(); | 83 return v8::Local<v8::Value>(); |
| 88 | 84 |
| 89 if (!frame->script().canExecuteScripts(AboutToExecuteScript)) | 85 if (!frame->script().canExecuteScripts(AboutToExecuteScript)) |
| 90 return v8::Local<v8::Value>(); | 86 return v8::Local<v8::Value>(); |
| 91 | 87 |
| 92 v8::Handle<v8::Value> parameters[1] = { jsEvent }; | 88 v8::Handle<v8::Value> parameters[1] = { jsEvent }; |
| 93 return frame->script().callFunction(handlerFunction, receiver, WTF_ARRAY_LEN
GTH(parameters), parameters); | 89 return frame->script().callFunction(handlerFunction, receiver, WTF_ARRAY_LEN
GTH(parameters), parameters); |
| 94 } | 90 } |
| 95 | 91 |
| 96 } // namespace WebCore | 92 } // namespace WebCore |
| OLD | NEW |