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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_WEBSHAREDWORKER_PROXY_H_
6 #define CONTENT_RENDERER_WEBSHAREDWORKER_PROXY_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "ipc/ipc_listener.h"
14 #include "third_party/WebKit/public/web/WebSharedWorkerConnector.h"
21 // Implementation of the WebSharedWorker APIs. This object is intended to only
22 // live long enough to allow the caller to send a "connect" event to the worker
23 // thread. Once the connect event has been sent, all future communication will
24 // happen via the WebMessagePortChannel, and the WebSharedWorker instance will
26 class WebSharedWorkerProxy
: public blink::WebSharedWorkerConnector
,
27 private IPC::Listener
{
29 // If the worker not loaded yet, route_id == MSG_ROUTING_NONE
30 WebSharedWorkerProxy(MessageRouter
* router
,
31 unsigned long long document_id
,
33 int render_frame_route_id
);
34 virtual ~WebSharedWorkerProxy();
36 // Implementations of WebSharedWorkerConnector APIs
37 virtual void connect(blink::WebMessagePortChannel
* channel
,
38 ConnectListener
* listener
);
41 // IPC::Listener implementation.
42 bool OnMessageReceived(const IPC::Message
& message
) override
;
44 // Disconnects the worker (stops listening for incoming messages).
47 // Sends a message to the worker thread (forwarded via the RenderViewHost).
48 // If WorkerStarted() has not yet been called, message is queued.
49 bool Send(IPC::Message
*);
51 // Returns true if there are queued messages.
52 bool HasQueuedMessages() { return !queued_messages_
.empty(); }
54 // Sends any messages currently in the queue.
55 void SendQueuedMessages();
57 void OnWorkerCreated();
58 void OnWorkerScriptLoadFailed();
59 void OnWorkerConnected();
61 // Routing id associated with this worker - used to receive messages from the
62 // worker, and also to route messages to the worker (WorkerService contains
63 // a map that maps between these renderer-side route IDs and worker-side
67 // The routing id for the RenderFrame that created this worker.
68 int render_frame_route_id_
;
70 MessageRouter
* const router_
;
72 // ID of our parent document (used to shutdown workers when the parent
73 // document is detached).
74 unsigned long long document_id_
;
76 // Stores messages that were sent before the StartWorkerContext message.
77 std::vector
<IPC::Message
*> queued_messages_
;
79 // The id for the placeholder worker instance we've stored on the
80 // browser process (we need to pass this same route id back in when creating
82 int pending_route_id_
;
83 ConnectListener
* connect_listener_
;
86 DISALLOW_COPY_AND_ASSIGN(WebSharedWorkerProxy
);
89 } // namespace content
91 #endif // CONTENT_RENDERER_WEBSHAREDWORKER_PROXY_H_