From cfb8c047aae384eb1e6c27c047832ff41a8764b3 Mon Sep 17 00:00:00 2001 From: "jianli@chromium.org" Date: Fri, 6 Mar 2009 02:11:58 +0000 Subject: 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 --- webkit/glue/webworker_impl.cc | 4 +++- webkit/glue/webworkerclient_impl.cc | 12 ++++++++---- webkit/glue/webworkerclient_impl.h | 8 ++++++++ 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(destination), static_cast(source), static_cast(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 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 script_execution_context_; + WebCore::Worker* worker_; scoped_ptr webworker_; bool asked_to_terminate_; -- cgit v1.1