| 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 12 matching lines...) Expand all Loading... |
| 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 "config.h" | 31 #include "config.h" |
| 32 | 32 |
| 33 #include "bindings/v8/V8WorkerContextEventListener.h" | 33 #include "bindings/v8/V8WorkerGlobalScopeEventListener.h" |
| 34 | 34 |
| 35 #include "V8Event.h" | 35 #include "V8Event.h" |
| 36 #include "V8EventTarget.h" | 36 #include "V8EventTarget.h" |
| 37 #include "bindings/v8/V8Binding.h" | 37 #include "bindings/v8/V8Binding.h" |
| 38 #include "bindings/v8/V8DOMWrapper.h" | 38 #include "bindings/v8/V8DOMWrapper.h" |
| 39 #include "bindings/v8/V8GCController.h" | 39 #include "bindings/v8/V8GCController.h" |
| 40 #include "bindings/v8/V8ScriptRunner.h" | 40 #include "bindings/v8/V8ScriptRunner.h" |
| 41 #include "bindings/v8/WorkerScriptController.h" | 41 #include "bindings/v8/WorkerScriptController.h" |
| 42 #include "core/inspector/InspectorInstrumentation.h" | 42 #include "core/inspector/InspectorInstrumentation.h" |
| 43 #include "core/workers/WorkerContext.h" | 43 #include "core/workers/WorkerGlobalScope.h" |
| 44 | 44 |
| 45 namespace WebCore { | 45 namespace WebCore { |
| 46 | 46 |
| 47 V8WorkerContextEventListener::V8WorkerContextEventListener(v8::Local<v8::Object>
listener, bool isInline) | 47 V8WorkerGlobalScopeEventListener::V8WorkerGlobalScopeEventListener(v8::Local<v8:
:Object> listener, bool isInline) |
| 48 : V8EventListener(listener, isInline) | 48 : V8EventListener(listener, isInline) |
| 49 { | 49 { |
| 50 } | 50 } |
| 51 | 51 |
| 52 void V8WorkerContextEventListener::handleEvent(ScriptExecutionContext* context,
Event* event) | 52 void V8WorkerGlobalScopeEventListener::handleEvent(ScriptExecutionContext* conte
xt, Event* event) |
| 53 { | 53 { |
| 54 if (!context) | 54 if (!context) |
| 55 return; | 55 return; |
| 56 | 56 |
| 57 // The callback function on XMLHttpRequest can clear the event listener and
destroys 'this' object. Keep a local reference to it. | 57 // The callback function on XMLHttpRequest can clear the event listener and
destroys 'this' object. Keep a local reference to it. |
| 58 // See issue 889829. | 58 // See issue 889829. |
| 59 RefPtr<V8AbstractEventListener> protect(this); | 59 RefPtr<V8AbstractEventListener> protect(this); |
| 60 | 60 |
| 61 v8::HandleScope handleScope; | 61 v8::HandleScope handleScope; |
| 62 | 62 |
| 63 ASSERT(context->isWorkerContext()); | 63 ASSERT(context->isWorkerGlobalScope()); |
| 64 WorkerScriptController* script = static_cast<WorkerContext*>(context)->scrip
t(); | 64 WorkerScriptController* script = static_cast<WorkerGlobalScope*>(context)->s
cript(); |
| 65 if (!script) | 65 if (!script) |
| 66 return; | 66 return; |
| 67 | 67 |
| 68 v8::Handle<v8::Context> v8Context = script->context(); | 68 v8::Handle<v8::Context> v8Context = script->context(); |
| 69 if (v8Context.IsEmpty()) | 69 if (v8Context.IsEmpty()) |
| 70 return; | 70 return; |
| 71 | 71 |
| 72 // Enter the V8 context in which to perform the event handling. | 72 // Enter the V8 context in which to perform the event handling. |
| 73 v8::Context::Scope scope(v8Context); | 73 v8::Context::Scope scope(v8Context); |
| 74 | 74 |
| 75 // Get the V8 wrapper for the event object. | 75 // Get the V8 wrapper for the event object. |
| 76 v8::Isolate* isolate = v8Context->GetIsolate(); | 76 v8::Isolate* isolate = v8Context->GetIsolate(); |
| 77 v8::Handle<v8::Value> jsEvent = toV8(event, v8::Handle<v8::Object>(), isolat
e); | 77 v8::Handle<v8::Value> jsEvent = toV8(event, v8::Handle<v8::Object>(), isolat
e); |
| 78 | 78 |
| 79 invokeEventHandler(context, event, v8::Local<v8::Value>::New(isolate, jsEven
t)); | 79 invokeEventHandler(context, event, v8::Local<v8::Value>::New(isolate, jsEven
t)); |
| 80 } | 80 } |
| 81 | 81 |
| 82 v8::Local<v8::Value> V8WorkerContextEventListener::callListenerFunction(ScriptEx
ecutionContext* context, v8::Handle<v8::Value> jsEvent, Event* event) | 82 v8::Local<v8::Value> V8WorkerGlobalScopeEventListener::callListenerFunction(Scri
ptExecutionContext* context, v8::Handle<v8::Value> jsEvent, Event* event) |
| 83 { | 83 { |
| 84 V8GCController::checkMemoryUsage(); | 84 V8GCController::checkMemoryUsage(); |
| 85 | 85 |
| 86 v8::Local<v8::Function> handlerFunction = getListenerFunction(context); | 86 v8::Local<v8::Function> handlerFunction = getListenerFunction(context); |
| 87 v8::Local<v8::Object> receiver = getReceiverObject(context, event); | 87 v8::Local<v8::Object> receiver = getReceiverObject(context, event); |
| 88 if (handlerFunction.IsEmpty() || receiver.IsEmpty()) | 88 if (handlerFunction.IsEmpty() || receiver.IsEmpty()) |
| 89 return v8::Local<v8::Value>(); | 89 return v8::Local<v8::Value>(); |
| 90 | 90 |
| 91 InspectorInstrumentationCookie cookie; | 91 InspectorInstrumentationCookie cookie; |
| 92 if (InspectorInstrumentation::timelineAgentEnabled(context)) { | 92 if (InspectorInstrumentation::timelineAgentEnabled(context)) { |
| 93 String resourceName("undefined"); | 93 String resourceName("undefined"); |
| 94 int lineNumber = 1; | 94 int lineNumber = 1; |
| 95 v8::ScriptOrigin origin = handlerFunction->GetScriptOrigin(); | 95 v8::ScriptOrigin origin = handlerFunction->GetScriptOrigin(); |
| 96 if (!origin.ResourceName().IsEmpty()) { | 96 if (!origin.ResourceName().IsEmpty()) { |
| 97 resourceName = toWebCoreString(origin.ResourceName()); | 97 resourceName = toWebCoreString(origin.ResourceName()); |
| 98 lineNumber = handlerFunction->GetScriptLineNumber() + 1; | 98 lineNumber = handlerFunction->GetScriptLineNumber() + 1; |
| 99 } | 99 } |
| 100 cookie = InspectorInstrumentation::willCallFunction(context, resourceNam
e, lineNumber); | 100 cookie = InspectorInstrumentation::willCallFunction(context, resourceNam
e, lineNumber); |
| 101 } | 101 } |
| 102 | 102 |
| 103 v8::Handle<v8::Value> parameters[1] = { jsEvent }; | 103 v8::Handle<v8::Value> parameters[1] = { jsEvent }; |
| 104 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(handlerFunction,
context, receiver, WTF_ARRAY_LENGTH(parameters), parameters); | 104 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(handlerFunction,
context, receiver, WTF_ARRAY_LENGTH(parameters), parameters); |
| 105 | 105 |
| 106 InspectorInstrumentation::didCallFunction(cookie); | 106 InspectorInstrumentation::didCallFunction(cookie); |
| 107 | 107 |
| 108 return result; | 108 return result; |
| 109 } | 109 } |
| 110 | 110 |
| 111 v8::Local<v8::Object> V8WorkerContextEventListener::getReceiverObject(ScriptExec
utionContext* context, Event* event) | 111 v8::Local<v8::Object> V8WorkerGlobalScopeEventListener::getReceiverObject(Script
ExecutionContext* context, Event* event) |
| 112 { | 112 { |
| 113 v8::Local<v8::Object> listener = getListenerObject(context); | 113 v8::Local<v8::Object> listener = getListenerObject(context); |
| 114 | 114 |
| 115 if (!listener.IsEmpty() && !listener->IsFunction()) | 115 if (!listener.IsEmpty() && !listener->IsFunction()) |
| 116 return listener; | 116 return listener; |
| 117 | 117 |
| 118 EventTarget* target = event->currentTarget(); | 118 EventTarget* target = event->currentTarget(); |
| 119 v8::Handle<v8::Value> value = toV8(target, v8::Handle<v8::Object>(), toV8Con
text(context, world())->GetIsolate()); | 119 v8::Handle<v8::Value> value = toV8(target, v8::Handle<v8::Object>(), toV8Con
text(context, world())->GetIsolate()); |
| 120 if (value.IsEmpty()) | 120 if (value.IsEmpty()) |
| 121 return v8::Local<v8::Object>(); | 121 return v8::Local<v8::Object>(); |
| 122 return v8::Local<v8::Object>::New(v8::Handle<v8::Object>::Cast(value)); | 122 return v8::Local<v8::Object>::New(v8::Handle<v8::Object>::Cast(value)); |
| 123 } | 123 } |
| 124 | 124 |
| 125 } // namespace WebCore | 125 } // namespace WebCore |
| OLD | NEW |