OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 13 matching lines...) Expand all Loading... |
24 * | 24 * |
25 */ | 25 */ |
26 | 26 |
27 #include "config.h" | 27 #include "config.h" |
28 | 28 |
29 #if ENABLE(WORKERS) | 29 #if ENABLE(WORKERS) |
30 | 30 |
31 #include "WorkerContext.h" | 31 #include "WorkerContext.h" |
32 | 32 |
33 #include "ActiveDOMObject.h" | 33 #include "ActiveDOMObject.h" |
| 34 #include "DOMTimer.h" |
34 #include "DOMWindow.h" | 35 #include "DOMWindow.h" |
35 #include "Event.h" | 36 #include "Event.h" |
36 #include "EventException.h" | 37 #include "EventException.h" |
37 #include "GenericWorkerTask.h" | 38 #include "GenericWorkerTask.h" |
38 #include "NotImplemented.h" | 39 #include "NotImplemented.h" |
39 #include "SecurityOrigin.h" | 40 #include "SecurityOrigin.h" |
40 #include "WorkerLocation.h" | 41 #include "WorkerLocation.h" |
41 #include "WorkerMessagingProxy.h" | 42 #include "WorkerMessagingProxy.h" |
42 #include "WorkerNavigator.h" | 43 #include "WorkerNavigator.h" |
43 #include "WorkerTask.h" | |
44 #include "WorkerThread.h" | 44 #include "WorkerThread.h" |
45 #include <wtf/RefPtr.h> | 45 #include <wtf/RefPtr.h> |
46 | 46 |
47 namespace WebCore { | 47 namespace WebCore { |
48 | 48 |
49 WorkerContext::WorkerContext(const KURL& url, const String& userAgent, WorkerThr
ead* thread) | 49 WorkerContext::WorkerContext(const KURL& url, const String& userAgent, WorkerThr
ead* thread) |
50 : m_url(url) | 50 : m_url(url) |
51 , m_userAgent(userAgent) | 51 , m_userAgent(userAgent) |
52 , m_location(WorkerLocation::create(url)) | 52 , m_location(WorkerLocation::create(url)) |
53 , m_script(new WorkerScriptController(this)) | 53 , m_script(new WorkerScriptController(this)) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 return true; | 104 return true; |
105 } | 105 } |
106 return false; | 106 return false; |
107 } | 107 } |
108 | 108 |
109 void WorkerContext::reportException(const String& errorMessage, int lineNumber,
const String& sourceURL) | 109 void WorkerContext::reportException(const String& errorMessage, int lineNumber,
const String& sourceURL) |
110 { | 110 { |
111 m_thread->messagingProxy()->postWorkerException(errorMessage, lineNumber, so
urceURL); | 111 m_thread->messagingProxy()->postWorkerException(errorMessage, lineNumber, so
urceURL); |
112 } | 112 } |
113 | 113 |
114 static void addMessageTask(ScriptExecutionContext* context, MessageDestination d
estination, MessageSource source, MessageLevel level, const String& message, uns
igned lineNumber, const String& sourceURL) | 114 static void addMessageTask(ScriptExecutionContext* context, WorkerMessagingProxy
* messagingProxy, MessageDestination destination, MessageSource source, MessageL
evel level, const String& message, unsigned lineNumber, const String& sourceURL) |
115 { | 115 { |
| 116 if (messagingProxy->askedToTerminate()) |
| 117 return; |
116 context->addMessage(destination, source, level, message, lineNumber, sourceU
RL); | 118 context->addMessage(destination, source, level, message, lineNumber, sourceU
RL); |
117 } | 119 } |
118 | 120 |
119 void WorkerContext::addMessage(MessageDestination destination, MessageSource sou
rce, MessageLevel level, const String& message, unsigned lineNumber, const Strin
g& sourceURL) | 121 void WorkerContext::addMessage(MessageDestination destination, MessageSource sou
rce, MessageLevel level, const String& message, unsigned lineNumber, const Strin
g& sourceURL) |
120 { | 122 { |
121 // createCallbackTask has to be a separate statement from postTaskToParentCo
ntext to make the destructor | 123 postTaskToWorkerObject(createCallbackTask(&addMessageTask, m_thread->messagi
ngProxy(), destination, source, level, message, lineNumber, sourceURL)); |
122 // for message.copy() get called before postTaskToParentContext. (If they a
re one statement, the destructor | |
123 // gets called after postTaskToParentContext which causes a race condition.)
| |
124 RefPtr<Task> task = createCallbackTask(m_thread->messagingProxy(), &addMessa
geTask, destination, source, level, message.copy(), lineNumber, sourceURL.copy()
); | |
125 postTaskToParentContext(task.release()); | |
126 } | 124 } |
127 | 125 |
128 void WorkerContext::resourceRetrievedByXMLHttpRequest(unsigned long, const Scrip
tString&) | 126 void WorkerContext::resourceRetrievedByXMLHttpRequest(unsigned long, const Scrip
tString&) |
129 { | 127 { |
130 // FIXME: The implementation is pending the fixes in https://bugs.webkit.org
/show_bug.cgi?id=23175 | 128 // FIXME: The implementation is pending the fixes in https://bugs.webkit.org
/show_bug.cgi?id=23175 |
131 notImplemented(); | 129 notImplemented(); |
132 } | 130 } |
133 | 131 |
134 void WorkerContext::postMessage(const String& message) | 132 void WorkerContext::postMessage(const String& message) |
135 { | 133 { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 ListenerVector listenersCopy = m_eventListeners.get(event->type()); | 178 ListenerVector listenersCopy = m_eventListeners.get(event->type()); |
181 for (ListenerVector::const_iterator listenerIter = listenersCopy.begin(); li
stenerIter != listenersCopy.end(); ++listenerIter) { | 179 for (ListenerVector::const_iterator listenerIter = listenersCopy.begin(); li
stenerIter != listenersCopy.end(); ++listenerIter) { |
182 event->setTarget(this); | 180 event->setTarget(this); |
183 event->setCurrentTarget(this); | 181 event->setCurrentTarget(this); |
184 listenerIter->get()->handleEvent(event.get(), false); | 182 listenerIter->get()->handleEvent(event.get(), false); |
185 } | 183 } |
186 | 184 |
187 return !event->defaultPrevented(); | 185 return !event->defaultPrevented(); |
188 } | 186 } |
189 | 187 |
190 class ScriptExecutionContextTaskWorkerTask : public WorkerTask { | |
191 public: | |
192 static PassRefPtr<ScriptExecutionContextTaskWorkerTask> create(PassRefPtr<Sc
riptExecutionContext::Task> task) | |
193 { | |
194 return adoptRef(new ScriptExecutionContextTaskWorkerTask(task)); | |
195 } | |
196 | |
197 private: | |
198 ScriptExecutionContextTaskWorkerTask(PassRefPtr<ScriptExecutionContext::Task
> task) | |
199 : m_task(task) | |
200 { | |
201 } | |
202 | |
203 virtual void performTask(WorkerContext* context) | |
204 { | |
205 m_task->performTask(context); | |
206 } | |
207 | |
208 RefPtr<ScriptExecutionContext::Task> m_task; | |
209 }; | |
210 | |
211 void WorkerContext::postTask(PassRefPtr<Task> task) | 188 void WorkerContext::postTask(PassRefPtr<Task> task) |
212 { | 189 { |
213 thread()->runLoop().postTask(ScriptExecutionContextTaskWorkerTask::create(ta
sk)); | 190 thread()->runLoop().postTask(task); |
214 } | 191 } |
215 | 192 |
216 void WorkerContext::postTaskToParentContext(PassRefPtr<Task> task) | 193 void WorkerContext::postTaskToWorkerObject(PassRefPtr<Task> task) |
217 { | 194 { |
218 thread()->messagingProxy()->postTaskToParentContext(task); | 195 thread()->messagingProxy()->postTaskToWorkerObject(task); |
| 196 } |
| 197 |
| 198 int WorkerContext::installTimeout(ScheduledAction* action, int timeout, bool sin
gleShot) |
| 199 { |
| 200 return DOMTimer::install(scriptExecutionContext(), action, timeout, singleSh
ot); |
| 201 } |
| 202 |
| 203 void WorkerContext::removeTimeout(int timeoutId) |
| 204 { |
| 205 DOMTimer::removeById(scriptExecutionContext(), timeoutId); |
219 } | 206 } |
220 | 207 |
221 } // namespace WebCore | 208 } // namespace WebCore |
222 | 209 |
223 #endif // ENABLE(WORKERS) | 210 #endif // ENABLE(WORKERS) |
224 | 211 |
225 | 212 |
226 | 213 |
OLD | NEW |