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 15 matching lines...) Expand all Loading... |
26 | 26 |
27 #include "config.h" | 27 #include "config.h" |
28 | 28 |
29 #if ENABLE(WORKERS) | 29 #if ENABLE(WORKERS) |
30 | 30 |
31 #include "WorkerMessagingProxy.h" | 31 #include "WorkerMessagingProxy.h" |
32 | 32 |
33 #include "DOMWindow.h" | 33 #include "DOMWindow.h" |
34 #include "Document.h" | 34 #include "Document.h" |
35 #include "MessageEvent.h" | 35 #include "MessageEvent.h" |
| 36 #include "ScriptExecutionContext.h" |
36 #include "Worker.h" | 37 #include "Worker.h" |
37 #include "WorkerContext.h" | 38 #include "WorkerContext.h" |
38 #include "WorkerTask.h" | |
39 #include "WorkerThread.h" | 39 #include "WorkerThread.h" |
40 | 40 |
41 namespace WebCore { | 41 namespace WebCore { |
42 | 42 |
43 class MessageWorkerContextTask : public WorkerTask { | 43 class MessageWorkerContextTask : public ScriptExecutionContext::Task { |
44 public: | 44 public: |
45 static PassRefPtr<MessageWorkerContextTask> create(const String& message) | 45 static PassRefPtr<MessageWorkerContextTask> create(const String& message) |
46 { | 46 { |
47 return adoptRef(new MessageWorkerContextTask(message)); | 47 return adoptRef(new MessageWorkerContextTask(message)); |
48 } | 48 } |
49 | 49 |
50 private: | 50 private: |
51 MessageWorkerContextTask(const String& message) | 51 MessageWorkerContextTask(const String& message) |
52 : m_message(message.copy()) | 52 : m_message(message.copy()) |
53 { | 53 { |
54 } | 54 } |
55 | 55 |
56 virtual void performTask(WorkerContext* context) | 56 virtual void performTask(ScriptExecutionContext* scriptContext) |
57 { | 57 { |
| 58 ASSERT(scriptContext->isWorkerContext()); |
| 59 WorkerContext* context = static_cast<WorkerContext*>(scriptContext); |
| 60 |
58 RefPtr<Event> evt = MessageEvent::create(m_message, "", "", 0, 0); | 61 RefPtr<Event> evt = MessageEvent::create(m_message, "", "", 0, 0); |
59 | 62 |
60 if (context->onmessage()) { | 63 if (context->onmessage()) { |
61 evt->setTarget(context); | 64 evt->setTarget(context); |
62 evt->setCurrentTarget(context); | 65 evt->setCurrentTarget(context); |
63 context->onmessage()->handleEvent(evt.get(), false); | 66 context->onmessage()->handleEvent(evt.get(), false); |
64 } | 67 } |
65 | 68 |
66 ExceptionCode ec = 0; | 69 ExceptionCode ec = 0; |
67 context->dispatchEvent(evt.release(), ec); | 70 context->dispatchEvent(evt.release(), ec); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 || (m_scriptExecutionContext->isWorkerContext() && currentThread() == st
atic_cast<WorkerContext*>(m_scriptExecutionContext.get())->thread()->threadID())
); | 209 || (m_scriptExecutionContext->isWorkerContext() && currentThread() == st
atic_cast<WorkerContext*>(m_scriptExecutionContext.get())->thread()->threadID())
); |
207 } | 210 } |
208 | 211 |
209 void WorkerMessagingProxy::postMessageToWorkerObject(const String& message) | 212 void WorkerMessagingProxy::postMessageToWorkerObject(const String& message) |
210 { | 213 { |
211 m_scriptExecutionContext->postTask(MessageWorkerTask::create(message, this))
; | 214 m_scriptExecutionContext->postTask(MessageWorkerTask::create(message, this))
; |
212 } | 215 } |
213 | 216 |
214 void WorkerMessagingProxy::postMessageToWorkerContext(const String& message) | 217 void WorkerMessagingProxy::postMessageToWorkerContext(const String& message) |
215 { | 218 { |
| 219 postTaskToWorkerContext(MessageWorkerContextTask::create(message)); |
| 220 } |
| 221 |
| 222 void WorkerMessagingProxy::postTaskToWorkerContext(PassRefPtr<ScriptExecutionCon
text::Task> task) |
| 223 { |
216 if (m_askedToTerminate) | 224 if (m_askedToTerminate) |
217 return; | 225 return; |
218 | 226 |
219 if (m_workerThread) { | 227 if (m_workerThread) { |
220 ++m_unconfirmedMessageCount; | 228 ++m_unconfirmedMessageCount; |
221 m_workerThread->runLoop().postTask(MessageWorkerContextTask::create(mess
age)); | 229 m_workerThread->runLoop().postTask(task); |
222 } else | 230 } else |
223 m_queuedEarlyTasks.append(MessageWorkerContextTask::create(message)); | 231 m_queuedEarlyTasks.append(task); |
224 } | 232 } |
225 | 233 |
226 void WorkerMessagingProxy::postTaskToParentContext(PassRefPtr<ScriptExecutionCon
text::Task> task) | 234 void WorkerMessagingProxy::postTaskToWorkerObject(PassRefPtr<ScriptExecutionCont
ext::Task> task) |
227 { | 235 { |
228 m_scriptExecutionContext->postTask(task); | 236 m_scriptExecutionContext->postTask(task); |
229 } | 237 } |
230 | 238 |
231 void WorkerMessagingProxy::postWorkerException(const String& errorMessage, int l
ineNumber, const String& sourceURL) | 239 void WorkerMessagingProxy::postWorkerException(const String& errorMessage, int l
ineNumber, const String& sourceURL) |
232 { | 240 { |
233 m_scriptExecutionContext->postTask(WorkerExceptionTask::create(errorMessage,
lineNumber, sourceURL, this)); | 241 m_scriptExecutionContext->postTask(WorkerExceptionTask::create(errorMessage,
lineNumber, sourceURL, this)); |
234 } | 242 } |
235 | 243 |
236 void WorkerMessagingProxy::workerThreadCreated(PassRefPtr<WorkerThread> workerTh
read) | 244 void WorkerMessagingProxy::workerThreadCreated(PassRefPtr<WorkerThread> workerTh
read) |
(...skipping 13 matching lines...) Expand all Loading... |
250 m_queuedEarlyTasks.clear(); | 258 m_queuedEarlyTasks.clear(); |
251 } | 259 } |
252 } | 260 } |
253 | 261 |
254 void WorkerMessagingProxy::workerObjectDestroyed() | 262 void WorkerMessagingProxy::workerObjectDestroyed() |
255 { | 263 { |
256 m_workerObject = 0; | 264 m_workerObject = 0; |
257 if (m_workerThread) | 265 if (m_workerThread) |
258 terminate(); | 266 terminate(); |
259 else | 267 else |
260 workerContextDestroyedInternal(); // It never existed, just do our clean
up. | 268 workerContextDestroyedInternal(); |
261 } | 269 } |
262 | 270 |
263 void WorkerMessagingProxy::workerContextDestroyed() | 271 void WorkerMessagingProxy::workerContextDestroyed() |
264 { | 272 { |
265 m_scriptExecutionContext->postTask(WorkerContextDestroyedTask::create(this))
; | 273 m_scriptExecutionContext->postTask(WorkerContextDestroyedTask::create(this))
; |
266 // Will execute workerContextDestroyedInternal() on context's thread. | 274 // Will execute workerContextDestroyedInternal() on context's thread. |
267 } | 275 } |
268 | 276 |
269 void WorkerMessagingProxy::workerContextDestroyedInternal() | 277 void WorkerMessagingProxy::workerContextDestroyedInternal() |
270 { | 278 { |
271 // WorkerContextDestroyedTask is always the last to be performed, so the pro
xy is not needed for communication | 279 // WorkerContextDestroyedTask is always the last to be performed, so the pro
xy is not needed for communication |
272 // in either side any more. However, the Worker object may still exist, and
it assumes that the proxy exists, too. | 280 // in either side any more. However, the Worker object may still exist, and
it assumes that the proxy exists, too. |
| 281 m_workerThread = 0; |
273 if (!m_workerObject) | 282 if (!m_workerObject) |
274 delete this; | 283 delete this; |
275 } | 284 } |
276 | 285 |
277 void WorkerMessagingProxy::terminate() | 286 void WorkerMessagingProxy::terminate() |
278 { | 287 { |
279 if (m_askedToTerminate) | 288 if (m_askedToTerminate) |
280 return; | 289 return; |
281 m_askedToTerminate = true; | 290 m_askedToTerminate = true; |
282 | 291 |
(...skipping 26 matching lines...) Expand all Loading... |
309 bool WorkerMessagingProxy::workerThreadHasPendingActivity() const | 318 bool WorkerMessagingProxy::workerThreadHasPendingActivity() const |
310 { | 319 { |
311 return (m_unconfirmedMessageCount || m_workerThreadHadPendingActivity) && !m
_askedToTerminate; | 320 return (m_unconfirmedMessageCount || m_workerThreadHadPendingActivity) && !m
_askedToTerminate; |
312 } | 321 } |
313 | 322 |
314 } // namespace WebCore | 323 } // namespace WebCore |
315 | 324 |
316 #endif // ENABLE(WORKERS) | 325 #endif // ENABLE(WORKERS) |
317 | 326 |
318 | 327 |
OLD | NEW |