Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: Source/bindings/v8/V8WorkerContextEventListener.cpp

Issue 17648006: Rename WorkerContext to WorkerGlobalScope (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
29 */
30
31 #include "config.h"
32
33 #include "bindings/v8/V8WorkerContextEventListener.h"
34
35 #include "V8Event.h"
36 #include "V8EventTarget.h"
37 #include "bindings/v8/V8Binding.h"
38 #include "bindings/v8/V8DOMWrapper.h"
39 #include "bindings/v8/V8GCController.h"
40 #include "bindings/v8/V8ScriptRunner.h"
41 #include "bindings/v8/WorkerScriptController.h"
42 #include "core/inspector/InspectorInstrumentation.h"
43 #include "core/workers/WorkerContext.h"
44
45 namespace WebCore {
46
47 V8WorkerContextEventListener::V8WorkerContextEventListener(v8::Local<v8::Object> listener, bool isInline)
48 : V8EventListener(listener, isInline)
49 {
50 }
51
52 void V8WorkerContextEventListener::handleEvent(ScriptExecutionContext* context, Event* event)
53 {
54 if (!context)
55 return;
56
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.
59 RefPtr<V8AbstractEventListener> protect(this);
60
61 v8::HandleScope handleScope;
62
63 ASSERT(context->isWorkerContext());
64 WorkerScriptController* script = static_cast<WorkerContext*>(context)->scrip t();
65 if (!script)
66 return;
67
68 v8::Handle<v8::Context> v8Context = script->context();
69 if (v8Context.IsEmpty())
70 return;
71
72 // Enter the V8 context in which to perform the event handling.
73 v8::Context::Scope scope(v8Context);
74
75 // Get the V8 wrapper for the event object.
76 v8::Isolate* isolate = v8Context->GetIsolate();
77 v8::Handle<v8::Value> jsEvent = toV8(event, v8::Handle<v8::Object>(), isolat e);
78
79 invokeEventHandler(context, event, v8::Local<v8::Value>::New(isolate, jsEven t));
80 }
81
82 v8::Local<v8::Value> V8WorkerContextEventListener::callListenerFunction(ScriptEx ecutionContext* context, v8::Handle<v8::Value> jsEvent, Event* event)
83 {
84 V8GCController::checkMemoryUsage();
85
86 v8::Local<v8::Function> handlerFunction = getListenerFunction(context);
87 v8::Local<v8::Object> receiver = getReceiverObject(context, event);
88 if (handlerFunction.IsEmpty() || receiver.IsEmpty())
89 return v8::Local<v8::Value>();
90
91 InspectorInstrumentationCookie cookie;
92 if (InspectorInstrumentation::timelineAgentEnabled(context)) {
93 String resourceName("undefined");
94 int lineNumber = 1;
95 v8::ScriptOrigin origin = handlerFunction->GetScriptOrigin();
96 if (!origin.ResourceName().IsEmpty()) {
97 resourceName = toWebCoreString(origin.ResourceName());
98 lineNumber = handlerFunction->GetScriptLineNumber() + 1;
99 }
100 cookie = InspectorInstrumentation::willCallFunction(context, resourceNam e, lineNumber);
101 }
102
103 v8::Handle<v8::Value> parameters[1] = { jsEvent };
104 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(handlerFunction, context, receiver, WTF_ARRAY_LENGTH(parameters), parameters);
105
106 InspectorInstrumentation::didCallFunction(cookie);
107
108 return result;
109 }
110
111 v8::Local<v8::Object> V8WorkerContextEventListener::getReceiverObject(ScriptExec utionContext* context, Event* event)
112 {
113 v8::Local<v8::Object> listener = getListenerObject(context);
114
115 if (!listener.IsEmpty() && !listener->IsFunction())
116 return listener;
117
118 EventTarget* target = event->currentTarget();
119 v8::Handle<v8::Value> value = toV8(target, v8::Handle<v8::Object>(), toV8Con text(context, world())->GetIsolate());
120 if (value.IsEmpty())
121 return v8::Local<v8::Object>();
122 return v8::Local<v8::Object>::New(v8::Handle<v8::Object>::Cast(value));
123 }
124
125 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/V8WorkerContextEventListener.h ('k') | Source/bindings/v8/V8WorkerGlobalScopeEventListener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698