OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_RENDERER_WEBWORKER_PROXY_H_ | 5 #ifndef CHROME_RENDERER_WEBWORKER_PROXY_H_ |
6 #define CHROME_RENDERER_WEBWORKER_PROXY_H_ | 6 #define CHROME_RENDERER_WEBWORKER_PROXY_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "chrome/renderer/webworker_base.h" |
11 #include "ipc/ipc_channel.h" | 12 #include "ipc/ipc_channel.h" |
12 #include "webkit/api/public/WebWorker.h" | 13 #include "webkit/api/public/WebWorker.h" |
13 | 14 |
14 class ChildThread; | 15 class ChildThread; |
15 class GURL; | 16 class GURL; |
16 class RenderView; | 17 class RenderView; |
17 struct WorkerHostMsg_PostConsoleMessageToWorkerObject_Params; | 18 struct WorkerHostMsg_PostConsoleMessageToWorkerObject_Params; |
18 | 19 |
19 // This class provides an implementation of WebWorker that the renderer provides | 20 // This class provides an implementation of WebWorker that the renderer provides |
20 // to the glue. This class converts function calls to IPC messages that are | 21 // to the glue. This class converts function calls to IPC messages that are |
21 // dispatched in the worker process by WebWorkerClientProxy. It also receives | 22 // dispatched in the worker process by WebWorkerClientProxy. It also receives |
22 // IPC messages from WebWorkerClientProxy which it converts to function calls to | 23 // IPC messages from WebWorkerClientProxy which it converts to function calls to |
23 // WebWorkerClient. | 24 // WebWorkerClient. |
24 class WebWorkerProxy : public WebKit::WebWorker, | 25 class WebWorkerProxy : public WebKit::WebWorker, private WebWorkerBase { |
25 public IPC::Channel::Listener { | |
26 public: | 26 public: |
27 WebWorkerProxy(WebKit::WebWorkerClient* client, | 27 WebWorkerProxy(WebKit::WebWorkerClient* client, |
28 ChildThread* child_thread, | 28 ChildThread* child_thread, |
29 int render_view_route_id); | 29 int render_view_route_id); |
30 virtual ~WebWorkerProxy(); | |
31 | 30 |
32 // WebWorker implementation. | 31 // WebWorker implementation. |
33 virtual void startWorkerContext(const WebKit::WebURL& script_url, | 32 virtual void startWorkerContext(const WebKit::WebURL& script_url, |
34 const WebKit::WebString& user_agent, | 33 const WebKit::WebString& user_agent, |
35 const WebKit::WebString& source_code); | 34 const WebKit::WebString& source_code); |
36 virtual void terminateWorkerContext(); | 35 virtual void terminateWorkerContext(); |
37 virtual void postMessageToWorkerContext( | 36 virtual void postMessageToWorkerContext( |
38 const WebKit::WebString& message, | 37 const WebKit::WebString& message, |
39 const WebKit::WebMessagePortChannelArray& channel_array); | 38 const WebKit::WebMessagePortChannelArray& channel_array); |
40 virtual void workerObjectDestroyed(); | 39 virtual void workerObjectDestroyed(); |
41 virtual void clientDestroyed(); | 40 virtual void clientDestroyed(); |
42 | 41 |
43 // IPC::Channel::Listener implementation. | 42 // IPC::Channel::Listener implementation. |
44 void OnMessageReceived(const IPC::Message& message); | 43 void OnMessageReceived(const IPC::Message& message); |
45 | 44 |
46 private: | 45 private: |
47 bool Send(IPC::Message* message); | 46 virtual void Disconnect(); |
48 | 47 |
49 void OnDedicatedWorkerCreated(); | 48 void OnWorkerCreated(); |
50 void OnPostMessage(const string16& message, | 49 void OnPostMessage(const string16& message, |
51 const std::vector<int>& sent_message_port_ids, | 50 const std::vector<int>& sent_message_port_ids, |
52 const std::vector<int>& new_routing_ids); | 51 const std::vector<int>& new_routing_ids); |
53 void OnPostConsoleMessageToWorkerObject( | 52 void OnPostConsoleMessageToWorkerObject( |
54 const WorkerHostMsg_PostConsoleMessageToWorkerObject_Params& params); | 53 const WorkerHostMsg_PostConsoleMessageToWorkerObject_Params& params); |
55 | 54 |
56 void Disconnect(); | |
57 | |
58 // The routing id used to reach WebWorkerClientProxy in the worker process. | |
59 int route_id_; | |
60 | |
61 ChildThread* child_thread_; | |
62 | |
63 // The routing id for the RenderView that created this worker. | |
64 int render_view_route_id_; | |
65 | 55 |
66 // Used to communicate to the WebCore::Worker object in response to IPC | 56 // Used to communicate to the WebCore::Worker object in response to IPC |
67 // messages. | 57 // messages. |
68 WebKit::WebWorkerClient* client_; | 58 WebKit::WebWorkerClient* client_; |
69 | 59 |
70 // Stores messages that were sent before the StartWorkerContext message. | |
71 std::vector<IPC::Message*> queued_messages_; | |
72 | |
73 DISALLOW_COPY_AND_ASSIGN(WebWorkerProxy); | 60 DISALLOW_COPY_AND_ASSIGN(WebWorkerProxy); |
74 }; | 61 }; |
75 | 62 |
76 #endif // CHROME_RENDERER_WEBWORKER_PROXY_H_ | 63 #endif // CHROME_RENDERER_WEBWORKER_PROXY_H_ |
OLD | NEW |