WorkerMessagingProxy.h [plain text]
#ifndef WorkerMessagingProxy_h
#define WorkerMessagingProxy_h
#if ENABLE(WORKERS)
#include "ScriptExecutionContext.h"
#include "WorkerContextProxy.h"
#include "WorkerLoaderProxy.h"
#include "WorkerObjectProxy.h"
#include <wtf/Forward.h>
#include <wtf/Noncopyable.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
namespace WebCore {
class DedicatedWorkerThread;
class ScriptExecutionContext;
class Worker;
class WorkerMessagingProxy : public WorkerContextProxy, public WorkerObjectProxy, public WorkerLoaderProxy {
WTF_MAKE_NONCOPYABLE(WorkerMessagingProxy); WTF_MAKE_FAST_ALLOCATED;
public:
explicit WorkerMessagingProxy(Worker*);
virtual void startWorkerContext(const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerThreadStartMode) OVERRIDE;
virtual void terminateWorkerContext() OVERRIDE;
virtual void postMessageToWorkerContext(PassRefPtr<SerializedScriptValue>, PassOwnPtr<MessagePortChannelArray>) OVERRIDE;
virtual bool hasPendingActivity() const OVERRIDE;
virtual void workerObjectDestroyed() OVERRIDE;
#if ENABLE(INSPECTOR)
virtual void connectToInspector(WorkerContextProxy::PageInspector*) OVERRIDE;
virtual void disconnectFromInspector() OVERRIDE;
virtual void sendMessageToInspector(const String&) OVERRIDE;
#endif
virtual void postMessageToWorkerObject(PassRefPtr<SerializedScriptValue>, PassOwnPtr<MessagePortChannelArray>) OVERRIDE;
virtual void postExceptionToWorkerObject(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL) OVERRIDE;
virtual void postConsoleMessageToWorkerObject(MessageSource, MessageLevel, const String& message, int lineNumber, int columnNumber, const String& sourceURL) OVERRIDE;
#if ENABLE(INSPECTOR)
virtual void postMessageToPageInspector(const String&) OVERRIDE;
virtual void updateInspectorStateCookie(const String&) OVERRIDE;
#endif
virtual void confirmMessageFromWorkerObject(bool hasPendingActivity) OVERRIDE;
virtual void reportPendingActivity(bool hasPendingActivity) OVERRIDE;
virtual void workerContextClosed() OVERRIDE;
virtual void workerContextDestroyed() OVERRIDE;
virtual void postTaskToLoader(PassOwnPtr<ScriptExecutionContext::Task>) OVERRIDE;
virtual bool postTaskForModeToWorkerContext(PassOwnPtr<ScriptExecutionContext::Task>, const String& mode) OVERRIDE;
void workerThreadCreated(PassRefPtr<DedicatedWorkerThread>);
bool askedToTerminate() const { return m_askedToTerminate; }
protected:
virtual ~WorkerMessagingProxy();
private:
friend class MessageWorkerTask;
friend class PostMessageToPageInspectorTask;
friend class WorkerContextDestroyedTask;
friend class WorkerExceptionTask;
friend class WorkerThreadActivityReportTask;
void workerContextDestroyedInternal();
static void workerObjectDestroyedInternal(ScriptExecutionContext*, WorkerMessagingProxy*);
void reportPendingActivityInternal(bool confirmingMessage, bool hasPendingActivity);
Worker* workerObject() const { return m_workerObject; }
RefPtr<ScriptExecutionContext> m_scriptExecutionContext;
Worker* m_workerObject;
bool m_mayBeDestroyed;
RefPtr<DedicatedWorkerThread> m_workerThread;
unsigned m_unconfirmedMessageCount; bool m_workerThreadHadPendingActivity;
bool m_askedToTerminate;
Vector<OwnPtr<ScriptExecutionContext::Task> > m_queuedEarlyTasks; #if ENABLE(INSPECTOR)
WorkerContextProxy::PageInspector* m_pageInspector;
#endif
};
}
#endif // ENABLE(WORKERS)
#endif // WorkerMessagingProxy_h