1 // Copyright 2014 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_SHARED_WORKER_EMBEDDED_SHARED_WORKER_STUB_H_
6 #define CONTENT_RENDERER_SHARED_WORKER_EMBEDDED_SHARED_WORKER_STUB_H_
10 #include "content/child/child_message_filter.h"
11 #include "content/child/scoped_child_process_reference.h"
12 #include "ipc/ipc_listener.h"
13 #include "third_party/WebKit/public/platform/WebString.h"
14 #include "third_party/WebKit/public/web/WebContentSecurityPolicy.h"
15 #include "third_party/WebKit/public/web/WebSharedWorkerClient.h"
19 class WebApplicationCacheHost
;
20 class WebApplicationCacheHostClient
;
21 class WebMessagePortChannel
;
22 class WebNotificationPresenter
;
23 class WebSecurityOrigin
;
24 class WebSharedWorker
;
25 class WebWorkerContentSettingsClientProxy
;
29 class SharedWorkerDevToolsAgent
;
30 class WebApplicationCacheHostImpl
;
31 class WebMessagePortChannelImpl
;
33 // A stub class to receive IPC from browser process and talk to
34 // blink::WebSharedWorker. Implements blink::WebSharedWorkerClient.
35 // This class is self-destruct (no one explicitly owns this), and
36 // deletes itself (via private Shutdown() method) when either one of
37 // following methods is called by blink::WebSharedWorker:
38 // - workerScriptLoadFailed() or
39 // - workerContextDestroyed()
41 // In either case the corresponding blink::WebSharedWorker also deletes
43 class EmbeddedSharedWorkerStub
: public IPC::Listener
,
44 public blink::WebSharedWorkerClient
{
46 EmbeddedSharedWorkerStub(
48 const base::string16
& name
,
49 const base::string16
& content_security_policy
,
50 blink::WebContentSecurityPolicyType security_policy_type
,
54 // IPC::Listener implementation.
55 bool OnMessageReceived(const IPC::Message
& message
) override
;
56 void OnChannelError() override
;
58 // blink::WebSharedWorkerClient implementation.
59 virtual void workerContextClosed() override
;
60 virtual void workerContextDestroyed() override
;
61 virtual void workerReadyForInspection() override
;
62 virtual void workerScriptLoaded() override
;
63 virtual void workerScriptLoadFailed() override
;
64 virtual void selectAppCacheID(long long) override
;
65 virtual blink::WebNotificationPresenter
* notificationPresenter() override
;
66 virtual blink::WebApplicationCacheHost
* createApplicationCacheHost(
67 blink::WebApplicationCacheHostClient
*) override
;
68 virtual blink::WebWorkerContentSettingsClientProxy
*
69 createWorkerContentSettingsClientProxy(
70 const blink::WebSecurityOrigin
& origin
) override
;
71 virtual blink::WebServiceWorkerNetworkProvider
*
72 createServiceWorkerNetworkProvider(blink::WebDataSource
*) override
;
73 virtual void sendDevToolsMessage(
75 const blink::WebString
& message
,
76 const blink::WebString
& state
) override
;
79 ~EmbeddedSharedWorkerStub() override
;
82 bool Send(IPC::Message
* message
);
84 // WebSharedWorker will own |channel|.
85 void ConnectToChannel(WebMessagePortChannelImpl
* channel
);
87 void OnConnect(int sent_message_port_id
, int routing_id
);
88 void OnTerminateWorkerContext();
92 bool running_
= false;
94 blink::WebSharedWorker
* impl_
= nullptr;
95 scoped_ptr
<SharedWorkerDevToolsAgent
> worker_devtools_agent_
;
97 typedef std::vector
<WebMessagePortChannelImpl
*> PendingChannelList
;
98 PendingChannelList pending_channels_
;
100 ScopedChildProcessReference process_ref_
;
101 WebApplicationCacheHostImpl
* app_cache_host_
= nullptr;
102 DISALLOW_COPY_AND_ASSIGN(EmbeddedSharedWorkerStub
);
105 } // namespace content
107 #endif // CONTENT_RENDERER_SHARED_WORKER_EMBEDDED_SHARED_WORKER_STUB_H_