diff options
-rw-r--r-- | webkit/glue/webworker_impl.cc | 4 | ||||
-rw-r--r-- | webkit/glue/webworkerclient_impl.cc | 12 | ||||
-rw-r--r-- | 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<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_; |