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_WORKER_WEBSHAREDWORKER_STUB_H_
6 #define CONTENT_WORKER_WEBSHAREDWORKER_STUB_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "content/worker/websharedworkerclient_proxy.h"
10 #include "content/worker/worker_webapplicationcachehost_impl.h"
11 #include "ipc/ipc_listener.h"
12 #include "third_party/WebKit/public/web/WebSharedWorker.h"
16 class WebSharedWorker
;
21 class SharedWorkerDevToolsAgent
;
23 // This class creates a WebSharedWorker, and translates incoming IPCs to the
24 // appropriate WebSharedWorker APIs.
25 class WebSharedWorkerStub
: public IPC::Listener
{
27 WebSharedWorkerStub(const string16
& name
, int route_id
,
28 const WorkerAppCacheInitInfo
& appcache_init_info
);
30 // IPC::Listener implementation.
31 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
32 virtual void OnChannelError() OVERRIDE
;
34 // Invoked when the WebSharedWorkerClientProxy is shutting down.
37 // Called after terminating the worker context to make sure that the worker
38 // actually terminates (is not stuck in an infinite loop).
39 void EnsureWorkerContextTerminates();
41 WebSharedWorkerClientProxy
* client() { return &client_
; }
43 const WorkerAppCacheInitInfo
& appcache_init_info() const {
44 return appcache_init_info_
;
47 // Returns the script url of this worker.
52 virtual ~WebSharedWorkerStub();
54 void OnConnect(int sent_message_port_id
, int routing_id
);
55 void OnStartWorkerContext(
56 const GURL
& url
, const string16
& user_agent
, const string16
& source_code
,
57 const string16
& content_security_policy
,
58 blink::WebContentSecurityPolicyType policy_type
);
60 void OnTerminateWorkerContext();
63 WorkerAppCacheInitInfo appcache_init_info_
;
65 // WebSharedWorkerClient that responds to outgoing API calls
66 // from the worker object.
67 WebSharedWorkerClientProxy client_
;
69 blink::WebSharedWorker
* impl_
;
73 scoped_ptr
<SharedWorkerDevToolsAgent
> worker_devtools_agent_
;
75 typedef std::pair
<int, int> PendingConnectInfo
;
76 typedef std::vector
<PendingConnectInfo
> PendingConnectInfoList
;
77 PendingConnectInfoList pending_connects_
;
79 DISALLOW_COPY_AND_ASSIGN(WebSharedWorkerStub
);
82 } // namespace content
84 #endif // CONTENT_WORKER_WEBSHAREDWORKER_STUB_H_