#ifndef WorkerMessagingProxy_h
#define WorkerMessagingProxy_h
#include "core/dom/ExecutionContext.h"
#include "core/workers/WorkerGlobalScopeProxy.h"
#include "core/workers/WorkerLoaderProxy.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 WorkerObjectProxy;
    class DedicatedWorkerThread;
    class ExecutionContext;
    class Worker;
    class WorkerClients;
    class WorkerMessagingProxy FINAL : public WorkerGlobalScopeProxy, public WorkerLoaderProxy {
        WTF_MAKE_NONCOPYABLE(WorkerMessagingProxy); WTF_MAKE_FAST_ALLOCATED;
    public:
        WorkerMessagingProxy(Worker*, PassOwnPtr<WorkerClients>);
        
        
        virtual void startWorkerGlobalScope(const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerThreadStartMode) OVERRIDE;
        virtual void terminateWorkerGlobalScope() OVERRIDE;
        virtual void postMessageToWorkerGlobalScope(PassRefPtr<SerializedScriptValue>, PassOwnPtr<MessagePortChannelArray>) OVERRIDE;
        virtual bool hasPendingActivity() const OVERRIDE;
        virtual void workerObjectDestroyed() OVERRIDE;
        virtual void connectToInspector(WorkerGlobalScopeProxy::PageInspector*) OVERRIDE;
        virtual void disconnectFromInspector() OVERRIDE;
        virtual void sendMessageToInspector(const String&) OVERRIDE;
        
        
        void postMessageToWorkerObject(PassRefPtr<SerializedScriptValue>, PassOwnPtr<MessagePortChannelArray>);
        void reportException(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL);
        void reportConsoleMessage(MessageSource, MessageLevel, const String& message, int lineNumber, const String& sourceURL);
        void postMessageToPageInspector(const String&);
        void confirmMessageFromWorkerObject(bool hasPendingActivity);
        void reportPendingActivity(bool hasPendingActivity);
        void workerGlobalScopeClosed();
        void workerGlobalScopeDestroyed();
        
        
        
        virtual void postTaskToLoader(PassOwnPtr<ExecutionContextTask>) OVERRIDE;
        virtual bool postTaskToWorkerGlobalScope(PassOwnPtr<ExecutionContextTask>) OVERRIDE;
        void workerThreadCreated(PassRefPtr<DedicatedWorkerThread>);
    protected:
        virtual ~WorkerMessagingProxy();
    private:
        static void workerObjectDestroyedInternal(ExecutionContext*, WorkerMessagingProxy*);
        RefPtr<ExecutionContext> m_executionContext;
        OwnPtr<WorkerObjectProxy> m_workerObjectProxy;
        Worker* m_workerObject;
        bool m_mayBeDestroyed;
        RefPtr<DedicatedWorkerThread> m_workerThread;
        unsigned m_unconfirmedMessageCount; 
        bool m_workerThreadHadPendingActivity; 
        bool m_askedToTerminate;
        Vector<OwnPtr<ExecutionContextTask> > m_queuedEarlyTasks; 
        WorkerGlobalScopeProxy::PageInspector* m_pageInspector;
        OwnPtr<WorkerClients> m_workerClients;
    };
} 
#endif