Commit 7442ffad authored by dslomov@google.com's avatar dslomov@google.com

https://bugs.webkit.org/show_bug.cgi?id=61016

[WebWorkers][Chromium] Use v8 Isolates for in-process implementation of WebWorkers.
This adds an implementation of in-process dedicated workers to chromium port.
The crux of the matter is the reimplementation of WebWorkerClientImpl. WebWorkerClientImpl now
implements all three of Worker{Loader,Context,Object}Proxies and delegates the implementation to
WebKit's standard WorkerMessagingProxy.
For now, we have 3 implementations of workers in chromium WebKit:
  - In-process dedicated workers (this checkin)
  - Inter-process shared workers
  - Inter-process dedicated workers (defunct after this checkin)
This patch extracts some new common interfaces (NewWebWorkerBase and NewWebWorkerClient) for these
three implementations.
Removing the remainings of inter-process dedicated workers -related classes is left for a separate patch
(it will require coordinated changes on chromuium side).

Reviewed by David Levin.

* public/WebCommonWorkerClient.h:
* src/DatabaseObserver.cpp:
(WebKit::AllowDatabaseMainThreadBridge::create):
(WebKit::AllowDatabaseMainThreadBridge::AllowDatabaseMainThreadBridge):
(WebKit::AllowDatabaseMainThreadBridge::allowDatabaseTask):
(WebKit::allowDatabaseForWorker):
(WebCore::DatabaseObserver::canEstablishDatabase):
* src/LocalFileSystemChromium.cpp:
(WebCore::openFileSystemHelper):
* src/WebSharedWorkerImpl.h:
(WebKit::WebSharedWorkerImpl::newCommonClient):
* src/WebWorkerBase.h:
(WebKit::WebWorkerBase::view):
* src/WebWorkerClientImpl.cpp:
(WebKit::WebWorkerClientImpl::createWorkerContextProxy):
(WebKit::WebWorkerClientImpl::startWorkerContext):
(WebKit::WebWorkerClientImpl::terminateWorkerContext):
(WebKit::WebWorkerClientImpl::postMessageToWorkerContext):
(WebKit::WebWorkerClientImpl::hasPendingActivity):
(WebKit::WebWorkerClientImpl::workerObjectDestroyed):
(WebKit::WebWorkerClientImpl::connectToInspector):
(WebKit::WebWorkerClientImpl::disconnectFromInspector):
(WebKit::WebWorkerClientImpl::sendMessageToInspector):
(WebKit::WebWorkerClientImpl::postMessageToPageInspector):
(WebKit::WebWorkerClientImpl::postTaskToLoader):
(WebKit::WebWorkerClientImpl::postTaskForModeToWorkerContext):
(WebKit::WebWorkerClientImpl::postMessageToWorkerObject):
(WebKit::WebWorkerClientImpl::confirmMessageFromWorkerObject):
(WebKit::WebWorkerClientImpl::reportPendingActivity):
(WebKit::WebWorkerClientImpl::workerContextClosed):
(WebKit::WebWorkerClientImpl::postExceptionToWorkerObject):
(WebKit::WebWorkerClientImpl::postConsoleMessageToWorkerObject):
(WebKit::WebWorkerClientImpl::workerContextDestroyed):
(WebKit::WebWorkerClientImpl::allowFileSystem):
(WebKit::WebWorkerClientImpl::openFileSystem):
(WebKit::WebWorkerClientImpl::allowDatabase):
(WebKit::WebWorkerClientImpl::dispatchDevToolsMessage):
(WebKit::WebWorkerClientImpl::view):
(WebKit::WebWorkerClientImpl::WebWorkerClientImpl):
(WebKit::WebWorkerClientImpl::~WebWorkerClientImpl):
* src/WebWorkerClientImpl.h:
(WebKit::WebWorkerClientImpl::newCommonClient):
* src/WebWorkerImpl.cpp:
(WebKit::WebWorkerImpl::newCommonClient):
* src/WebWorkerImpl.h:
* src/WorkerFileSystemCallbacksBridge.cpp:
(WebKit::WorkerFileSystemCallbacksBridge::postOpenFileSystemToMainThread):
(WebKit::WorkerFileSystemCallbacksBridge::openFileSystemOnMainThread):
* src/WorkerFileSystemCallbacksBridge.h:

