OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_RENDERER_WEBSHAREDWORKER_PROXY_H_ | 5 #ifndef CONTENT_RENDERER_WEBSHAREDWORKER_PROXY_H_ |
6 #define CONTENT_RENDERER_WEBSHAREDWORKER_PROXY_H_ | 6 #define CONTENT_RENDERER_WEBSHAREDWORKER_PROXY_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "ipc/ipc_listener.h" | 13 #include "ipc/ipc_listener.h" |
14 #include "third_party/WebKit/public/web/WebSharedWorkerConnector.h" | 14 #include "third_party/WebKit/public/web/WebSharedWorkerConnector.h" |
15 #include "url/gurl.h" | |
16 | 15 |
17 namespace IPC { | 16 namespace IPC { |
18 class MessageRouter; | 17 class MessageRouter; |
19 } | 18 } |
20 | 19 |
21 namespace content { | 20 namespace content { |
22 | 21 |
23 // Implementation of the WebSharedWorker APIs. This object is intended to only | 22 // Implementation of the WebSharedWorker APIs. This object is intended to only |
24 // live long enough to allow the caller to send a "connect" event to the worker | 23 // live long enough to allow the caller to send a "connect" event to the worker |
25 // thread. Once the connect event has been sent, all future communication will | 24 // thread. Once the connect event has been sent, all future communication will |
26 // happen via the WebMessagePortChannel, and the WebSharedWorker instance will | 25 // happen via the WebMessagePortChannel, and the WebSharedWorker instance will |
27 // be freed. | 26 // be freed. |
28 class WebSharedWorkerProxy : public blink::WebSharedWorkerConnector, | 27 class WebSharedWorkerProxy : public blink::WebSharedWorkerConnector, |
29 private IPC::Listener { | 28 private IPC::Listener { |
30 public: | 29 public: |
31 WebSharedWorkerProxy(IPC::MessageRouter* router, int route_id); | 30 WebSharedWorkerProxy(IPC::MessageRouter* router, int route_id); |
32 ~WebSharedWorkerProxy() override; | 31 ~WebSharedWorkerProxy() override; |
33 | 32 |
34 // Implementations of WebSharedWorkerConnector APIs | 33 // Implementations of WebSharedWorkerConnector APIs |
35 void connect(blink::WebMessagePortChannel* channel, | 34 void connect(blink::WebMessagePortChannel* channel, |
36 ConnectListener* listener) override; | 35 ConnectListener* listener) override; |
37 | 36 |
38 private: | 37 private: |
39 // IPC::Listener implementation. | 38 // IPC::Listener implementation. |
40 bool OnMessageReceived(const IPC::Message& message) override; | 39 bool OnMessageReceived(const IPC::Message& message) override; |
41 | 40 |
42 // Sends a message to the worker thread (forwarded via the RenderViewHost). | |
43 // If WorkerStarted() has not yet been called, message is queued. | |
44 bool Send(std::unique_ptr<IPC::Message> message); | |
45 | |
46 // Sends any messages currently in the queue. | |
47 void SendQueuedMessages(); | |
48 | |
49 void OnWorkerCreated(); | 41 void OnWorkerCreated(); |
50 void OnWorkerScriptLoadFailed(); | 42 void OnWorkerScriptLoadFailed(); |
51 void OnWorkerConnected(); | 43 void OnWorkerConnected(); |
52 | 44 |
53 // Routing id associated with this worker - used to receive messages from the | 45 // Routing id associated with this worker - used to receive messages from the |
54 // worker, and also to route messages to the worker (WorkerService contains | 46 // worker, and also to route messages to the worker (WorkerService contains |
55 // a map that maps between these renderer-side route IDs and worker-side | 47 // a map that maps between these renderer-side route IDs and worker-side |
56 // routing ids). | 48 // routing ids). |
57 const int route_id_; | 49 const int route_id_; |
58 | 50 |
59 IPC::MessageRouter* const router_; | 51 IPC::MessageRouter* const router_; |
60 | 52 |
61 // Stores messages that were sent before the StartWorkerContext message. | 53 int message_port_id_; |
62 std::vector<std::unique_ptr<IPC::Message>> queued_messages_; | |
63 | |
64 ConnectListener* connect_listener_; | 54 ConnectListener* connect_listener_; |
65 bool created_; | |
66 | 55 |
67 DISALLOW_COPY_AND_ASSIGN(WebSharedWorkerProxy); | 56 DISALLOW_COPY_AND_ASSIGN(WebSharedWorkerProxy); |
68 }; | 57 }; |
69 | 58 |
70 } // namespace content | 59 } // namespace content |
71 | 60 |
72 #endif // CONTENT_RENDERER_WEBSHAREDWORKER_PROXY_H_ | 61 #endif // CONTENT_RENDERER_WEBSHAREDWORKER_PROXY_H_ |
OLD | NEW |