tizen beta release
[profile/ivi/webkit-efl.git] / Source / WebCore / workers / WorkerMessagingProxy.h
1 /*
2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  *
25  */
26
27 #ifndef WorkerMessagingProxy_h
28 #define WorkerMessagingProxy_h
29
30 #if ENABLE(WORKERS)
31
32 #include "ScriptExecutionContext.h"
33 #include "WorkerContextProxy.h"
34 #include "WorkerLoaderProxy.h"
35 #include "WorkerObjectProxy.h"
36 #include <wtf/Forward.h>
37 #include <wtf/Noncopyable.h>
38 #include <wtf/PassOwnPtr.h>
39 #include <wtf/PassRefPtr.h>
40 #include <wtf/RefPtr.h>
41 #include <wtf/Vector.h>
42
43 namespace WebCore {
44
45     class DedicatedWorkerThread;
46     class ScriptExecutionContext;
47     class Worker;
48
49     class WorkerMessagingProxy : public WorkerContextProxy, public WorkerObjectProxy, public WorkerLoaderProxy {
50         WTF_MAKE_NONCOPYABLE(WorkerMessagingProxy); WTF_MAKE_FAST_ALLOCATED;
51     public:
52         WorkerMessagingProxy(Worker*);
53
54         // Implementations of WorkerContextProxy.
55         // (Only use these methods in the worker object thread.)
56         virtual void startWorkerContext(const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerThreadStartMode);
57         virtual void terminateWorkerContext();
58         virtual void postMessageToWorkerContext(PassRefPtr<SerializedScriptValue>, PassOwnPtr<MessagePortChannelArray>);
59         virtual bool hasPendingActivity() const;
60         virtual void workerObjectDestroyed();
61 #if ENABLE(INSPECTOR)
62         virtual void connectToInspector(WorkerContextProxy::PageInspector*);
63         virtual void disconnectFromInspector();
64         virtual void sendMessageToInspector(const String&);
65 #endif
66
67         // Implementations of WorkerObjectProxy.
68         // (Only use these methods in the worker context thread.)
69         virtual void postMessageToWorkerObject(PassRefPtr<SerializedScriptValue>, PassOwnPtr<MessagePortChannelArray>);
70         virtual void postExceptionToWorkerObject(const String& errorMessage, int lineNumber, const String& sourceURL);
71         virtual void postConsoleMessageToWorkerObject(MessageSource, MessageType, MessageLevel, const String& message, int lineNumber, const String& sourceURL);
72 #if ENABLE(INSPECTOR)
73         virtual void postMessageToPageInspector(const String&);
74         virtual void updateInspectorStateCookie(const String&);
75 #endif
76         virtual void confirmMessageFromWorkerObject(bool hasPendingActivity);
77         virtual void reportPendingActivity(bool hasPendingActivity);
78         virtual void workerContextClosed();
79         virtual void workerContextDestroyed();
80
81         // Implementation of WorkerLoaderProxy.
82         // These methods are called on different threads to schedule loading
83         // requests and to send callbacks back to WorkerContext.
84         virtual void postTaskToLoader(PassOwnPtr<ScriptExecutionContext::Task>);
85         virtual void postTaskForModeToWorkerContext(PassOwnPtr<ScriptExecutionContext::Task>, const String& mode);
86
87         void workerThreadCreated(PassRefPtr<DedicatedWorkerThread>);
88
89         // Only use this method on the worker object thread.
90         bool askedToTerminate() const { return m_askedToTerminate; }
91
92     private:
93         friend class MessageWorkerTask;
94         friend class PostMessageToPageInspectorTask;
95         friend class WorkerContextDestroyedTask;
96         friend class WorkerExceptionTask;
97         friend class WorkerThreadActivityReportTask;
98
99         virtual ~WorkerMessagingProxy();
100
101         void workerContextDestroyedInternal();
102         void reportPendingActivityInternal(bool confirmingMessage, bool hasPendingActivity);
103         Worker* workerObject() const { return m_workerObject; }
104
105         RefPtr<ScriptExecutionContext> m_scriptExecutionContext;
106         Worker* m_workerObject;
107         RefPtr<DedicatedWorkerThread> m_workerThread;
108
109         unsigned m_unconfirmedMessageCount; // Unconfirmed messages from worker object to worker thread.
110         bool m_workerThreadHadPendingActivity; // The latest confirmation from worker thread reported that it was still active.
111
112         bool m_askedToTerminate;
113
114         Vector<OwnPtr<ScriptExecutionContext::Task> > m_queuedEarlyTasks; // Tasks are queued here until there's a thread object created.
115 #if ENABLE(INSPECTOR)
116         WorkerContextProxy::PageInspector* m_pageInspector;
117 #endif
118     };
119
120 } // namespace WebCore
121
122 #endif // ENABLE(WORKERS)
123
124 #endif // WorkerMessagingProxy_h