diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-24 20:22:43 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-24 20:22:43 +0000 |
commit | 27ba8536c70127d3367f4609cb0ee1e65944ae20 (patch) | |
tree | f004485d299b52c673acece6b0e5ca90f5273f3d /webkit | |
parent | 9c16251546f278a3b804dd2034f29234f6354a09 (diff) | |
download | chromium_src-27ba8536c70127d3367f4609cb0ee1e65944ae20.zip chromium_src-27ba8536c70127d3367f4609cb0ee1e65944ae20.tar.gz chromium_src-27ba8536c70127d3367f4609cb0ee1e65944ae20.tar.bz2 |
Use WebWorker and WebWorkerClient from the WebKit API.
BUG=10995
R=jam
Review URL: http://codereview.chromium.org/92144
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14461 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/webview_delegate.h | 6 | ||||
-rw-r--r-- | webkit/glue/webworker.h | 31 | ||||
-rw-r--r-- | webkit/glue/webworker_impl.cc | 89 | ||||
-rw-r--r-- | webkit/glue/webworker_impl.h | 52 | ||||
-rw-r--r-- | webkit/glue/webworkerclient.h | 37 | ||||
-rw-r--r-- | webkit/glue/webworkerclient_impl.cc | 73 | ||||
-rw-r--r-- | webkit/glue/webworkerclient_impl.h | 61 | ||||
-rwxr-xr-x | webkit/tools/test_shell/test_webview_delegate.cc | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_webview_delegate.h | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_webworker_helper.cc | 4 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_webworker_helper.h | 9 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_worker/test_webworker.cc | 108 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_worker/test_webworker.h | 57 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_worker/test_worker_main.cc | 5 |
14 files changed, 263 insertions, 273 deletions
diff --git a/webkit/glue/webview_delegate.h b/webkit/glue/webview_delegate.h index d62024f..d2065c5 100644 --- a/webkit/glue/webview_delegate.h +++ b/webkit/glue/webview_delegate.h @@ -39,6 +39,8 @@ class WebMediaPlayerDelegate; namespace WebKit { class WebDragData; +class WebWorker; +class WebWorkerClient; struct WebPoint; struct WebRect; } @@ -58,8 +60,6 @@ class WebRequest; class WebResponse; class WebView; class WebWidget; -class WebWorker; -class WebWorkerClient; enum NavigationGesture { NavigationGestureUser, // User initiated navigation/load. This is not @@ -125,7 +125,7 @@ class WebViewDelegate : virtual public WebWidgetDelegate { } // This method is called when the renderer creates a worker object. - virtual WebWorker* CreateWebWorker(WebWorkerClient* client) { + virtual WebKit::WebWorker* CreateWebWorker(WebKit::WebWorkerClient* client) { return NULL; } diff --git a/webkit/glue/webworker.h b/webkit/glue/webworker.h deleted file mode 100644 index 302fa24..0000000 --- a/webkit/glue/webworker.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef WEBKIT_GLUE_WEBWORKER_H_ -#define WEBKIT_GLUE_WEBWORKER_H_ - -#include "base/string16.h" - -class GURL; -class WebWorkerClient; - -// This is a version of the WebCore::WorkerContextProxy interface that uses -// Chrome data types. -class WebWorker { - public: - virtual ~WebWorker() { } - - // Creates a WebWorker object that wraps around the WebKit code that implements - // web workers. - static WebWorker* Create(WebWorkerClient* client); - - virtual void StartWorkerContext(const GURL& script_url, - const string16& user_agent, - const string16& source_code) = 0; - virtual void TerminateWorkerContext() = 0; - virtual void PostMessageToWorkerContext(const string16& message) = 0; - virtual void WorkerObjectDestroyed() = 0; -}; - -#endif // #ifndef WEBKIT_GLUE_WEBWORKER_H_ diff --git a/webkit/glue/webworker_impl.cc b/webkit/glue/webworker_impl.cc index 9fdf1fc..a8e461d 100644 --- a/webkit/glue/webworker_impl.cc +++ b/webkit/glue/webworker_impl.cc @@ -18,16 +18,25 @@ #include "base/logging.h" #include "webkit/glue/glue_util.h" -#include "webkit/glue/webworkerclient.h" #include "webkit/glue/webworker_impl.h" +#include "third_party/WebKit/WebKit/chromium/public/WebString.h" +#include "third_party/WebKit/WebKit/chromium/public/WebURL.h" +#include "third_party/WebKit/WebKit/chromium/public/WebWorkerClient.h" +using WebKit::WebWorker; +using WebKit::WebWorkerClient; +using WebKit::WebString; +using WebKit::WebURL; #if ENABLE(WORKERS) -WebWorker* WebWorker::Create(WebWorkerClient* client) { +namespace WebKit { + +WebWorker* WebWorker::create(WebWorkerClient* client) { return new WebWorkerImpl(client); } +} // This function is called on the main thread to force to initialize some static // values used in WebKit before any worker thread is started. This is because in @@ -62,17 +71,19 @@ void WebWorkerImpl::PostMessageToWorkerContextTask( static_cast<WebCore::WorkerContext*>(context); worker_context->dispatchMessage(message); - this_ptr->client_->ConfirmMessageFromWorkerObject( + this_ptr->client_->confirmMessageFromWorkerObject( worker_context->hasPendingActivity()); } -void WebWorkerImpl::StartWorkerContext(const GURL& script_url, - const string16& user_agent, - const string16& source_code) { +// WebWorker ------------------------------------------------------------------- + +void WebWorkerImpl::startWorkerContext(const WebURL& script_url, + const WebString& user_agent, + const WebString& source_code) { worker_thread_ = WebCore::WorkerThread::create( - webkit_glue::GURLToKURL(script_url), - webkit_glue::String16ToString(user_agent), - webkit_glue::String16ToString(source_code), + webkit_glue::WebURLToKURL(script_url), + webkit_glue::WebStringToString(user_agent), + webkit_glue::WebStringToString(source_code), this); // Worker initialization means a pending activity. @@ -81,32 +92,34 @@ void WebWorkerImpl::StartWorkerContext(const GURL& script_url, worker_thread_->start(); } -void WebWorkerImpl::TerminateWorkerContext() { +void WebWorkerImpl::terminateWorkerContext() { worker_thread_->stop(); } -void WebWorkerImpl::PostMessageToWorkerContext(const string16& message) { +void WebWorkerImpl::postMessageToWorkerContext(const WebString& message) { worker_thread_->runLoop().postTask(WebCore::createCallbackTask( &PostMessageToWorkerContextTask, this, - webkit_glue::String16ToString(message))); + webkit_glue::WebStringToString(message))); } -void WebWorkerImpl::WorkerObjectDestroyed() { +void WebWorkerImpl::workerObjectDestroyed() { } +// WorkerObjectProxy ----------------------------------------------------------- + void WebWorkerImpl::postMessageToWorkerObject(const WebCore::String& message) { - client_->PostMessageToWorkerObject(webkit_glue::StringToString16(message)); + client_->postMessageToWorkerObject(webkit_glue::StringToWebString(message)); } void WebWorkerImpl::postExceptionToWorkerObject( - const WebCore::String& errorMessage, - int lineNumber, - const WebCore::String& sourceURL) { - client_->PostExceptionToWorkerObject( - webkit_glue::StringToString16(errorMessage), - lineNumber, - webkit_glue::StringToString16(sourceURL)); + const WebCore::String& error_message, + int line_number, + const WebCore::String& source_url) { + client_->postExceptionToWorkerObject( + webkit_glue::StringToWebString(error_message), + line_number, + webkit_glue::StringToWebString(source_url)); } void WebWorkerImpl::postConsoleMessageToWorkerObject( @@ -114,27 +127,27 @@ void WebWorkerImpl::postConsoleMessageToWorkerObject( WebCore::MessageSource source, WebCore::MessageLevel level, const WebCore::String& message, - int lineNumber, - const WebCore::String& sourceURL) { - client_->PostConsoleMessageToWorkerObject( - destination, - source, - level, - webkit_glue::StringToString16(message), - lineNumber, - webkit_glue::StringToString16(sourceURL)); + int line_number, + const WebCore::String& source_url) { + client_->postConsoleMessageToWorkerObject( + static_cast<int>(destination), + static_cast<int>(source), + static_cast<int>(level), + webkit_glue::StringToWebString(message), + line_number, + webkit_glue::StringToWebString(source_url)); } -void WebWorkerImpl::confirmMessageFromWorkerObject(bool hasPendingActivity) { - client_->ConfirmMessageFromWorkerObject(hasPendingActivity); +void WebWorkerImpl::confirmMessageFromWorkerObject(bool has_pending_activity) { + client_->confirmMessageFromWorkerObject(has_pending_activity); } -void WebWorkerImpl::reportPendingActivity(bool hasPendingActivity) { - client_->ReportPendingActivity(hasPendingActivity); +void WebWorkerImpl::reportPendingActivity(bool has_pending_activity) { + client_->reportPendingActivity(has_pending_activity); } void WebWorkerImpl::workerContextDestroyed() { - client_->WorkerContextDestroyed(); + client_->workerContextDestroyed(); // The lifetime of this proxy is controlled by the worker context. delete this; @@ -142,8 +155,12 @@ void WebWorkerImpl::workerContextDestroyed() { #else -WebWorker* WebWorker::Create(WebWorkerClient* client) { +namespace WebKit { + +WebWorker* WebWorker::create(WebWorkerClient* client) { return NULL; } +} + #endif diff --git a/webkit/glue/webworker_impl.h b/webkit/glue/webworker_impl.h index 4af1f64..8ae78c6 100644 --- a/webkit/glue/webworker_impl.h +++ b/webkit/glue/webworker_impl.h @@ -5,7 +5,7 @@ #ifndef WEBKIT_GLUE_WEBWORKER_IMPL_H_ #define WEBKIT_GLUE_WEBWORKER_IMPL_H_ -#include "webkit/glue/webworker.h" +#include "third_party/WebKit/WebKit/chromium/public/WebWorker.h" #if ENABLE(WORKERS) @@ -26,33 +26,35 @@ class WorkerThread; // WebCore::WorkerObjectProxy, this class will conver to Chrome data types first // and then call the supplied WebWorkerClient. class WebWorkerImpl: public WebCore::WorkerObjectProxy, - public WebWorker { + public WebKit::WebWorker { public: - WebWorkerImpl(WebWorkerClient* client); + explicit WebWorkerImpl(WebKit::WebWorkerClient* client); virtual ~WebWorkerImpl(); - // WebCore::WorkerObjectProxy implementation. - void postMessageToWorkerObject(const WebCore::String& message); - void postExceptionToWorkerObject(const WebCore::String& errorMessage, - int lineNumber, - const WebCore::String& sourceURL); - void postConsoleMessageToWorkerObject(WebCore::MessageDestination destination, - WebCore::MessageSource source, - WebCore::MessageLevel level, - const WebCore::String& message, - int lineNumber, - const WebCore::String& sourceURL); - void confirmMessageFromWorkerObject(bool hasPendingActivity); - void reportPendingActivity(bool hasPendingActivity); - void workerContextDestroyed(); + // WebCore::WorkerObjectProxy methods: + virtual void postMessageToWorkerObject(const WebCore::String& message); + virtual void postExceptionToWorkerObject( + const WebCore::String& error_message, + int line_number, + const WebCore::String& source_url); + virtual void postConsoleMessageToWorkerObject( + WebCore::MessageDestination destination, + WebCore::MessageSource source, + WebCore::MessageLevel level, + const WebCore::String& message, + int line_number, + const WebCore::String& source_url); + virtual void confirmMessageFromWorkerObject(bool has_pending_activity); + virtual void reportPendingActivity(bool has_pending_activity); + virtual void workerContextDestroyed(); - // WebWorker implementation. - void StartWorkerContext(const GURL& script_url, - const string16& user_agent, - const string16& source_code); - void TerminateWorkerContext(); - void PostMessageToWorkerContext(const string16& message); - void WorkerObjectDestroyed(); + // WebWorker methods: + virtual void startWorkerContext(const WebKit::WebURL& script_url, + const WebKit::WebString& user_agent, + const WebKit::WebString& source_code); + virtual void terminateWorkerContext(); + virtual void postMessageToWorkerContext(const WebKit::WebString& message); + virtual void workerObjectDestroyed(); private: static void PostMessageToWorkerContextTask( @@ -60,7 +62,7 @@ class WebWorkerImpl: public WebCore::WorkerObjectProxy, WebWorkerImpl* this_ptr, const WebCore::String& message); - WebWorkerClient* client_; + WebKit::WebWorkerClient* client_; WTF::RefPtr<WebCore::WorkerThread> worker_thread_; DISALLOW_COPY_AND_ASSIGN(WebWorkerImpl); diff --git a/webkit/glue/webworkerclient.h b/webkit/glue/webworkerclient.h deleted file mode 100644 index 7938aa1..0000000 --- a/webkit/glue/webworkerclient.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef WEBKIT_GLUE_WEBWORKERCLIENT_H_ -#define WEBKIT_GLUE_WEBWORKERCLIENT_H_ - -#include "base/string16.h" - -// This is a version of the WebCore::WorkerObjectProxy interface that uses -// Chrome data types. -class WebWorkerClient { - public: - virtual ~WebWorkerClient() { } - - // These functions are called on the worker thread. - virtual void PostMessageToWorkerObject(const string16& message) = 0; - virtual void PostExceptionToWorkerObject( - const string16& error_message, - int line_number, - const string16& source_url) = 0; - // destination, source, and level are the int values of the corresponding - // WebKit enums. This avoids duplicating the enums and having to stay up to - // date. - virtual void PostConsoleMessageToWorkerObject( - int destination, - int source, - int level, - const string16& message, - int line_number, - const string16& source_url) = 0; - virtual void ConfirmMessageFromWorkerObject(bool has_pending_activity) = 0; - virtual void ReportPendingActivity(bool has_pending_activity) = 0; - virtual void WorkerContextDestroyed() = 0; -}; - -#endif // #ifndef WEBKIT_GLUE_WEBWORKERCLIENT_H_ diff --git a/webkit/glue/webworkerclient_impl.cc b/webkit/glue/webworkerclient_impl.cc index 68cd330..add7eeb 100644 --- a/webkit/glue/webworkerclient_impl.cc +++ b/webkit/glue/webworkerclient_impl.cc @@ -23,8 +23,15 @@ #include "webkit/glue/webframe_impl.h" #include "webkit/glue/webview_delegate.h" #include "webkit/glue/webview_impl.h" -#include "webkit/glue/webworker.h" +#include "third_party/WebKit/WebKit/chromium/public/WebConsoleMessage.h" +#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h" +#include "third_party/WebKit/WebKit/chromium/public/WebWorker.h" +using WebKit::WebConsoleMessage; +using WebKit::WebScriptSource; +using WebKit::WebString; +using WebKit::WebWorker; +using WebKit::WebWorkerClient; // When WebKit creates a WorkerContextProxy object, we check if we're in the // renderer or worker process. If the latter, then we just use @@ -71,16 +78,17 @@ void WebWorkerClientImpl::set_webworker(WebWorker* webworker) { } void WebWorkerClientImpl::startWorkerContext( - const WebCore::KURL& scriptURL, - const WebCore::String& userAgent, - const WebCore::String& sourceCode) { + const WebCore::KURL& script_url, + const WebCore::String& user_agent, + const WebCore::String& source_code) { // Worker.terminate() could be called from JS before the context is started. if (asked_to_terminate_) return; - webworker_->StartWorkerContext(webkit_glue::KURLToGURL(scriptURL), - webkit_glue::StringToString16(userAgent), - webkit_glue::StringToString16(sourceCode)); + webworker_->startWorkerContext( + webkit_glue::KURLToWebURL(script_url), + webkit_glue::StringToWebString(user_agent), + webkit_glue::StringToWebString(source_code)); } void WebWorkerClientImpl::terminateWorkerContext() { @@ -88,7 +96,7 @@ void WebWorkerClientImpl::terminateWorkerContext() { return; asked_to_terminate_ = true; - webworker_->TerminateWorkerContext(); + webworker_->terminateWorkerContext(); } void WebWorkerClientImpl::postMessageToWorkerContext( @@ -98,8 +106,8 @@ void WebWorkerClientImpl::postMessageToWorkerContext( return; ++unconfirmed_message_count_; - webworker_->PostMessageToWorkerContext( - webkit_glue::StringToString16(message)); + webworker_->postMessageToWorkerContext( + webkit_glue::StringToWebString(message)); } bool WebWorkerClientImpl::hasPendingActivity() const { @@ -108,51 +116,52 @@ bool WebWorkerClientImpl::hasPendingActivity() const { } void WebWorkerClientImpl::workerObjectDestroyed() { - webworker_->WorkerObjectDestroyed(); + webworker_->workerObjectDestroyed(); // The lifetime of this proxy is controlled by the worker. delete this; } -void WebWorkerClientImpl::PostMessageToWorkerObject(const string16& message) { - worker_->dispatchMessage(webkit_glue::String16ToString(message)); +void WebWorkerClientImpl::postMessageToWorkerObject(const WebString& message) { + worker_->dispatchMessage(webkit_glue::WebStringToString(message)); } -void WebWorkerClientImpl::PostExceptionToWorkerObject( - const string16& error_message, +void WebWorkerClientImpl::postExceptionToWorkerObject( + const WebString& error_message, int line_number, - const string16& source_url) { + const WebString& source_url) { script_execution_context_->reportException( - webkit_glue::String16ToString(error_message), + webkit_glue::WebStringToString(error_message), line_number, - webkit_glue::String16ToString(source_url)); + webkit_glue::WebStringToString(source_url)); } -void WebWorkerClientImpl::PostConsoleMessageToWorkerObject( - int destination, - int source, - int level, - const string16& message, +void WebWorkerClientImpl::postConsoleMessageToWorkerObject( + int destination_id, + int source_id, + int message_level, + const WebString& message, int line_number, - const string16& source_url) { + const WebString& source_url) { script_execution_context_->addMessage( - static_cast<WebCore::MessageDestination>(destination), - static_cast<WebCore::MessageSource>(source), - static_cast<WebCore::MessageLevel>(level), - webkit_glue::String16ToString(message), + static_cast<WebCore::MessageDestination>(destination_id), + static_cast<WebCore::MessageSource>(source_id), + static_cast<WebCore::MessageLevel>(message_level), + webkit_glue::WebStringToString(message), line_number, - webkit_glue::String16ToString(source_url)); + webkit_glue::WebStringToString(source_url)); } -void WebWorkerClientImpl::ConfirmMessageFromWorkerObject(bool has_pending_activity) { +void WebWorkerClientImpl::confirmMessageFromWorkerObject( + bool has_pending_activity) { --unconfirmed_message_count_; } -void WebWorkerClientImpl::ReportPendingActivity(bool has_pending_activity) { +void WebWorkerClientImpl::reportPendingActivity(bool has_pending_activity) { worker_context_had_pending_activity_ = has_pending_activity; } -void WebWorkerClientImpl::WorkerContextDestroyed() { +void WebWorkerClientImpl::workerContextDestroyed() { } #endif diff --git a/webkit/glue/webworkerclient_impl.h b/webkit/glue/webworkerclient_impl.h index 5a8a4cd..847b341 100644 --- a/webkit/glue/webworkerclient_impl.h +++ b/webkit/glue/webworkerclient_impl.h @@ -7,51 +7,54 @@ #if ENABLE(WORKERS) -#include "webkit/glue/webworkerclient.h" +#include "third_party/WebKit/WebKit/chromium/public/WebWorkerClient.h" #include "WorkerContextProxy.h" #include <wtf/RefPtr.h> -class WebWorker; - namespace WebCore { class ScriptExecutionContext; -}; +} +namespace WebKit { +class WebWorker; +} // 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 // IPC. class WebWorkerClientImpl : public WebCore::WorkerContextProxy, - public WebWorkerClient { + public WebKit::WebWorkerClient { public: WebWorkerClientImpl(WebCore::Worker* worker); - void set_webworker(WebWorker* webworker); + void set_webworker(WebKit::WebWorker* webworker); - // WebCore::WorkerContextProxy implementation - void startWorkerContext(const WebCore::KURL& scriptURL, - const WebCore::String& userAgent, - const WebCore::String& sourceCode); - void terminateWorkerContext(); - void postMessageToWorkerContext(const WebCore::String& message); - bool hasPendingActivity() const; - void workerObjectDestroyed(); + // WebCore::WorkerContextProxy methods: + virtual void startWorkerContext(const WebCore::KURL& script_url, + const WebCore::String& user_agent, + const WebCore::String& source_code); + virtual void terminateWorkerContext(); + virtual void postMessageToWorkerContext(const WebCore::String& message); + virtual bool hasPendingActivity() const; + virtual void workerObjectDestroyed(); - // WebWorkerClient implementation. - void PostMessageToWorkerObject(const string16& message); - void PostExceptionToWorkerObject(const string16& error_message, - int line_number, - const string16& source_url); - void PostConsoleMessageToWorkerObject(int destination, - int source, - int level, - const string16& message, - int line_number, - const string16& source_url); - void ConfirmMessageFromWorkerObject(bool has_pending_activity); - void ReportPendingActivity(bool has_pending_activity); - void WorkerContextDestroyed(); + // WebWorkerClient methods: + virtual void postMessageToWorkerObject(const WebKit::WebString& message); + virtual void postExceptionToWorkerObject( + const WebKit::WebString& error_message, + int line_number, + const WebKit::WebString& source_url); + virtual void postConsoleMessageToWorkerObject( + int destination_id, + int source_id, + int message_level, + const WebKit::WebString& message, + int line_number, + const WebKit::WebString& source_url); + virtual void confirmMessageFromWorkerObject(bool has_pending_activity); + virtual void reportPendingActivity(bool has_pending_activity); + virtual void workerContextDestroyed(); private: virtual ~WebWorkerClientImpl(); @@ -60,7 +63,7 @@ class WebWorkerClientImpl : public WebCore::WorkerContextProxy, WTF::RefPtr<WebCore::ScriptExecutionContext> script_execution_context_; WebCore::Worker* worker_; - WebWorker* webworker_; + WebKit::WebWorker* webworker_; bool asked_to_terminate_; uint32 unconfirmed_message_count_; bool worker_context_had_pending_activity_; diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index a49f513..aeae028 100755 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -47,6 +47,8 @@ using WebKit::WebRect; using WebKit::WebScreenInfo; using WebKit::WebSize; using WebKit::WebString; +using WebKit::WebWorker; +using WebKit::WebWorkerClient; namespace { diff --git a/webkit/tools/test_shell/test_webview_delegate.h b/webkit/tools/test_shell/test_webview_delegate.h index c828ff8..8826752 100644 --- a/webkit/tools/test_shell/test_webview_delegate.h +++ b/webkit/tools/test_shell/test_webview_delegate.h @@ -85,7 +85,7 @@ class TestWebViewDelegate : public base::RefCounted<TestWebViewDelegate>, const std::string& mime_type, const std::string& clsid, std::string* actual_mime_type); - virtual WebWorker* CreateWebWorker(WebWorkerClient* client); + virtual WebKit::WebWorker* CreateWebWorker(WebKit::WebWorkerClient* client); virtual void OpenURL(WebView* webview, const GURL& url, const GURL& referrer, diff --git a/webkit/tools/test_shell/test_webworker_helper.cc b/webkit/tools/test_shell/test_webworker_helper.cc index e565632..6cf309c 100644 --- a/webkit/tools/test_shell/test_webworker_helper.cc +++ b/webkit/tools/test_shell/test_webworker_helper.cc @@ -19,7 +19,9 @@ #include "base/file_util.h" #include "base/path_service.h" #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" -#include "webkit/glue/webworkerclient.h" + +using WebKit::WebWorker; +using WebKit::WebWorkerClient; WebWorker* TestWebWorkerHelper::CreateWebWorker(WebWorkerClient* client) { TestWebWorkerHelper* loader = new TestWebWorkerHelper(); diff --git a/webkit/tools/test_shell/test_webworker_helper.h b/webkit/tools/test_shell/test_webworker_helper.h index 6012c95..6770678 100644 --- a/webkit/tools/test_shell/test_webworker_helper.h +++ b/webkit/tools/test_shell/test_webworker_helper.h @@ -16,17 +16,20 @@ #include <wtf/MainThread.h> class TestWebWorkerHelper; + +namespace WebKit { class WebWorker; class WebWorkerClient; +} // Function to call in test_worker DLL. -typedef WebWorker* (API_CALL *CreateWebWorkerFunc)( - WebWorkerClient* webworker_client, +typedef WebKit::WebWorker* (API_CALL *CreateWebWorkerFunc)( + WebKit::WebWorkerClient* webworker_client, TestWebWorkerHelper* webworker_helper);; class TestWebWorkerHelper { public: - static WebWorker* CreateWebWorker(WebWorkerClient* client); + static WebKit::WebWorker* CreateWebWorker(WebKit::WebWorkerClient* client); TestWebWorkerHelper(); ~TestWebWorkerHelper(); diff --git a/webkit/tools/test_shell/test_worker/test_webworker.cc b/webkit/tools/test_shell/test_worker/test_webworker.cc index 0be6977..6b073b5 100644 --- a/webkit/tools/test_shell/test_worker/test_webworker.cc +++ b/webkit/tools/test_shell/test_worker/test_webworker.cc @@ -11,10 +11,29 @@ #include "base/compiler_specific.h" #include "base/task.h" #undef LOG -#include "webkit/glue/webworkerclient.h" #include "webkit/glue/webworker_impl.h" #include "webkit/tools/test_shell/test_webworker_helper.h" +using WebKit::WebString; +using WebKit::WebURL; +using WebKit::WebWorker; +using WebKit::WebWorkerClient; + +// We use this class to pass a WebString between threads. This works by +// copying to a string16 which is itself safe to pass between threads. +// TODO(jam): Remove this once all worker callbacks happen on the main thread. +class ThreadSafeWebString { + public: + explicit ThreadSafeWebString(const WebString& str) + : str_(str) { + } + operator WebString() const { + return str_; + } + private: + string16 str_; +}; + TestWebWorker::TestWebWorker(WebWorkerClient* client, TestWebWorkerHelper* webworker_helper) : webworkerclient_delegate_(client), @@ -29,125 +48,124 @@ TestWebWorker::~TestWebWorker() { webworker_helper_->Unload(); } -void TestWebWorker::StartWorkerContext(const GURL& script_url, - const string16& user_agent, - const string16& source_code) { +void TestWebWorker::startWorkerContext(const WebURL& script_url, + const WebString& user_agent, + const WebString& source_code) { webworker_impl_ = new WebWorkerImpl(this); - webworker_impl_->StartWorkerContext(script_url, - user_agent, - source_code); + webworker_impl_->startWorkerContext(script_url, user_agent, source_code); for (size_t i = 0; i < queued_messages_.size(); ++i) - webworker_impl_->PostMessageToWorkerContext(queued_messages_[i]); + webworker_impl_->postMessageToWorkerContext(queued_messages_[i]); queued_messages_.clear(); } -void TestWebWorker::TerminateWorkerContext() { +void TestWebWorker::terminateWorkerContext() { if (webworker_impl_) - webworker_impl_->TerminateWorkerContext(); + webworker_impl_->terminateWorkerContext(); } -void TestWebWorker::PostMessageToWorkerContext(const string16& message) { +void TestWebWorker::postMessageToWorkerContext(const WebString& message) { if (webworker_impl_) - webworker_impl_->PostMessageToWorkerContext(message); + webworker_impl_->postMessageToWorkerContext(message); else queued_messages_.push_back(message); } -void TestWebWorker::WorkerObjectDestroyed() { +void TestWebWorker::workerObjectDestroyed() { if (webworker_impl_) - webworker_impl_->WorkerObjectDestroyed(); + webworker_impl_->workerObjectDestroyed(); webworkerclient_delegate_ = NULL; Release(); // Releases the reference held for worker object. } -void TestWebWorker::PostMessageToWorkerObject(const string16& message) { +void TestWebWorker::postMessageToWorkerObject(const WebString& message) { if (webworker_helper_->IsMainThread()) { if (webworkerclient_delegate_) - webworkerclient_delegate_->PostMessageToWorkerObject(message); + webworkerclient_delegate_->postMessageToWorkerObject(message); } else { webworker_helper_->DispatchToMainThread( InvokeMainThreadMethod, NewRunnableMethod( - this, &TestWebWorker::PostMessageToWorkerObject, message)); + this, &TestWebWorker::postMessageToWorkerObject, + ThreadSafeWebString(message))); } } -void TestWebWorker::PostExceptionToWorkerObject(const string16& error_message, +void TestWebWorker::postExceptionToWorkerObject(const WebString& error_message, int line_number, - const string16& source_url) { + const WebString& source_url) { if (webworker_helper_->IsMainThread()) { if (webworkerclient_delegate_) - webworkerclient_delegate_->PostExceptionToWorkerObject(error_message, + webworkerclient_delegate_->postExceptionToWorkerObject(error_message, line_number, source_url); } else { webworker_helper_->DispatchToMainThread( InvokeMainThreadMethod, NewRunnableMethod( - this, &TestWebWorker::PostExceptionToWorkerObject, - error_message, line_number, source_url)); + this, &TestWebWorker::postExceptionToWorkerObject, + ThreadSafeWebString(error_message), line_number, + ThreadSafeWebString(source_url))); } } -void TestWebWorker::PostConsoleMessageToWorkerObject( - int destination, - int source, - int level, - const string16& message, +void TestWebWorker::postConsoleMessageToWorkerObject( + int destination_id, + int source_id, + int message_level, + const WebString& message, int line_number, - const string16& source_url) { + const WebString& source_url) { if (webworker_helper_->IsMainThread()) { if (webworkerclient_delegate_) - webworkerclient_delegate_->PostConsoleMessageToWorkerObject(destination, - source, - level, - message, - line_number, - source_url); + webworkerclient_delegate_->postConsoleMessageToWorkerObject( + destination_id, source_id, message_level, message, line_number, + source_url); } else { webworker_helper_->DispatchToMainThread( InvokeMainThreadMethod, NewRunnableMethod( - this, &TestWebWorker::PostConsoleMessageToWorkerObject, - destination, source, level, message, line_number, source_url)); + this, &TestWebWorker::postConsoleMessageToWorkerObject, + destination_id, source_id, message_level, + ThreadSafeWebString(message), line_number, + ThreadSafeWebString(source_url))); } } -void TestWebWorker::ConfirmMessageFromWorkerObject(bool has_pending_activity) { +void TestWebWorker::confirmMessageFromWorkerObject(bool has_pending_activity) { if (webworker_helper_->IsMainThread()) { if (webworkerclient_delegate_) - webworkerclient_delegate_->ConfirmMessageFromWorkerObject( + webworkerclient_delegate_->confirmMessageFromWorkerObject( has_pending_activity); } else { webworker_helper_->DispatchToMainThread( InvokeMainThreadMethod, NewRunnableMethod( - this, &TestWebWorker::ConfirmMessageFromWorkerObject, + this, &TestWebWorker::confirmMessageFromWorkerObject, has_pending_activity)); } } -void TestWebWorker::ReportPendingActivity(bool has_pending_activity) { +void TestWebWorker::reportPendingActivity(bool has_pending_activity) { if (webworker_helper_->IsMainThread()) { if (webworkerclient_delegate_) - webworkerclient_delegate_->ReportPendingActivity(has_pending_activity); + webworkerclient_delegate_->reportPendingActivity(has_pending_activity); } else { webworker_helper_->DispatchToMainThread( InvokeMainThreadMethod, NewRunnableMethod( - this, &TestWebWorker::ReportPendingActivity, + this, &TestWebWorker::reportPendingActivity, has_pending_activity)); } } -void TestWebWorker::WorkerContextDestroyed() { +void TestWebWorker::workerContextDestroyed() { if (webworker_helper_->IsMainThread()) { if (webworkerclient_delegate_) - webworkerclient_delegate_->WorkerContextDestroyed(); + webworkerclient_delegate_->workerContextDestroyed(); Release(); // Releases the reference held for worker context object. } else { webworker_impl_ = NULL; webworker_helper_->DispatchToMainThread( InvokeMainThreadMethod, NewRunnableMethod( - this, &TestWebWorker::WorkerContextDestroyed)); + this, &TestWebWorker::workerContextDestroyed)); } } diff --git a/webkit/tools/test_shell/test_worker/test_webworker.h b/webkit/tools/test_shell/test_worker/test_webworker.h index aa192e7..c3f3ddc 100644 --- a/webkit/tools/test_shell/test_worker/test_webworker.h +++ b/webkit/tools/test_shell/test_worker/test_webworker.h @@ -11,42 +11,43 @@ #include "base/basictypes.h" #include "base/ref_counted.h" -#include "webkit/glue/webworker.h" -#include "webkit/glue/webworkerclient.h" +#include "third_party/WebKit/WebKit/chromium/public/WebString.h" +#include "third_party/WebKit/WebKit/chromium/public/WebWorker.h" +#include "third_party/WebKit/WebKit/chromium/public/WebWorkerClient.h" class GURL; class TestWebWorkerHelper; -class TestWebWorker : public WebWorker, - public WebWorkerClient, +class TestWebWorker : public WebKit::WebWorker, + public WebKit::WebWorkerClient, public base::RefCounted<TestWebWorker> { public: TestWebWorker(WebWorkerClient* client, TestWebWorkerHelper* webworker_helper); - // WebWorker implementation. - virtual void StartWorkerContext(const GURL& script_url, - const string16& user_agent, - const string16& source_code); - virtual void TerminateWorkerContext(); - virtual void PostMessageToWorkerContext(const string16& message); - virtual void WorkerObjectDestroyed(); + // WebWorker methods: + virtual void startWorkerContext(const WebKit::WebURL& script_url, + const WebKit::WebString& user_agent, + const WebKit::WebString& source_code); + virtual void terminateWorkerContext(); + virtual void postMessageToWorkerContext(const WebKit::WebString&); + virtual void workerObjectDestroyed(); - // WebWorkerClient implementation. - virtual void PostMessageToWorkerObject(const string16& message); - virtual void PostExceptionToWorkerObject( - const string16& error_message, + // WebWorkerClient methods: + virtual void postMessageToWorkerObject(const WebKit::WebString& message); + virtual void postExceptionToWorkerObject( + const WebKit::WebString& error_message, int line_number, - const string16& source_url); - virtual void PostConsoleMessageToWorkerObject( - int destination, - int source, - int level, - const string16& message, + const WebKit::WebString& source_url); + virtual void postConsoleMessageToWorkerObject( + int destination_id, + int source_id, + int message_level, + const WebKit::WebString& message, int line_number, - const string16& source_url); - virtual void ConfirmMessageFromWorkerObject(bool has_pending_activity); - virtual void ReportPendingActivity(bool has_pending_activity); - virtual void WorkerContextDestroyed(); + const WebKit::WebString& source_url); + virtual void confirmMessageFromWorkerObject(bool has_pending_activity); + virtual void reportPendingActivity(bool has_pending_activity); + virtual void workerContextDestroyed(); private: friend class base::RefCounted<TestWebWorker>; @@ -54,10 +55,10 @@ class TestWebWorker : public WebWorker, static void InvokeMainThreadMethod(void* param); - WebWorkerClient* webworkerclient_delegate_; - WebWorker* webworker_impl_; + WebKit::WebWorkerClient* webworkerclient_delegate_; + WebKit::WebWorker* webworker_impl_; TestWebWorkerHelper* webworker_helper_; - std::vector<string16> queued_messages_; + std::vector<WebKit::WebString> queued_messages_; DISALLOW_COPY_AND_ASSIGN(TestWebWorker); }; diff --git a/webkit/tools/test_shell/test_worker/test_worker_main.cc b/webkit/tools/test_shell/test_worker/test_worker_main.cc index 7fe6b61..6695a11 100644 --- a/webkit/tools/test_shell/test_worker/test_worker_main.cc +++ b/webkit/tools/test_shell/test_worker/test_worker_main.cc @@ -15,12 +15,13 @@ #include "third_party/WebKit/WebKit/chromium/public/WebString.h" #include "webkit/glue/resource_loader_bridge.h" #include "webkit/glue/webkit_glue.h" -#include "webkit/glue/webworker.h" #include "webkit/glue/webkitclient_impl.h" -#include "webkit/glue/webworkerclient.h" #include "webkit/tools/test_shell/test_webworker_helper.h" #include "webkit/tools/test_shell/test_worker/test_webworker.h" +using WebKit::WebWorker; +using WebKit::WebWorkerClient; + // Create a global AtExitManager so that our code can use code from base that // uses Singletons, for example. We don't care about static constructors here. static base::AtExitManager global_at_exit_manager; |