summaryrefslogtreecommitdiffstats
path: root/webkit/glue/webworker_impl.cc
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-01 20:33:27 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-01 20:33:27 +0000
commit982e781d80d395cd9749de92d2efd6a309168cd3 (patch)
tree74cb4e36be8cf047c25812649a4f3a2f5325520f /webkit/glue/webworker_impl.cc
parent52049d5cfde95de013f8f333f940fef4ecd31533 (diff)
downloadchromium_src-982e781d80d395cd9749de92d2efd6a309168cd3.zip
chromium_src-982e781d80d395cd9749de92d2efd6a309168cd3.tar.gz
chromium_src-982e781d80d395cd9749de92d2efd6a309168cd3.tar.bz2
Call WebWorkerClient on the main thread. This makes it consistent with the rest of the WebKit API, which is single threaded. Also a bunch of small fixes to make layout tests pass: the dll was being unloaded while its functions were still queued to be dispatched, and a string allocated in the dll was being GC'd in test shell.
BUG=11011 Review URL: http://codereview.chromium.org/102005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15087 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/webworker_impl.cc')
-rw-r--r--webkit/glue/webworker_impl.cc100
1 files changed, 93 insertions, 7 deletions
diff --git a/webkit/glue/webworker_impl.cc b/webkit/glue/webworker_impl.cc
index a8e461d..ba78c7d 100644
--- a/webkit/glue/webworker_impl.cc
+++ b/webkit/glue/webworker_impl.cc
@@ -12,6 +12,7 @@
#include "SecurityOrigin.h"
#include "WorkerContext.h"
#include "WorkerThread.h"
+#include <wtf/MainThread.h>
#include <wtf/Threading.h>
#undef LOG
@@ -106,17 +107,54 @@ void WebWorkerImpl::postMessageToWorkerContext(const WebString& message) {
void WebWorkerImpl::workerObjectDestroyed() {
}
+void WebWorkerImpl::DispatchTaskToMainThread(
+ PassRefPtr<WebCore::ScriptExecutionContext::Task> task) {
+ return WTF::callOnMainThread(InvokeTaskMethod, task.releaseRef());
+}
+
+void WebWorkerImpl::InvokeTaskMethod(void* param) {
+ WebCore::ScriptExecutionContext::Task* task =
+ static_cast<WebCore::ScriptExecutionContext::Task*>(param);
+ task->performTask(NULL);
+ task->deref();
+}
+
// WorkerObjectProxy -----------------------------------------------------------
void WebWorkerImpl::postMessageToWorkerObject(const WebCore::String& message) {
- client_->postMessageToWorkerObject(webkit_glue::StringToWebString(message));
+ DispatchTaskToMainThread(WebCore::createCallbackTask(
+ &PostMessageTask,
+ this,
+ message));
+}
+
+void WebWorkerImpl::PostMessageTask(
+ WebCore::ScriptExecutionContext* context,
+ WebWorkerImpl* this_ptr,
+ WebCore::String message) {
+ this_ptr->client_->postMessageToWorkerObject(
+ webkit_glue::StringToWebString(message));
}
void WebWorkerImpl::postExceptionToWorkerObject(
const WebCore::String& error_message,
int line_number,
const WebCore::String& source_url) {
- client_->postExceptionToWorkerObject(
+ DispatchTaskToMainThread(WebCore::createCallbackTask(
+ &PostExceptionTask,
+ this,
+ error_message,
+ line_number,
+ source_url));
+}
+
+void WebWorkerImpl::PostExceptionTask(
+ WebCore::ScriptExecutionContext* context,
+ WebWorkerImpl* this_ptr,
+ const WebCore::String& error_message,
+ int line_number,
+ const WebCore::String& source_url) {
+ this_ptr->client_->postExceptionToWorkerObject(
webkit_glue::StringToWebString(error_message),
line_number,
webkit_glue::StringToWebString(source_url));
@@ -129,28 +167,76 @@ void WebWorkerImpl::postConsoleMessageToWorkerObject(
const WebCore::String& message,
int line_number,
const WebCore::String& source_url) {
- client_->postConsoleMessageToWorkerObject(
+ DispatchTaskToMainThread(WebCore::createCallbackTask(
+ &PostConsoleMessageTask,
+ this,
static_cast<int>(destination),
static_cast<int>(source),
static_cast<int>(level),
+ message,
+ line_number,
+ source_url));
+}
+
+void WebWorkerImpl::PostConsoleMessageTask(
+ WebCore::ScriptExecutionContext* context,
+ WebWorkerImpl* this_ptr,
+ int destination,
+ int source,
+ int level,
+ const WebCore::String& message,
+ int line_number,
+ const WebCore::String& source_url) {
+ this_ptr->client_->postConsoleMessageToWorkerObject(
+ destination,
+ source,
+ level,
webkit_glue::StringToWebString(message),
line_number,
webkit_glue::StringToWebString(source_url));
}
void WebWorkerImpl::confirmMessageFromWorkerObject(bool has_pending_activity) {
- client_->confirmMessageFromWorkerObject(has_pending_activity);
+ DispatchTaskToMainThread(WebCore::createCallbackTask(
+ &ConfirmMessageTask,
+ this,
+ has_pending_activity));
+}
+
+void WebWorkerImpl::ConfirmMessageTask(
+ WebCore::ScriptExecutionContext* context,
+ WebWorkerImpl* this_ptr,
+ bool has_pending_activity) {
+ this_ptr->client_->confirmMessageFromWorkerObject(has_pending_activity);
}
void WebWorkerImpl::reportPendingActivity(bool has_pending_activity) {
- client_->reportPendingActivity(has_pending_activity);
+ DispatchTaskToMainThread(WebCore::createCallbackTask(
+ &ReportPendingActivityTask,
+ this,
+ has_pending_activity));
+}
+
+void WebWorkerImpl::ReportPendingActivityTask(
+ WebCore::ScriptExecutionContext* context,
+ WebWorkerImpl* this_ptr,
+ bool has_pending_activity) {
+ this_ptr->client_->reportPendingActivity(has_pending_activity);
}
void WebWorkerImpl::workerContextDestroyed() {
- client_->workerContextDestroyed();
+ DispatchTaskToMainThread(WebCore::createCallbackTask(
+ &WorkerContextDestroyedTask,
+ this));
+}
+
+void WebWorkerImpl::WorkerContextDestroyedTask(
+ WebCore::ScriptExecutionContext* context,
+ WebWorkerImpl* this_ptr) {
+ this_ptr->client_->workerContextDestroyed();
// The lifetime of this proxy is controlled by the worker context.
- delete this;
+ delete this_ptr;
}
#else