summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-06 02:11:58 +0000
committerjianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-06 02:11:58 +0000
commitcfb8c047aae384eb1e6c27c047832ff41a8764b3 (patch)
treee4ecc7853bc3314c83f3855eca620c6b9f478748
parentad615eb3ff51a7d75c065498460e060ad17028ca (diff)
downloadchromium_src-cfb8c047aae384eb1e6c27c047832ff41a8764b3.zip
chromium_src-cfb8c047aae384eb1e6c27c047832ff41a8764b3.tar.gz
chromium_src-cfb8c047aae384eb1e6c27c047832ff41a8764b3.tar.bz2
Fix lifetime control for worker and worker context.
Review URL: http://codereview.chromium.org/40197 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11088 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--webkit/glue/webworker_impl.cc4
-rw-r--r--webkit/glue/webworkerclient_impl.cc12
-rw-r--r--webkit/glue/webworkerclient_impl.h8
3 files changed, 19 insertions, 5 deletions
diff --git a/webkit/glue/webworker_impl.cc b/webkit/glue/webworker_impl.cc
index 0d6529c..4b4ae94 100644
--- a/webkit/glue/webworker_impl.cc
+++ b/webkit/glue/webworker_impl.cc
@@ -73,7 +73,6 @@ void WebWorkerImpl::PostMessageToWorkerContext(const string16& message) {
}
void WebWorkerImpl::WorkerObjectDestroyed() {
- TerminateWorkerContext();
}
void WebWorkerImpl::postMessageToWorkerObject(const WebCore::String& message) {
@@ -116,6 +115,9 @@ void WebWorkerImpl::reportPendingActivity(bool hasPendingActivity) {
void WebWorkerImpl::workerContextDestroyed() {
client_->WorkerContextDestroyed();
+
+ // The lifetime of this proxy is controlled by the worker context.
+ delete this;
}
#else
diff --git a/webkit/glue/webworkerclient_impl.cc b/webkit/glue/webworkerclient_impl.cc
index c75bff4..11ccfca 100644
--- a/webkit/glue/webworkerclient_impl.cc
+++ b/webkit/glue/webworkerclient_impl.cc
@@ -10,6 +10,7 @@
#include "Frame.h"
#include "FrameLoaderClient.h"
+#include "ScriptExecutionContext.h"
#include "WorkerMessagingProxy.h"
#include "Worker.h"
@@ -55,7 +56,8 @@ WebCore::WorkerContextProxy* WebCore::WorkerContextProxy::create(
WebWorkerClientImpl::WebWorkerClientImpl(WebCore::Worker* worker)
- : worker_(worker),
+ : script_execution_context_(worker->scriptExecutionContext()),
+ worker_(worker),
asked_to_terminate_(false),
unconfirmed_message_count_(0),
worker_context_had_pending_activity_(false) {
@@ -99,6 +101,9 @@ bool WebWorkerClientImpl::hasPendingActivity() const {
void WebWorkerClientImpl::workerObjectDestroyed() {
webworker_->WorkerObjectDestroyed();
+
+ // The lifetime of this proxy is controlled by the worker.
+ delete this;
}
void WebWorkerClientImpl::PostMessageToWorkerObject(const string16& message) {
@@ -109,7 +114,7 @@ void WebWorkerClientImpl::PostExceptionToWorkerObject(
const string16& error_message,
int line_number,
const string16& source_url) {
- worker_->scriptExecutionContext()->reportException(
+ script_execution_context_->reportException(
webkit_glue::String16ToString(error_message),
line_number,
webkit_glue::String16ToString(source_url));
@@ -122,7 +127,7 @@ void WebWorkerClientImpl::PostConsoleMessageToWorkerObject(
const string16& message,
int line_number,
const string16& source_url) {
- worker_->scriptExecutionContext()->addMessage(
+ script_execution_context_->addMessage(
static_cast<WebCore::MessageDestination>(destination),
static_cast<WebCore::MessageSource>(source),
static_cast<WebCore::MessageLevel>(level),
@@ -140,7 +145,6 @@ void WebWorkerClientImpl::ReportPendingActivity(bool has_pending_activity) {
}
void WebWorkerClientImpl::WorkerContextDestroyed() {
- delete this;
}
#endif
diff --git a/webkit/glue/webworkerclient_impl.h b/webkit/glue/webworkerclient_impl.h
index 4277f4b..4c8277c 100644
--- a/webkit/glue/webworkerclient_impl.h
+++ b/webkit/glue/webworkerclient_impl.h
@@ -11,9 +11,14 @@
#include "webkit/glue/webworkerclient.h"
#include "WorkerContextProxy.h"
+#include <wtf/RefPtr.h>
class WebWorker;
+namespace WebCore {
+class ScriptExecutionContext;
+};
+
// The purpose of this class is to provide a WorkerContextProxy
// implementation that we can give to WebKit. Internally, it converts the
// data types to Chrome compatible ones so that renderer code can use it over
@@ -52,6 +57,9 @@ class WebWorkerClientImpl : public WebCore::WorkerContextProxy,
private:
virtual ~WebWorkerClientImpl();
+ // Guard against context from being destroyed before a worker exits.
+ WTF::RefPtr<WebCore::ScriptExecutionContext> script_execution_context_;
+
WebCore::Worker* worker_;
scoped_ptr<WebWorker> webworker_;
bool asked_to_terminate_;