| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 | 8 |
| 9 #include "GenericWorkerTask.h" | 9 #include "GenericWorkerTask.h" |
| 10 #include "KURL.h" | 10 #include "KURL.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // Note that we have to pass a URL with valid protocol in order to follow | 110 // Note that we have to pass a URL with valid protocol in order to follow |
| 111 // the path to do static value initializations. | 111 // the path to do static value initializations. |
| 112 WTF::RefPtr<WebCore::SecurityOrigin> origin = | 112 WTF::RefPtr<WebCore::SecurityOrigin> origin = |
| 113 WebCore::SecurityOrigin::create(WebCore::KURL("http://localhost")); | 113 WebCore::SecurityOrigin::create(WebCore::KURL("http://localhost")); |
| 114 origin.release(); | 114 origin.release(); |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 | 117 |
| 118 WebWorkerImpl::WebWorkerImpl(WebWorkerClient* client) | 118 WebWorkerImpl::WebWorkerImpl(WebWorkerClient* client) |
| 119 : client_(client), | 119 : client_(client), |
| 120 web_view_(NULL) { | 120 web_view_(NULL), |
| 121 asked_to_terminate_(false) { |
| 121 InitializeWebKitStaticValues(); | 122 InitializeWebKitStaticValues(); |
| 122 } | 123 } |
| 123 | 124 |
| 124 WebWorkerImpl::~WebWorkerImpl() { | 125 WebWorkerImpl::~WebWorkerImpl() { |
| 125 web_view_->Close(); | 126 web_view_->Close(); |
| 126 } | 127 } |
| 127 | 128 |
| 128 void WebWorkerImpl::PostMessageToWorkerContextTask( | 129 void WebWorkerImpl::PostMessageToWorkerContextTask( |
| 129 WebCore::ScriptExecutionContext* context, | 130 WebCore::ScriptExecutionContext* context, |
| 130 WebWorkerImpl* this_ptr, | 131 WebWorkerImpl* this_ptr, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 *this, | 178 *this, |
| 178 *this); | 179 *this); |
| 179 | 180 |
| 180 // Worker initialization means a pending activity. | 181 // Worker initialization means a pending activity. |
| 181 reportPendingActivity(true); | 182 reportPendingActivity(true); |
| 182 | 183 |
| 183 worker_thread_->start(); | 184 worker_thread_->start(); |
| 184 } | 185 } |
| 185 | 186 |
| 186 void WebWorkerImpl::terminateWorkerContext() { | 187 void WebWorkerImpl::terminateWorkerContext() { |
| 188 if (asked_to_terminate_) |
| 189 return; |
| 190 asked_to_terminate_ = true; |
| 191 |
| 187 if (worker_thread_) | 192 if (worker_thread_) |
| 188 worker_thread_->stop(); | 193 worker_thread_->stop(); |
| 189 } | 194 } |
| 190 | 195 |
| 191 void WebWorkerImpl::postMessageToWorkerContext(const WebString& message) { | 196 void WebWorkerImpl::postMessageToWorkerContext(const WebString& message) { |
| 192 worker_thread_->runLoop().postTask(WebCore::createCallbackTask( | 197 worker_thread_->runLoop().postTask(WebCore::createCallbackTask( |
| 193 &PostMessageToWorkerContextTask, | 198 &PostMessageToWorkerContextTask, |
| 194 this, | 199 this, |
| 195 webkit_glue::WebStringToString(message))); | 200 webkit_glue::WebStringToString(message))); |
| 196 } | 201 } |
| 197 | 202 |
| 198 void WebWorkerImpl::workerObjectDestroyed() { | 203 void WebWorkerImpl::workerObjectDestroyed() { |
| 204 // Worker object in the renderer was destroyed, perhaps a result of GC. |
| 205 // For us, it's a signal to start terminating the WorkerContext too. |
| 206 // TODO(dimich): when 'kill a worker' html5 spec algorithm is implemented, it |
| 207 // should be used here instead of 'terminate a worker'. |
| 208 terminateWorkerContext(); |
| 199 } | 209 } |
| 200 | 210 |
| 201 void WebWorkerImpl::DispatchTaskToMainThread( | 211 void WebWorkerImpl::DispatchTaskToMainThread( |
| 202 PassRefPtr<WebCore::ScriptExecutionContext::Task> task) { | 212 PassRefPtr<WebCore::ScriptExecutionContext::Task> task) { |
| 203 return WTF::callOnMainThread(InvokeTaskMethod, task.releaseRef()); | 213 return WTF::callOnMainThread(InvokeTaskMethod, task.releaseRef()); |
| 204 } | 214 } |
| 205 | 215 |
| 206 void WebWorkerImpl::InvokeTaskMethod(void* param) { | 216 void WebWorkerImpl::InvokeTaskMethod(void* param) { |
| 207 WebCore::ScriptExecutionContext::Task* task = | 217 WebCore::ScriptExecutionContext::Task* task = |
| 208 static_cast<WebCore::ScriptExecutionContext::Task*>(param); | 218 static_cast<WebCore::ScriptExecutionContext::Task*>(param); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 358 |
| 349 namespace WebKit { | 359 namespace WebKit { |
| 350 | 360 |
| 351 WebWorker* WebWorker::create(WebWorkerClient* client) { | 361 WebWorker* WebWorker::create(WebWorkerClient* client) { |
| 352 return NULL; | 362 return NULL; |
| 353 } | 363 } |
| 354 | 364 |
| 355 } | 365 } |
| 356 | 366 |
| 357 #endif | 367 #endif |
| OLD | NEW |