git-svn-id: svn://svn.chromium.org/blink/trunk@93330 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent a280e074
2011-08-15 Dmitry Lomov <dslomov@google.com>
https://bugs.webkit.org/show_bug.cgi?id=61016
[WebWorkers][Chromium] Use v8 Isolates for in-process implementation of WebWorkers.
This adds an implementation of in-process dedicated workers to chromium port.
The crux of the matter is the reimplementation of WebWorkerClientImpl. WebWorkerClientImpl now
implements all three of Worker{Loader,Context,Object}Proxies and delegates the implementation to
WebKit's standard WorkerMessagingProxy.
For now, we have 3 implementations of workers in chromium WebKit:
- In-process dedicated workers (this checkin)
- Inter-process shared workers
- Inter-process dedicated workers (defunct after this checkin)
This patch extracts some new common interfaces (NewWebWorkerBase and NewWebWorkerClient) for these
three implementations.
Removing the remainings of inter-process dedicated workers -related classes is left for a separate patch
(it will require coordinated changes on chromuium side).
Reviewed by David Levin.
* public/WebCommonWorkerClient.h:
* src/DatabaseObserver.cpp:
(WebKit::AllowDatabaseMainThreadBridge::create):
(WebKit::AllowDatabaseMainThreadBridge::AllowDatabaseMainThreadBridge):
(WebKit::AllowDatabaseMainThreadBridge::allowDatabaseTask):
(WebKit::allowDatabaseForWorker):
(WebCore::DatabaseObserver::canEstablishDatabase):
* src/LocalFileSystemChromium.cpp:
(WebCore::openFileSystemHelper):
* src/WebSharedWorkerImpl.h:
(WebKit::WebSharedWorkerImpl::newCommonClient):
* src/WebWorkerBase.h:
(WebKit::WebWorkerBase::view):
* src/WebWorkerClientImpl.cpp:
(WebKit::WebWorkerClientImpl::createWorkerContextProxy):
(WebKit::WebWorkerClientImpl::startWorkerContext):
(WebKit::WebWorkerClientImpl::terminateWorkerContext):
(WebKit::WebWorkerClientImpl::postMessageToWorkerContext):
(WebKit::WebWorkerClientImpl::hasPendingActivity):
(WebKit::WebWorkerClientImpl::workerObjectDestroyed):
(WebKit::WebWorkerClientImpl::connectToInspector):
(WebKit::WebWorkerClientImpl::disconnectFromInspector):
(WebKit::WebWorkerClientImpl::sendMessageToInspector):
(WebKit::WebWorkerClientImpl::postMessageToPageInspector):
(WebKit::WebWorkerClientImpl::postTaskToLoader):
(WebKit::WebWorkerClientImpl::postTaskForModeToWorkerContext):
(WebKit::WebWorkerClientImpl::postMessageToWorkerObject):
(WebKit::WebWorkerClientImpl::confirmMessageFromWorkerObject):
(WebKit::WebWorkerClientImpl::reportPendingActivity):
(WebKit::WebWorkerClientImpl::workerContextClosed):
(WebKit::WebWorkerClientImpl::postExceptionToWorkerObject):
(WebKit::WebWorkerClientImpl::postConsoleMessageToWorkerObject):
(WebKit::WebWorkerClientImpl::workerContextDestroyed):
(WebKit::WebWorkerClientImpl::allowFileSystem):
(WebKit::WebWorkerClientImpl::openFileSystem):
(WebKit::WebWorkerClientImpl::allowDatabase):
(WebKit::WebWorkerClientImpl::dispatchDevToolsMessage):
(WebKit::WebWorkerClientImpl::view):
(WebKit::WebWorkerClientImpl::WebWorkerClientImpl):
(WebKit::WebWorkerClientImpl::~WebWorkerClientImpl):
* src/WebWorkerClientImpl.h:
(WebKit::WebWorkerClientImpl::newCommonClient):
* src/WebWorkerImpl.cpp:
(WebKit::WebWorkerImpl::newCommonClient):
* src/WebWorkerImpl.h:
* src/WorkerFileSystemCallbacksBridge.cpp:
(WebKit::WorkerFileSystemCallbacksBridge::postOpenFileSystemToMainThread):
(WebKit::WorkerFileSystemCallbacksBridge::openFileSystemOnMainThread):
* src/WorkerFileSystemCallbacksBridge.h:
2011-08-18 James Robinson <jamesr@chromium.org> 2011-08-18 James Robinson <jamesr@chromium.org>
[chromium] Draw the root/"non-composited content" in compositor side [chromium] Draw the root/"non-composited content" in compositor side
......
...@@ -44,12 +44,24 @@ class WebString; ...@@ -44,12 +44,24 @@ class WebString;
class WebWorker; class WebWorker;
class WebWorkerClient; class WebWorkerClient;
class NewWebCommonWorkerClient {
public:
// Called on the main webkit thread before opening a web database.
virtual bool allowDatabase(WebFrame*, const WebString& name, const WebString& displayName, unsigned long estimatedSize) = 0;
// Called on the main webkit thread before opening a file system.
virtual bool allowFileSystem() = 0;
// Called on the main webkit thread before opening a file system.
virtual void openFileSystem(WebFileSystem::Type, long long size, bool create, WebFileSystemCallbacks*) = 0;
};
// Provides an interface back to the in-page script object for a worker. // Provides an interface back to the in-page script object for a worker.
// This interface contains common APIs used by both shared and dedicated // This interface contains common APIs used by both shared and dedicated
// workers. // workers.
// All functions are expected to be called back on the thread that created // All functions are expected to be called back on the thread that created
// the Worker object, unless noted. // the Worker object, unless noted.
class WebCommonWorkerClient { class WebCommonWorkerClient : public NewWebCommonWorkerClient {
public: public:
virtual void postExceptionToWorkerObject( virtual void postExceptionToWorkerObject(
const WebString& errorString, int lineNumber, const WebString& errorString, int lineNumber,
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
#include "WebPermissionClient.h" #include "WebPermissionClient.h"
#include "WebSecurityOrigin.h" #include "WebSecurityOrigin.h"
#include "WebViewImpl.h" #include "WebViewImpl.h"
#include "WebWorkerImpl.h" #include "WebWorkerBase.h"
#include "WorkerContext.h" #include "WorkerContext.h"
#include "WorkerLoaderProxy.h" #include "WorkerLoaderProxy.h"
#include "WorkerScriptController.h" #include "WorkerScriptController.h"
...@@ -64,7 +64,7 @@ static const char allowDatabaseMode[] = "allowDatabaseMode"; ...@@ -64,7 +64,7 @@ static const char allowDatabaseMode[] = "allowDatabaseMode";
// call back to the worker context. // call back to the worker context.
class AllowDatabaseMainThreadBridge : public ThreadSafeRefCounted<AllowDatabaseMainThreadBridge> { class AllowDatabaseMainThreadBridge : public ThreadSafeRefCounted<AllowDatabaseMainThreadBridge> {
public: public:
static PassRefPtr<AllowDatabaseMainThreadBridge> create(WebCore::WorkerLoaderProxy* workerLoaderProxy, const WTF::String& mode, WebCommonWorkerClient* commonClient, WebFrame* frame, const WTF::String& name, const WTF::String& displayName, unsigned long estimatedSize) static PassRefPtr<AllowDatabaseMainThreadBridge> create(WebCore::WorkerLoaderProxy* workerLoaderProxy, const WTF::String& mode, NewWebCommonWorkerClient* commonClient, WebFrame* frame, const WTF::String& name, const WTF::String& displayName, unsigned long estimatedSize)
{ {
return adoptRef(new AllowDatabaseMainThreadBridge(workerLoaderProxy, mode, commonClient, frame, name, displayName, estimatedSize)); return adoptRef(new AllowDatabaseMainThreadBridge(workerLoaderProxy, mode, commonClient, frame, name, displayName, estimatedSize));
} }
...@@ -92,7 +92,7 @@ public: ...@@ -92,7 +92,7 @@ public:
} }
private: private:
AllowDatabaseMainThreadBridge(WebCore::WorkerLoaderProxy* workerLoaderProxy, const WTF::String& mode, WebCommonWorkerClient* commonClient, WebFrame* frame, const WTF::String& name, const WTF::String& displayName, unsigned long estimatedSize) AllowDatabaseMainThreadBridge(WebCore::WorkerLoaderProxy* workerLoaderProxy, const WTF::String& mode, NewWebCommonWorkerClient* commonClient, WebFrame* frame, const WTF::String& name, const WTF::String& displayName, unsigned long estimatedSize)
: m_workerLoaderProxy(workerLoaderProxy) : m_workerLoaderProxy(workerLoaderProxy)
, m_mode(mode) , m_mode(mode)
{ {
...@@ -103,7 +103,7 @@ private: ...@@ -103,7 +103,7 @@ private:
WebCore::AllowCrossThreadAccess(this))); WebCore::AllowCrossThreadAccess(this)));
} }
static void allowDatabaseTask(WebCore::ScriptExecutionContext* context, WebCommonWorkerClient* commonClient, WebFrame* frame, const WTF::String name, const WTF::String displayName, unsigned long estimatedSize, PassRefPtr<AllowDatabaseMainThreadBridge> bridge) static void allowDatabaseTask(WebCore::ScriptExecutionContext* context, NewWebCommonWorkerClient* commonClient, WebFrame* frame, const WTF::String name, const WTF::String displayName, unsigned long estimatedSize, PassRefPtr<AllowDatabaseMainThreadBridge> bridge)
{ {
if (commonClient) if (commonClient)
bridge->signalCompleted(commonClient->allowDatabase(frame, name, displayName, estimatedSize)); bridge->signalCompleted(commonClient->allowDatabase(frame, name, displayName, estimatedSize));
...@@ -122,7 +122,7 @@ private: ...@@ -122,7 +122,7 @@ private:
WTF::String m_mode; WTF::String m_mode;
}; };
bool allowDatabaseForWorker(WebCommonWorkerClient* commonClient, WebFrame* frame, const WebString& name, const WebString& displayName, unsigned long estimatedSize) bool allowDatabaseForWorker(NewWebCommonWorkerClient* commonClient, WebFrame* frame, const WebString& name, const WebString& displayName, unsigned long estimatedSize)
{ {
WebCore::WorkerScriptController* controller = WebCore::WorkerScriptController::controllerForContext(); WebCore::WorkerScriptController* controller = WebCore::WorkerScriptController::controllerForContext();
WebCore::WorkerContext* workerContext = controller->workerContext(); WebCore::WorkerContext* workerContext = controller->workerContext();
...@@ -165,8 +165,8 @@ bool DatabaseObserver::canEstablishDatabase(ScriptExecutionContext* scriptExecut ...@@ -165,8 +165,8 @@ bool DatabaseObserver::canEstablishDatabase(ScriptExecutionContext* scriptExecut
#if ENABLE(WORKERS) #if ENABLE(WORKERS)
WorkerContext* workerContext = static_cast<WorkerContext*>(scriptExecutionContext); WorkerContext* workerContext = static_cast<WorkerContext*>(scriptExecutionContext);
WorkerLoaderProxy* workerLoaderProxy = &workerContext->thread()->workerLoaderProxy(); WorkerLoaderProxy* workerLoaderProxy = &workerContext->thread()->workerLoaderProxy();
WebWorkerBase* webWorker = static_cast<WebWorkerBase*>(workerLoaderProxy); NewWebWorkerBase* webWorker = static_cast<NewWebWorkerBase*>(workerLoaderProxy);
return allowDatabaseForWorker(webWorker->commonClient(), webWorker->webView()->mainFrame(), name, displayName, estimatedSize); return allowDatabaseForWorker(webWorker->newCommonClient(), webWorker->view()->mainFrame(), name, displayName, estimatedSize);
#else #else
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
#endif #endif
......
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
#include "FileSystemCallback.h" #include "FileSystemCallback.h"
#include "FileSystemCallbacks.h" #include "FileSystemCallbacks.h"
#include "PlatformString.h" #include "PlatformString.h"
#include "WebCommonWorkerClient.h"
#include "WebFileError.h" #include "WebFileError.h"
#include "WebFileSystem.h" #include "WebFileSystem.h"
#include "WebFileSystemCallbacksImpl.h" #include "WebFileSystemCallbacksImpl.h"
...@@ -48,7 +47,7 @@ ...@@ -48,7 +47,7 @@
#include "WebFrameImpl.h" #include "WebFrameImpl.h"
#include "WebPermissionClient.h" #include "WebPermissionClient.h"
#include "WebViewImpl.h" #include "WebViewImpl.h"
#include "WebWorkerImpl.h" #include "WebWorkerBase.h"
#include "WorkerContext.h" #include "WorkerContext.h"
#include "WorkerFileSystemCallbacksBridge.h" #include "WorkerFileSystemCallbacksBridge.h"
#include "WorkerThread.h" #include "WorkerThread.h"
...@@ -80,7 +79,7 @@ static const char openFileSystemMode[] = "openFileSystemMode"; ...@@ -80,7 +79,7 @@ static const char openFileSystemMode[] = "openFileSystemMode";
// call back to the worker context. // call back to the worker context.
class AllowFileSystemMainThreadBridge : public ThreadSafeRefCounted<AllowFileSystemMainThreadBridge> { class AllowFileSystemMainThreadBridge : public ThreadSafeRefCounted<AllowFileSystemMainThreadBridge> {
public: public:
static PassRefPtr<AllowFileSystemMainThreadBridge> create(WebCore::WorkerLoaderProxy* workerLoaderProxy, const WTF::String& mode, WebCommonWorkerClient* commonClient) static PassRefPtr<AllowFileSystemMainThreadBridge> create(WebCore::WorkerLoaderProxy* workerLoaderProxy, const WTF::String& mode, NewWebCommonWorkerClient* commonClient)
{ {
return adoptRef(new AllowFileSystemMainThreadBridge(workerLoaderProxy, mode, commonClient)); return adoptRef(new AllowFileSystemMainThreadBridge(workerLoaderProxy, mode, commonClient));
} }
...@@ -107,7 +106,7 @@ public: ...@@ -107,7 +106,7 @@ public:
} }
private: private:
AllowFileSystemMainThreadBridge(WebCore::WorkerLoaderProxy* workerLoaderProxy, const WTF::String& mode, WebCommonWorkerClient* commonClient) AllowFileSystemMainThreadBridge(WebCore::WorkerLoaderProxy* workerLoaderProxy, const WTF::String& mode, NewWebCommonWorkerClient* commonClient)
: m_workerLoaderProxy(workerLoaderProxy) : m_workerLoaderProxy(workerLoaderProxy)
, m_mode(mode) , m_mode(mode)
{ {
...@@ -116,7 +115,7 @@ private: ...@@ -116,7 +115,7 @@ private:
AllowCrossThreadAccess(this))); AllowCrossThreadAccess(this)));
} }
static void allowFileSystemTask(WebCore::ScriptExecutionContext* context, WebCommonWorkerClient* commonClient, PassRefPtr<AllowFileSystemMainThreadBridge> bridge) static void allowFileSystemTask(WebCore::ScriptExecutionContext* context, NewWebCommonWorkerClient* commonClient, PassRefPtr<AllowFileSystemMainThreadBridge> bridge)
{ {
if (commonClient) if (commonClient)
bridge->signalCompleted(commonClient->allowFileSystem()); bridge->signalCompleted(commonClient->allowFileSystem());
...@@ -135,7 +134,7 @@ private: ...@@ -135,7 +134,7 @@ private:
WTF::String m_mode; WTF::String m_mode;
}; };
bool allowFileSystemForWorker(WebCommonWorkerClient* commonClient) bool allowFileSystemForWorker(NewWebCommonWorkerClient* commonClient)
{ {
WorkerScriptController* controller = WorkerScriptController::controllerForContext(); WorkerScriptController* controller = WorkerScriptController::controllerForContext();
WorkerContext* workerContext = controller->workerContext(); WorkerContext* workerContext = controller->workerContext();
...@@ -158,7 +157,7 @@ bool allowFileSystemForWorker(WebCommonWorkerClient* commonClient) ...@@ -158,7 +157,7 @@ bool allowFileSystemForWorker(WebCommonWorkerClient* commonClient)
return bridge->result(); return bridge->result();
} }
void openFileSystemForWorker(WebCommonWorkerClient* commonClient, WebFileSystem::Type type, long long size, bool create, WebFileSystemCallbacks* callbacks, bool synchronous) void openFileSystemForWorker(NewWebCommonWorkerClient* commonClient, WebFileSystem::Type type, long long size, bool create, WebFileSystemCallbacks* callbacks, bool synchronous)
{ {
WorkerScriptController* controller = WorkerScriptController::controllerForContext(); WorkerScriptController* controller = WorkerScriptController::controllerForContext();
WorkerContext* workerContext = controller->workerContext(); WorkerContext* workerContext = controller->workerContext();
...@@ -204,11 +203,12 @@ static void openFileSystemHelper(ScriptExecutionContext* context, AsyncFileSyste ...@@ -204,11 +203,12 @@ static void openFileSystemHelper(ScriptExecutionContext* context, AsyncFileSyste
#if ENABLE(WORKERS) #if ENABLE(WORKERS)
WorkerContext* workerContext = static_cast<WorkerContext*>(context); WorkerContext* workerContext = static_cast<WorkerContext*>(context);
WorkerLoaderProxy* workerLoaderProxy = &workerContext->thread()->workerLoaderProxy(); WorkerLoaderProxy* workerLoaderProxy = &workerContext->thread()->workerLoaderProxy();
WebWorkerBase* webWorker = static_cast<WebWorkerBase*>(workerLoaderProxy); NewWebWorkerBase* webWorker = static_cast<NewWebWorkerBase*>(workerLoaderProxy);
if (!allowFileSystemForWorker(webWorker->commonClient())) if (!allowFileSystemForWorker(webWorker->newCommonClient()))
allowed = false; allowed = false;
else else
openFileSystemForWorker(webWorker->commonClient(), static_cast<WebFileSystem::Type>(type), size, create == CreateIfNotPresent, new WebFileSystemCallbacksImpl(callbacks, type, context, synchronous), synchronous); openFileSystemForWorker(webWorker->newCommonClient(), static_cast<WebFileSystem::Type>(type), size, create == CreateIfNotPresent, new WebFileSystemCallbacksImpl(callbacks, type, context, synchronous), synchronous);
#else #else
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
#endif #endif
......
...@@ -64,6 +64,9 @@ public: ...@@ -64,6 +64,9 @@ public:
WebWorkerClient* client(); WebWorkerClient* client();
WebCommonWorkerClient* commonClient() { return m_client; } WebCommonWorkerClient* commonClient() { return m_client; }
// NewWebWorkerBase methods:
NewWebCommonWorkerClient* newCommonClient() { return m_client; }
private: private:
virtual ~WebSharedWorkerImpl(); virtual ~WebSharedWorkerImpl();
......
...@@ -34,9 +34,11 @@ ...@@ -34,9 +34,11 @@
#if ENABLE(WORKERS) #if ENABLE(WORKERS)
#include "ScriptExecutionContext.h" #include "ScriptExecutionContext.h"
#include "WebCommonWorkerClient.h"
#include "WebFrameClient.h" #include "WebFrameClient.h"
#include "WorkerLoaderProxy.h" #include "WorkerLoaderProxy.h"
#include "WorkerObjectProxy.h" #include "WorkerObjectProxy.h"
#include "WorkerThread.h"
#include <wtf/PassOwnPtr.h> #include <wtf/PassOwnPtr.h>
#include <wtf/RefPtr.h> #include <wtf/RefPtr.h>
...@@ -55,17 +57,27 @@ class WebView; ...@@ -55,17 +57,27 @@ class WebView;
class WebWorker; class WebWorker;
class WebWorkerClient; class WebWorkerClient;
// Base class for WebSharedWorkerImpl, WebWorkerClientImpl and (defunct) WebWorkerImpl
// containing common interface for shared workers and dedicated in-proc workers implementation.
//
// FIXME: Rename this class into WebWorkerBase, merge existing WebWorkerBase and WebSharedWorker.
class NewWebWorkerBase : public WebCore::WorkerLoaderProxy {
public:
virtual NewWebCommonWorkerClient* newCommonClient() = 0;
virtual WebView* view() const = 0;
};
// Base class for WebSharedWorkerImpl and WebWorkerImpl. It contains common // Base class for WebSharedWorkerImpl and WebWorkerImpl. It contains common
// code used by both implementation classes, including implementations of the // code used by both implementation classes, including implementations of the
// WorkerObjectProxy and WorkerLoaderProxy interfaces. // WorkerObjectProxy and WorkerLoaderProxy interfaces.
class WebWorkerBase : public WebCore::WorkerObjectProxy class WebWorkerBase : public WebCore::WorkerObjectProxy
, public WebCore::WorkerLoaderProxy , public NewWebWorkerBase
, public WebFrameClient { , public WebFrameClient {
public: public:
WebWorkerBase(); WebWorkerBase();
virtual ~WebWorkerBase(); virtual ~WebWorkerBase();
// WebCore::WorkerObjectProxy methods: // WebCommonWorkerBase methods:
virtual void postMessageToWorkerObject( virtual void postMessageToWorkerObject(
PassRefPtr<WebCore::SerializedScriptValue>, PassRefPtr<WebCore::SerializedScriptValue>,
PassOwnPtr<WebCore::MessagePortChannelArray>); PassOwnPtr<WebCore::MessagePortChannelArray>);
...@@ -79,6 +91,7 @@ public: ...@@ -79,6 +91,7 @@ public:
virtual void reportPendingActivity(bool); virtual void reportPendingActivity(bool);
virtual void workerContextClosed(); virtual void workerContextClosed();
virtual void workerContextDestroyed(); virtual void workerContextDestroyed();
virtual WebView* view() const { return m_webView; }
// WebCore::WorkerLoaderProxy methods: // WebCore::WorkerLoaderProxy methods:
virtual void postTaskToLoader(PassOwnPtr<WebCore::ScriptExecutionContext::Task>); virtual void postTaskToLoader(PassOwnPtr<WebCore::ScriptExecutionContext::Task>);
...@@ -92,11 +105,8 @@ public: ...@@ -92,11 +105,8 @@ public:
// Executes the given task on the main thread. // Executes the given task on the main thread.
static void dispatchTaskToMainThread(PassOwnPtr<WebCore::ScriptExecutionContext::Task>); static void dispatchTaskToMainThread(PassOwnPtr<WebCore::ScriptExecutionContext::Task>);
WebView* webView() const { return m_webView; }
virtual WebCommonWorkerClient* commonClient() = 0;
protected: protected:
virtual WebCommonWorkerClient* commonClient() = 0;
virtual WebWorkerClient* client() = 0; virtual WebWorkerClient* client() = 0;
void setWorkerThread(PassRefPtr<WebCore::WorkerThread> thread) { m_workerThread = thread; } void setWorkerThread(PassRefPtr<WebCore::WorkerThread> thread) { m_workerThread = thread; }
......
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
#include "WebKit.h" #include "WebKit.h"
#include "WebKitClient.h" #include "WebKitClient.h"
#include "WebMessagePortChannel.h" #include "WebMessagePortChannel.h"
#include "WebPermissionClient.h"
#include "WebString.h" #include "WebString.h"
#include "WebURL.h" #include "WebURL.h"
#include "WebViewImpl.h" #include "WebViewImpl.h"
...@@ -69,387 +70,164 @@ using namespace WebCore; ...@@ -69,387 +70,164 @@ using namespace WebCore;
namespace WebKit { namespace WebKit {
// When WebKit creates a WorkerContextProxy object, we check if we're in the // Chromium-specific wrapper over WorkerMessagingProxy.
// renderer or worker process. If the latter, then we just use // Delegates implementation of Worker{Loader,Context,Object}Proxy to WorkerMessagingProxy.
// WorkerMessagingProxy.
//
// If we're in the renderer process, then we need use the glue provided
// WebWorker object to talk to the worker process over IPC. The worker process
// talks to Worker* using WorkerObjectProxy, which we implement on
// WebWorkerClientImpl.
//
// Note that if we're running each worker in a separate process, then nested
// workers end up using the same codepath as the renderer process.
// static // static
WorkerContextProxy* WebWorkerClientImpl::createWorkerContextProxy(Worker* worker) WorkerContextProxy* WebWorkerClientImpl::createWorkerContextProxy(Worker* worker)
{ {
// Special behavior for multiple workers per process.
// FIXME: v8 doesn't support more than one workers per process.
// if (!worker->scriptExecutionContext()->isDocument())
// return new WorkerMessagingProxy(worker);
WebWorker* webWorker = 0;
WebWorkerClientImpl* proxy = new WebWorkerClientImpl(worker);
if (worker->scriptExecutionContext()->isDocument()) { if (worker->scriptExecutionContext()->isDocument()) {
Document* document = static_cast<Document*>( Document* document = static_cast<Document*>(worker->scriptExecutionContext());
worker->scriptExecutionContext());
WebFrameImpl* webFrame = WebFrameImpl::fromFrame(document->frame()); WebFrameImpl* webFrame = WebFrameImpl::fromFrame(document->frame());
webWorker = webFrame->client()->createWorker(webFrame, proxy); WebWorkerClientImpl* proxy = new WebWorkerClientImpl(worker, webFrame);
} else { return proxy;
WorkerScriptController* controller = WorkerScriptController::controllerForContext(); }
if (!controller) { ASSERT_NOT_REACHED();
ASSERT_NOT_REACHED(); return 0;
return 0;
}
DedicatedWorkerThread* thread = static_cast<DedicatedWorkerThread*>(controller->workerContext()->thread());
WorkerObjectProxy* workerObjectProxy = &thread->workerObjectProxy();
WebWorkerImpl* impl = reinterpret_cast<WebWorkerImpl*>(workerObjectProxy);
webWorker = impl->client()->createWorker(proxy);
}
proxy->setWebWorker(webWorker);
return proxy;
}
WebWorkerClientImpl::WebWorkerClientImpl(Worker* worker)
: m_scriptExecutionContext(worker->scriptExecutionContext())
, m_worker(worker)
, m_askedToTerminate(false)
, m_unconfirmedMessageCount(0)
, m_workerContextHadPendingActivity(false)
, m_workerThreadId(currentThread())
, m_pageInspector(0)
{
}
WebWorkerClientImpl::~WebWorkerClientImpl()
{
} }
void WebWorkerClientImpl::setWebWorker(WebWorker* webWorker) void WebWorkerClientImpl::startWorkerContext(const KURL& scriptURL, const String& userAgent, const String& sourceCode)
{ {
m_webWorker = webWorker; RefPtr<DedicatedWorkerThread> thread = DedicatedWorkerThread::create(scriptURL, userAgent, sourceCode, *this, *this);
} m_proxy->workerThreadCreated(thread);
thread->start();
void WebWorkerClientImpl::startWorkerContext(const KURL& scriptURL,
const String& userAgent,
const String& sourceCode)
{
// Worker.terminate() could be called from JS before the context is started.
if (m_askedToTerminate)
return;
if (!isMainThread()) {
WebWorkerBase::dispatchTaskToMainThread(createCallbackTask(
&startWorkerContextTask,
AllowCrossThreadAccess(this),
scriptURL.string(),
userAgent,
sourceCode));
return;
}
startWorkerContextInternal(scriptURL, userAgent, sourceCode);
}
void WebWorkerClientImpl::startWorkerContextInternal(const KURL& scriptURL, const WTF::String& userAgent, const WTF::String& sourceCode)
{
m_webWorker->startWorkerContext(scriptURL, userAgent, sourceCode);
m_workerContextHadPendingActivity = true; // Worker initialization means a pending activity.
} }
void WebWorkerClientImpl::terminateWorkerContext() void WebWorkerClientImpl::terminateWorkerContext()
{ {
if (m_askedToTerminate) m_proxy->terminateWorkerContext();
return;
m_askedToTerminate = true;
if (!isMainThread()) {
WebWorkerBase::dispatchTaskToMainThread(
createCallbackTask(&terminateWorkerContextTask, AllowCrossThreadAccess(this)));
return;
}
m_webWorker->terminateWorkerContext();
InspectorInstrumentation::workerContextTerminated(m_scriptExecutionContext.get(), this); InspectorInstrumentation::workerContextTerminated(m_scriptExecutionContext.get(), this);
} }
void WebWorkerClientImpl::postMessageToWorkerContext( void WebWorkerClientImpl::postMessageToWorkerContext(
PassRefPtr<SerializedScriptValue> message, PassRefPtr<SerializedScriptValue> value,
PassOwnPtr<MessagePortChannelArray> channels) PassOwnPtr<MessagePortChannelArray> ports)
{ {
// Worker.terminate() could be called from JS before the context is started. m_proxy->postMessageToWorkerContext(value, ports);
if (m_askedToTerminate)
return;
++m_unconfirmedMessageCount;
if (!isMainThread()) {
WebWorkerBase::dispatchTaskToMainThread(createCallbackTask(&postMessageToWorkerContextTask,
AllowCrossThreadAccess(this),
message->toWireString(),
channels));
return;
}
WebMessagePortChannelArray webChannels(channels.get() ? channels->size() : 0);
for (size_t i = 0; i < webChannels.size(); ++i) {
WebMessagePortChannel* webchannel =
(*channels)[i]->channel()->webChannelRelease();
webchannel->setClient(0);
webChannels[i] = webchannel;
}
m_webWorker->postMessageToWorkerContext(message->toWireString(), webChannels);
} }
bool WebWorkerClientImpl::hasPendingActivity() const bool WebWorkerClientImpl::hasPendingActivity() const
{ {
return !m_askedToTerminate return m_proxy->hasPendingActivity();
&& (m_unconfirmedMessageCount || m_workerContextHadPendingActivity);
} }
void WebWorkerClientImpl::workerObjectDestroyed() void WebWorkerClientImpl::workerObjectDestroyed()
{ {
if (isMainThread()) { m_proxy->workerObjectDestroyed();
m_webWorker->workerObjectDestroyed();
m_worker = 0;
}
// Even if this is called on the main thread, there could be a queued task for
// this object, so don't delete it right away.
WebWorkerBase::dispatchTaskToMainThread(createCallbackTask(&workerObjectDestroyedTask,
AllowCrossThreadAccess(this)));
} }
void WebWorkerClientImpl::connectToInspector(WorkerContextProxy::PageInspector* pageInspector) #if ENABLE(INSPECTOR)
void WebWorkerClientImpl::connectToInspector(PageInspector* inspector)
{ {
m_proxy->connectToInspector(inspector);
ASSERT(!m_pageInspector); ASSERT(!m_pageInspector);
m_pageInspector = pageInspector; m_pageInspector = inspector;
m_webWorker->attachDevTools();
} }
void WebWorkerClientImpl::disconnectFromInspector() void WebWorkerClientImpl::disconnectFromInspector()
{ {
if (!m_askedToTerminate)
m_webWorker->detachDevTools();
m_pageInspector = 0; m_pageInspector = 0;
m_proxy->disconnectFromInspector();
} }
void WebWorkerClientImpl::sendMessageToInspector(const String& message) void WebWorkerClientImpl::sendMessageToInspector(const String& message)
{ {
m_webWorker->dispatchDevToolsMessage(message); m_proxy->sendMessageToInspector(message);
} }
void WebWorkerClientImpl::postMessageToWorkerObject(const WebString& message, void WebWorkerClientImpl::postMessageToPageInspector(const String& message)
const WebMessagePortChannelArray& channels)
{ {
OwnPtr<MessagePortChannelArray> channels2; m_proxy->postMessageToPageInspector(message);
if (channels.size()) {
channels2 = adoptPtr(new MessagePortChannelArray(channels.size()));
for (size_t i = 0; i < channels.size(); ++i) {
RefPtr<PlatformMessagePortChannel> platform_channel =
PlatformMessagePortChannel::create(channels[i]);
channels[i]->setClient(platform_channel.get());
(*channels2)[i] = MessagePortChannel::create(platform_channel);
}
}
if (currentThread() != m_workerThreadId) {
m_scriptExecutionContext->postTask(createCallbackTask(&postMessageToWorkerObjectTask,
AllowCrossThreadAccess(this),
String(message),
channels2.release()));
return;
}
postMessageToWorkerObjectTask(m_scriptExecutionContext.get(), this,
message, channels2.release());
} }
#endif // ENABLE(INSPECTOR)
void WebWorkerClientImpl::postExceptionToWorkerObject(const WebString& errorMessage, void WebWorkerClientImpl::postTaskToLoader(PassOwnPtr<ScriptExecutionContext::Task> task)
int lineNumber,
const WebString& sourceURL)
{ {
if (currentThread() != m_workerThreadId) { m_proxy->postTaskToLoader(task);
m_scriptExecutionContext->postTask(createCallbackTask(&postExceptionToWorkerObjectTask,
AllowCrossThreadAccess(this),
String(errorMessage),
lineNumber,
String(sourceURL)));
return;
}
bool unhandled = m_worker->dispatchEvent(ErrorEvent::create(errorMessage,
sourceURL,
lineNumber));
if (unhandled)
m_scriptExecutionContext->reportException(errorMessage, lineNumber, sourceURL, 0);
} }
void WebWorkerClientImpl::postConsoleMessageToWorkerObject(int destination, void WebWorkerClientImpl::postTaskForModeToWorkerContext(PassOwnPtr<ScriptExecutionContext::Task> task, const String& mode)
int sourceId,
int messageType,
int messageLevel,
const WebString& message,
int lineNumber,
const WebString& sourceURL)
{ {
if (currentThread() != m_workerThreadId) { m_proxy->postTaskForModeToWorkerContext(task, mode);
m_scriptExecutionContext->postTask(createCallbackTask(&postConsoleMessageToWorkerObjectTask,
AllowCrossThreadAccess(this),
sourceId,
messageType,
messageLevel,
String(message),
lineNumber,
String(sourceURL)));
return;
}
m_scriptExecutionContext->addMessage(static_cast<MessageSource>(sourceId),
static_cast<MessageType>(messageType),
static_cast<MessageLevel>(messageLevel),
String(message), lineNumber,
String(sourceURL), 0);
} }
void WebWorkerClientImpl::postConsoleMessageToWorkerObject(int sourceId, void WebWorkerClientImpl::postMessageToWorkerObject(PassRefPtr<SerializedScriptValue> value, PassOwnPtr<MessagePortChannelArray> ports)
int messageType,
int messageLevel,
const WebString& message,
int lineNumber,
const WebString& sourceURL)
{ {
postConsoleMessageToWorkerObject(0, sourceId, messageType, messageLevel, message, lineNumber, sourceURL); m_proxy->postMessageToWorkerObject(value, ports);
} }
void WebWorkerClientImpl::confirmMessageFromWorkerObject(bool hasPendingActivity) void WebWorkerClientImpl::confirmMessageFromWorkerObject(bool hasPendingActivity)
{ {
// unconfirmed_message_count_ can only be updated on the thread where it's m_proxy->confirmMessageFromWorkerObject(hasPendingActivity);
// accessed. Otherwise there are race conditions with v8's garbage
// collection.
m_scriptExecutionContext->postTask(createCallbackTask(&confirmMessageFromWorkerObjectTask,
AllowCrossThreadAccess(this),
hasPendingActivity));
} }
void WebWorkerClientImpl::reportPendingActivity(bool hasPendingActivity) void WebWorkerClientImpl::reportPendingActivity(bool hasPendingActivity)
{ {
// See above comment in confirmMessageFromWorkerObject. m_proxy->reportPendingActivity(hasPendingActivity);
m_scriptExecutionContext->postTask(createCallbackTask(&reportPendingActivityTask,
AllowCrossThreadAccess(this),
hasPendingActivity));
}
void WebWorkerClientImpl::workerContextDestroyed()
{
InspectorInstrumentation::workerContextTerminated(m_scriptExecutionContext.get(), this);
} }
void WebWorkerClientImpl::workerContextClosed() void WebWorkerClientImpl::workerContextClosed()
{ {
m_proxy->workerContextClosed();
} }
void WebWorkerClientImpl::dispatchDevToolsMessage(const WebString& message) void WebWorkerClientImpl::postExceptionToWorkerObject(const String& errorMessage, int lineNumber, const String& sourceURL)
{ {
if (m_pageInspector) m_proxy->postExceptionToWorkerObject(errorMessage, lineNumber, sourceURL);
m_pageInspector->dispatchMessageFromWorker(message);
} }
void WebWorkerClientImpl::startWorkerContextTask(ScriptExecutionContext* context, void WebWorkerClientImpl::postConsoleMessageToWorkerObject(MessageSource source, MessageType type, MessageLevel level, const String& message, int lineNumber, const String& sourceURL)
WebWorkerClientImpl* thisPtr,
const String& scriptURL,
const String& userAgent,
const String& sourceCode)
{ {
thisPtr->startWorkerContextInternal(KURL(ParsedURLString, scriptURL), userAgent, sourceCode); m_proxy->postConsoleMessageToWorkerObject(source, type, level, message, lineNumber, sourceURL);
} }
void WebWorkerClientImpl::terminateWorkerContextTask(ScriptExecutionContext* context, void WebWorkerClientImpl::workerContextDestroyed()
WebWorkerClientImpl* thisPtr)
{ {
thisPtr->m_webWorker->terminateWorkerContext(); m_proxy->workerContextDestroyed();
InspectorInstrumentation::workerContextTerminated(m_scriptExecutionContext.get(), this);
} }
void WebWorkerClientImpl::postMessageToWorkerContextTask(ScriptExecutionContext* context, bool WebWorkerClientImpl::allowFileSystem()
WebWorkerClientImpl* thisPtr,
const String& message,
PassOwnPtr<MessagePortChannelArray> channels)
{ {
WebMessagePortChannelArray webChannels(channels.get() ? channels->size() : 0); WebKit::WebViewImpl* webView = m_webFrame->viewImpl();
return !webView->permissionClient() || webView->permissionClient()->allowFileSystem(m_webFrame);
for (size_t i = 0; i < webChannels.size(); ++i) {
webChannels[i] = (*channels)[i]->channel()->webChannelRelease();
webChannels[i]->setClient(0);
}
thisPtr->m_webWorker->postMessageToWorkerContext(message, webChannels);
} }
void WebWorkerClientImpl::workerObjectDestroyedTask(ScriptExecutionContext* context, void WebWorkerClientImpl::openFileSystem(WebFileSystem::Type type, long long size, bool create,
WebWorkerClientImpl* thisPtr) WebFileSystemCallbacks* callbacks)
{ {
if (thisPtr->m_worker) // Check we haven't alread called this. m_webFrame->client()->openFileSystem(m_webFrame, type, size, create, callbacks);
thisPtr->m_webWorker->workerObjectDestroyed();
delete thisPtr;
} }
void WebWorkerClientImpl::postMessageToWorkerObjectTask( bool WebWorkerClientImpl::allowDatabase(WebFrame*, const WebString& name, const WebString& displayName, unsigned long estimatedSize)
ScriptExecutionContext* context,
WebWorkerClientImpl* thisPtr,
const String& message,
PassOwnPtr<MessagePortChannelArray> channels)
{ {
WebKit::WebViewImpl* webView = m_webFrame->viewImpl();
if (thisPtr->m_worker) { return !webView->permissionClient() || webView->permissionClient()->allowDatabase(m_webFrame, name, displayName, estimatedSize);
OwnPtr<MessagePortArray> ports =
MessagePort::entanglePorts(*context, channels);
RefPtr<SerializedScriptValue> serializedMessage =
SerializedScriptValue::createFromWire(message);
thisPtr->m_worker->dispatchEvent(MessageEvent::create(ports.release(),
serializedMessage.release()));
}
} }
void WebWorkerClientImpl::postExceptionToWorkerObjectTask( void WebWorkerClientImpl::dispatchDevToolsMessage(const WebString& message)
ScriptExecutionContext* context,
WebWorkerClientImpl* thisPtr,
const String& errorMessage,
int lineNumber,
const String& sourceURL)
{ {
bool handled = false; if (m_pageInspector)
if (thisPtr->m_worker) m_pageInspector->dispatchMessageFromWorker(message);
handled = thisPtr->m_worker->dispatchEvent(ErrorEvent::create(errorMessage,
sourceURL,
lineNumber));
if (!handled)
thisPtr->m_scriptExecutionContext->reportException(errorMessage, lineNumber, sourceURL, 0);
} }
void WebWorkerClientImpl::postConsoleMessageToWorkerObjectTask(ScriptExecutionContext* context, WebView* WebWorkerClientImpl::view() const
WebWorkerClientImpl* thisPtr, {
int sourceId, return m_webFrame->view();
int messageType,
int messageLevel,
const String& message,
int lineNumber,
const String& sourceURL)
{
thisPtr->m_scriptExecutionContext->addMessage(static_cast<MessageSource>(sourceId),
static_cast<MessageType>(messageType),
static_cast<MessageLevel>(messageLevel),
message, lineNumber, sourceURL, 0);
} }
void WebWorkerClientImpl::confirmMessageFromWorkerObjectTask(ScriptExecutionContext* context, WebWorkerClientImpl::WebWorkerClientImpl(Worker* worker, WebFrameImpl* webFrame)
WebWorkerClientImpl* thisPtr, : m_proxy(new WorkerMessagingProxy(worker))
bool hasPendingActivity) , m_scriptExecutionContext(worker->scriptExecutionContext())
, m_webFrame(webFrame)
, m_pageInspector(0)
{ {
thisPtr->m_unconfirmedMessageCount--;
thisPtr->m_workerContextHadPendingActivity = hasPendingActivity;
} }
void WebWorkerClientImpl::reportPendingActivityTask(ScriptExecutionContext* context, WebWorkerClientImpl::~WebWorkerClientImpl()
WebWorkerClientImpl* thisPtr,
bool hasPendingActivity)
{ {
thisPtr->m_workerContextHadPendingActivity = hasPendingActivity;
} }
} // namespace WebKit } // namespace WebKit
......
...@@ -33,37 +33,40 @@ ...@@ -33,37 +33,40 @@
#if ENABLE(WORKERS) #if ENABLE(WORKERS)
#include "ScriptExecutionContext.h"
#include "WorkerContextProxy.h"
#include "WorkerLoaderProxy.h"
#include "WorkerMessagingProxy.h"
#include "WorkerObjectProxy.h"
#include "WebFileSystem.h" #include "WebFileSystem.h"
#include "WebWorkerBase.h"
#include "WebWorkerClient.h" #include "WebWorkerClient.h"
#include "WorkerContextProxy.h"
#include <wtf/OwnPtr.h> #include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h> #include <wtf/PassOwnPtr.h>
#include <wtf/RefPtr.h> #include <wtf/RefPtr.h>
namespace WebCore {
class ScriptExecutionContext;
}
namespace WebKit { namespace WebKit {
class WebWorker; class WebWorker;
class WebFrameImpl;
// The purpose of this class is to provide a WorkerContextProxy // This class provides chromium implementation for WorkerContextProxt, WorkerObjectProxy amd WorkerLoaderProxy
// implementation that we can give to WebKit. Internally, it converts the // for in-proc dedicated workers. It also acts as a bridge for workers to chromium implementation of file systems,
// data types to Chrome compatible ones so that renderer code can use it over // databases and other related functionality.
// IPC. //
// In essence, this class wraps WorkerMessagingProxy.
class WebWorkerClientImpl : public WebCore::WorkerContextProxy class WebWorkerClientImpl : public WebCore::WorkerContextProxy
, public WebWorkerClient { , public WebCore::WorkerObjectProxy
, public NewWebWorkerBase
, public NewWebCommonWorkerClient {
public: public:
WebWorkerClientImpl(WebCore::Worker*);
// WebCore::WorkerContextProxy Factory. // WebCore::WorkerContextProxy Factory.
static WebCore::WorkerContextProxy* createWorkerContextProxy(WebCore::Worker*); static WebCore::WorkerContextProxy* createWorkerContextProxy(WebCore::Worker*);
void setWebWorker(WebWorker*);
// WebCore::WorkerContextProxy methods: // WebCore::WorkerContextProxy methods:
// These are called on the thread that created the worker. In the renderer // These are called on the thread that created the worker. In the renderer
// process, this will be the main WebKit thread. In the worker process, this // process, this will be the main WebKit thread.
// will be the thread of the executing worker (not the main WebKit thread).
virtual void startWorkerContext(const WebCore::KURL&, virtual void startWorkerContext(const WebCore::KURL&,
const WTF::String&, const WTF::String&,
const WTF::String&); const WTF::String&);
...@@ -74,103 +77,48 @@ public: ...@@ -74,103 +77,48 @@ public:
virtual bool hasPendingActivity() const; virtual bool hasPendingActivity() const;
virtual void workerObjectDestroyed(); virtual void workerObjectDestroyed();
virtual void connectToInspector(WorkerContextProxy::PageInspector*); #if ENABLE(INSPECTOR)
virtual void connectToInspector(WebCore::WorkerContextProxy::PageInspector*);
virtual void disconnectFromInspector(); virtual void disconnectFromInspector();
virtual void sendMessageToInspector(const String&); virtual void sendMessageToInspector(const String&);
virtual void postMessageToPageInspector(const String&);
#endif
// WebCore::WorkerLoaderProxy methods:
virtual void postTaskToLoader(PassOwnPtr<WebCore::ScriptExecutionContext::Task>);
virtual void postTaskForModeToWorkerContext(PassOwnPtr<WebCore::ScriptExecutionContext::Task>, const String& mode);
// WebWorkerClient methods: // WebCore::WorkerObjectProxy methods:
// These are called on the main WebKit thread. virtual void postMessageToWorkerObject(PassRefPtr<WebCore::SerializedScriptValue>, PassOwnPtr<WebCore::MessagePortChannelArray>);
virtual void postMessageToWorkerObject(const WebString&, const WebMessagePortChannelArray&); virtual void postExceptionToWorkerObject(const String& errorMessage, int lineNumber, const String& sourceURL);
virtual void postExceptionToWorkerObject(const WebString&, int, const WebString&);
// FIXME: the below is for compatibility only and should be virtual void postConsoleMessageToWorkerObject(WebCore::MessageSource, WebCore::MessageType, WebCore::MessageLevel,
// removed once Chromium is updated to remove message const String& message, int lineNumber, const String& sourceURL);
// destination parameter <http://webkit.org/b/37155>.
virtual void postConsoleMessageToWorkerObject(int, int, int, int, const WebString&, int, const WebString&);
virtual void postConsoleMessageToWorkerObject(int, int, int, const WebString&, int, const WebString&);
virtual void confirmMessageFromWorkerObject(bool); virtual void confirmMessageFromWorkerObject(bool);
virtual void reportPendingActivity(bool); virtual void reportPendingActivity(bool);
virtual void workerContextClosed(); virtual void workerContextClosed();
virtual void workerContextDestroyed(); virtual void workerContextDestroyed();
virtual WebWorker* createWorker(WebWorkerClient*) { return 0; }
virtual WebNotificationPresenter* notificationPresenter() // WebWorkerClientBase methods:
{ virtual bool allowDatabase(WebFrame*, const WebString& name, const WebString& displayName, unsigned long estimatedSize);
// FIXME: Notifications not yet supported in workers. virtual bool allowFileSystem();
return 0; virtual void openFileSystem(WebFileSystem::Type, long long size, bool create,
} WebFileSystemCallbacks*);
virtual WebApplicationCacheHost* createApplicationCacheHost(WebApplicationCacheHostClient*) { return 0; }
virtual bool allowDatabase(WebFrame*, const WebString& name, const WebString& displayName, unsigned long estimatedSize)
{
ASSERT_NOT_REACHED();
return true;
}
virtual bool allowFileSystem()
{
ASSERT_NOT_REACHED();
return true;
}
virtual void dispatchDevToolsMessage(const WebString&); virtual void dispatchDevToolsMessage(const WebString&);
// WebCommentWorkerBase methods:
virtual NewWebCommonWorkerClient* newCommonClient() { return this; }
virtual WebView* view() const;
private: private:
WebWorkerClientImpl(WebCore::Worker*, WebFrameImpl*);
virtual ~WebWorkerClientImpl(); virtual ~WebWorkerClientImpl();
// Methods used to support WebWorkerClientImpl being constructed on worker WebCore::WorkerMessagingProxy* m_proxy;
// threads.
// These tasks are dispatched on the WebKit thread.
static void startWorkerContextTask(WebCore::ScriptExecutionContext* context,
WebWorkerClientImpl* thisPtr,
const WTF::String& scriptURL,
const WTF::String& userAgent,
const WTF::String& sourceCode);
static void terminateWorkerContextTask(WebCore::ScriptExecutionContext* context,
WebWorkerClientImpl* thisPtr);
static void postMessageToWorkerContextTask(WebCore::ScriptExecutionContext* context,
WebWorkerClientImpl* thisPtr,
const WTF::String& message,
PassOwnPtr<WebCore::MessagePortChannelArray> channels);
static void workerObjectDestroyedTask(WebCore::ScriptExecutionContext* context,
WebWorkerClientImpl* thisPtr);
// These tasks are dispatched on the thread that created the worker (i.e.
// main WebKit thread in renderer process, and the worker thread in the
// worker process).
static void postMessageToWorkerObjectTask(WebCore::ScriptExecutionContext* context,
WebWorkerClientImpl* thisPtr,
const WTF::String& message,
PassOwnPtr<WebCore::MessagePortChannelArray> channels);
static void postExceptionToWorkerObjectTask(WebCore::ScriptExecutionContext* context,
WebWorkerClientImpl* thisPtr,
const WTF::String& message,
int lineNumber,
const WTF::String& sourceURL);
static void postConsoleMessageToWorkerObjectTask(WebCore::ScriptExecutionContext* context,
WebWorkerClientImpl* thisPtr,
int sourceId,
int messageType,
int messageLevel,
const WTF::String& message,
int lineNumber,
const WTF::String& sourceURL);
static void confirmMessageFromWorkerObjectTask(WebCore::ScriptExecutionContext* context,
WebWorkerClientImpl* thisPtr,
bool hasPendingActivity);
static void reportPendingActivityTask(WebCore::ScriptExecutionContext* context,
WebWorkerClientImpl* thisPtr,
bool hasPendingActivity);
void startWorkerContextInternal(const WebCore::KURL& scriptURL, const WTF::String& userAgent, const WTF::String& sourceCode);
// Guard against context from being destroyed before a worker exits. // Guard against context from being destroyed before a worker exits.
RefPtr<WebCore::ScriptExecutionContext> m_scriptExecutionContext; RefPtr<WebCore::ScriptExecutionContext> m_scriptExecutionContext;
WebFrameImpl* m_webFrame;
WebCore::Worker* m_worker; WebCore::WorkerContextProxy::PageInspector* m_pageInspector;
WebWorker* m_webWorker;
bool m_askedToTerminate;
unsigned m_unconfirmedMessageCount;
bool m_workerContextHadPendingActivity;
ThreadIdentifier m_workerThreadId;
WorkerContextProxy::PageInspector* m_pageInspector;
}; };
} // namespace WebKit; } // namespace WebKit;
......
...@@ -74,6 +74,11 @@ WebWorkerImpl::~WebWorkerImpl() ...@@ -74,6 +74,11 @@ WebWorkerImpl::~WebWorkerImpl()
{ {
} }
NewWebCommonWorkerClient* WebWorkerImpl::newCommonClient()
{
return m_client;
}
WebCommonWorkerClient* WebWorkerImpl::commonClient() WebCommonWorkerClient* WebWorkerImpl::commonClient()
{ {
return m_client; return m_client;
......
...@@ -65,6 +65,9 @@ public: ...@@ -65,6 +65,9 @@ public:
virtual WebWorkerClient* client() { return m_client; } virtual WebWorkerClient* client() { return m_client; }
virtual WebCommonWorkerClient* commonClient(); virtual WebCommonWorkerClient* commonClient();
// NewWebWorkerBase methods:
virtual NewWebCommonWorkerClient* newCommonClient();
private: private:
virtual ~WebWorkerImpl(); virtual ~WebWorkerImpl();
......
...@@ -156,7 +156,7 @@ void WorkerFileSystemCallbacksBridge::stop() ...@@ -156,7 +156,7 @@ void WorkerFileSystemCallbacksBridge::stop()
} }
} }
void WorkerFileSystemCallbacksBridge::postOpenFileSystemToMainThread(WebCommonWorkerClient* commonClient, WebFileSystem::Type type, long long size, bool create, const String& mode) void WorkerFileSystemCallbacksBridge::postOpenFileSystemToMainThread(NewWebCommonWorkerClient* commonClient, WebFileSystem::Type type, long long size, bool create, const String& mode)
{ {
dispatchTaskToMainThread( dispatchTaskToMainThread(
createCallbackTask(&openFileSystemOnMainThread, createCallbackTask(&openFileSystemOnMainThread,
...@@ -251,7 +251,7 @@ void WorkerFileSystemCallbacksBridge::postReadDirectoryToMainThread(WebFileSyste ...@@ -251,7 +251,7 @@ void WorkerFileSystemCallbacksBridge::postReadDirectoryToMainThread(WebFileSyste
AllowCrossThreadAccess(this), mode)); AllowCrossThreadAccess(this), mode));
} }
void WorkerFileSystemCallbacksBridge::openFileSystemOnMainThread(ScriptExecutionContext*, WebCommonWorkerClient* commonClient, WebFileSystem::Type type, long long size, bool create, WorkerFileSystemCallbacksBridge* bridge, const String& mode) void WorkerFileSystemCallbacksBridge::openFileSystemOnMainThread(ScriptExecutionContext*, NewWebCommonWorkerClient* commonClient, WebFileSystem::Type type, long long size, bool create, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
{ {
if (!commonClient) if (!commonClient)
bridge->didFailOnMainThread(WebFileErrorAbort, mode); bridge->didFailOnMainThread(WebFileErrorAbort, mode);
......
...@@ -51,8 +51,8 @@ namespace WebKit { ...@@ -51,8 +51,8 @@ namespace WebKit {
class AsyncFileSystem; class AsyncFileSystem;
class MainThreadFileSystemCallbacks; class MainThreadFileSystemCallbacks;
class NewWebCommonWorkerClient;
class ThreadableCallbacksBridgeWrapper; class ThreadableCallbacksBridgeWrapper;
class WebCommonWorkerClient;
class WebFileSystemCallbacks; class WebFileSystemCallbacks;
struct WebFileInfo; struct WebFileInfo;
struct WebFileSystemEntry; struct WebFileSystemEntry;
...@@ -87,7 +87,7 @@ public: ...@@ -87,7 +87,7 @@ public:
} }
// Methods that create an instance and post an initial request task to the main thread. They must be called on the worker thread. // Methods that create an instance and post an initial request task to the main thread. They must be called on the worker thread.
void postOpenFileSystemToMainThread(WebCommonWorkerClient*, WebFileSystem::Type, long long size, bool create, const String& mode); void postOpenFileSystemToMainThread(NewWebCommonWorkerClient*, WebFileSystem::Type, long long size, bool create, const String& mode);
void postMoveToMainThread(WebFileSystem*, const WebCore::KURL& srcPath, const WebCore::KURL& destPath, const String& mode); void postMoveToMainThread(WebFileSystem*, const WebCore::KURL& srcPath, const WebCore::KURL& destPath, const String& mode);
void postCopyToMainThread(WebFileSystem*, const WebCore::KURL& srcPath, const WebCore::KURL& destPath, const String& mode); void postCopyToMainThread(WebFileSystem*, const WebCore::KURL& srcPath, const WebCore::KURL& destPath, const String& mode);
void postRemoveToMainThread(WebFileSystem*, const WebCore::KURL& path, const String& mode); void postRemoveToMainThread(WebFileSystem*, const WebCore::KURL& path, const String& mode);
...@@ -110,7 +110,7 @@ private: ...@@ -110,7 +110,7 @@ private:
WorkerFileSystemCallbacksBridge(WebCore::WorkerLoaderProxy*, WebCore::ScriptExecutionContext*, WebFileSystemCallbacks*); WorkerFileSystemCallbacksBridge(WebCore::WorkerLoaderProxy*, WebCore::ScriptExecutionContext*, WebFileSystemCallbacks*);
// Methods that are to be called on the main thread. // Methods that are to be called on the main thread.
static void openFileSystemOnMainThread(WebCore::ScriptExecutionContext*, WebCommonWorkerClient*, WebFileSystem::Type, long long size, bool create, WorkerFileSystemCallbacksBridge*, const String& mode); static void openFileSystemOnMainThread(WebCore::ScriptExecutionContext*, NewWebCommonWorkerClient*, WebFileSystem::Type, long long size, bool create, WorkerFileSystemCallbacksBridge*, const String& mode);
static void moveOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const WebCore::KURL& srcPath, const WebCore::KURL& destPath, WorkerFileSystemCallbacksBridge*, const String& mode); static void moveOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const WebCore::KURL& srcPath, const WebCore::KURL& destPath, WorkerFileSystemCallbacksBridge*, const String& mode);
static void copyOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const WebCore::KURL& srcPath, const WebCore::KURL& destPath, WorkerFileSystemCallbacksBridge*, const String& mode); static void copyOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const WebCore::KURL& srcPath, const WebCore::KURL& destPath, WorkerFileSystemCallbacksBridge*, const String& mode);
static void removeOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const WebCore::KURL& path, WorkerFileSystemCallbacksBridge*, const String& mode); static void removeOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const WebCore::KURL& path, WorkerFileSystemCallbacksBridge*, const String& mode);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment