OLD | NEW |
| (Empty) |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef WEBKIT_GLUE_WEBWORKER_IMPL_H_ | |
6 #define WEBKIT_GLUE_WEBWORKER_IMPL_H_ | |
7 | |
8 #include "webkit/api/public/WebWorker.h" | |
9 | |
10 #if ENABLE(WORKERS) | |
11 | |
12 #include "ScriptExecutionContext.h" | |
13 #include "WorkerLoaderProxy.h" | |
14 #include "WorkerObjectProxy.h" | |
15 #include <wtf/PassOwnPtr.h> | |
16 #include <wtf/RefPtr.h> | |
17 | |
18 namespace WebCore { | |
19 class WorkerThread; | |
20 } | |
21 | |
22 namespace WebKit { | |
23 class WebView; | |
24 } | |
25 | |
26 // This class is used by the worker process code to talk to the WebCore::Worker | |
27 // implementation. It can't use it directly since it uses WebKit types, so this | |
28 // class converts the data types. When the WebCore::Worker object wants to call | |
29 // WebCore::WorkerObjectProxy, this class will conver to Chrome data types first | |
30 // and then call the supplied WebWorkerClient. | |
31 class WebWorkerImpl: public WebCore::WorkerObjectProxy, | |
32 public WebCore::WorkerLoaderProxy, | |
33 public WebKit::WebWorker { | |
34 public: | |
35 explicit WebWorkerImpl(WebKit::WebWorkerClient* client); | |
36 | |
37 // WebCore::WorkerObjectProxy methods: | |
38 virtual void postMessageToWorkerObject( | |
39 WTF::PassRefPtr<WebCore::SerializedScriptValue> message, | |
40 WTF::PassOwnPtr<WebCore::MessagePortChannelArray> channels); | |
41 virtual void postExceptionToWorkerObject( | |
42 const WebCore::String& error_message, | |
43 int line_number, | |
44 const WebCore::String& source_url); | |
45 virtual void postConsoleMessageToWorkerObject( | |
46 WebCore::MessageDestination destination, | |
47 WebCore::MessageSource source, | |
48 WebCore::MessageType type, | |
49 WebCore::MessageLevel level, | |
50 const WebCore::String& message, | |
51 int line_number, | |
52 const WebCore::String& source_url); | |
53 virtual void confirmMessageFromWorkerObject(bool has_pending_activity); | |
54 virtual void reportPendingActivity(bool has_pending_activity); | |
55 virtual void workerContextDestroyed(); | |
56 | |
57 // WebCore::WorkerLoaderProxy methods: | |
58 virtual void postTaskToLoader( | |
59 WTF::PassRefPtr<WebCore::ScriptExecutionContext::Task>); | |
60 virtual void postTaskForModeToWorkerContext( | |
61 WTF::PassRefPtr<WebCore::ScriptExecutionContext::Task>, | |
62 const WebCore::String& mode); | |
63 | |
64 // WebWorker methods: | |
65 virtual void startWorkerContext(const WebKit::WebURL& script_url, | |
66 const WebKit::WebString& user_agent, | |
67 const WebKit::WebString& source_code); | |
68 virtual void terminateWorkerContext(); | |
69 virtual void postMessageToWorkerContext( | |
70 const WebKit::WebString& message, | |
71 const WebKit::WebMessagePortChannelArray& channel); | |
72 virtual void workerObjectDestroyed(); | |
73 virtual void clientDestroyed(); | |
74 | |
75 WebKit::WebWorkerClient* client() { return client_; } | |
76 | |
77 // Executes the given task on the main thread. | |
78 static void DispatchTaskToMainThread( | |
79 PassRefPtr<WebCore::ScriptExecutionContext::Task> task); | |
80 | |
81 private: | |
82 virtual ~WebWorkerImpl(); | |
83 | |
84 // Tasks that are run on the worker thread. | |
85 static void PostMessageToWorkerContextTask( | |
86 WebCore::ScriptExecutionContext* context, | |
87 WebWorkerImpl* this_ptr, | |
88 const WebCore::String& message, | |
89 WTF::PassOwnPtr<WebCore::MessagePortChannelArray> channels); | |
90 | |
91 // Function used to invoke tasks on the main thread. | |
92 static void InvokeTaskMethod(void* param); | |
93 | |
94 // Tasks that are run on the main thread. | |
95 static void PostMessageTask( | |
96 WebCore::ScriptExecutionContext* context, | |
97 WebWorkerImpl* this_ptr, | |
98 WebCore::String message, | |
99 WTF::PassOwnPtr<WebCore::MessagePortChannelArray> channels); | |
100 static void PostExceptionTask( | |
101 WebCore::ScriptExecutionContext* context, | |
102 WebWorkerImpl* this_ptr, | |
103 const WebCore::String& error_message, | |
104 int line_number, | |
105 const WebCore::String& source_url); | |
106 static void PostConsoleMessageTask( | |
107 WebCore::ScriptExecutionContext* context, | |
108 WebWorkerImpl* this_ptr, | |
109 int destination, | |
110 int source, | |
111 int type, | |
112 int level, | |
113 const WebCore::String& message, | |
114 int line_number, | |
115 const WebCore::String& source_url); | |
116 static void ConfirmMessageTask( | |
117 WebCore::ScriptExecutionContext* context, | |
118 WebWorkerImpl* this_ptr, | |
119 bool has_pending_activity); | |
120 static void ReportPendingActivityTask( | |
121 WebCore::ScriptExecutionContext* context, | |
122 WebWorkerImpl* this_ptr, | |
123 bool has_pending_activity); | |
124 static void WorkerContextDestroyedTask( | |
125 WebCore::ScriptExecutionContext* context, | |
126 WebWorkerImpl* this_ptr); | |
127 | |
128 WebKit::WebWorkerClient* client_; | |
129 | |
130 // 'shadow page' - created to proxy loading requests from the worker. | |
131 WTF::RefPtr<WebCore::ScriptExecutionContext> loading_document_; | |
132 WebKit::WebView* web_view_; | |
133 bool asked_to_terminate_; | |
134 | |
135 WTF::RefPtr<WebCore::WorkerThread> worker_thread_; | |
136 | |
137 DISALLOW_COPY_AND_ASSIGN(WebWorkerImpl); | |
138 }; | |
139 | |
140 #endif | |
141 | |
142 #endif // WEBKIT_GLUE_WEBWORKER_IMPL_H_ | |
OLD | NEW |