bde7cbae29609283a681bebbe14d995be1114dc3
[platform/framework/web/crosswalk.git] / src / content / worker / websharedworker_stub.h
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.
4
5 #ifndef CONTENT_WORKER_WEBSHAREDWORKER_STUB_H_
6 #define CONTENT_WORKER_WEBSHAREDWORKER_STUB_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #include "content/child/scoped_child_process_reference.h"
10 #include "content/worker/websharedworkerclient_proxy.h"
11 #include "content/worker/worker_webapplicationcachehost_impl.h"
12 #include "ipc/ipc_listener.h"
13 #include "third_party/WebKit/public/web/WebSharedWorker.h"
14 #include "url/gurl.h"
15
16 namespace blink {
17 class WebMessagePortChannel;
18 class WebSharedWorker;
19 }
20
21 namespace content {
22
23 class SharedWorkerDevToolsAgent;
24 class WebMessagePortChannelImpl;
25
26 // This class creates a WebSharedWorker, and translates incoming IPCs to the
27 // appropriate WebSharedWorker APIs.
28 class WebSharedWorkerStub : public IPC::Listener {
29  public:
30   WebSharedWorkerStub(const GURL& url,
31                       const base::string16& name,
32                       const base::string16& content_security_policy,
33                       blink::WebContentSecurityPolicyType security_policy_type,
34                       int route_id,
35                       const WorkerAppCacheInitInfo& appcache_init_info);
36
37   // IPC::Listener implementation.
38   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
39   virtual void OnChannelError() OVERRIDE;
40
41   // Invoked when the WebSharedWorkerClientProxy is shutting down.
42   void Shutdown();
43
44   void WorkerScriptLoaded();
45   void WorkerScriptLoadFailed();
46
47   // Called after terminating the worker context to make sure that the worker
48   // actually terminates (is not stuck in an infinite loop).
49   void EnsureWorkerContextTerminates();
50
51   WebSharedWorkerClientProxy* client() { return &client_; }
52
53   const WorkerAppCacheInitInfo& appcache_init_info() const {
54     return appcache_init_info_;
55   }
56
57   // Returns the script url of this worker.
58   const GURL& url();
59
60
61  private:
62   virtual ~WebSharedWorkerStub();
63
64   void OnConnect(int sent_message_port_id, int routing_id);
65   void OnStartWorkerContext(
66       const GURL& url, const base::string16& user_agent,
67       const base::string16& source_code,
68       const base::string16& content_security_policy,
69       blink::WebContentSecurityPolicyType policy_type);
70
71   void OnTerminateWorkerContext();
72
73   ScopedChildProcessReference process_ref_;
74
75   int route_id_;
76   WorkerAppCacheInitInfo appcache_init_info_;
77
78   // WebSharedWorkerClient that responds to outgoing API calls
79   // from the worker object.
80   WebSharedWorkerClientProxy client_;
81
82   blink::WebSharedWorker* impl_;
83   base::string16 name_;
84   bool started_;
85   GURL url_;
86   bool worker_script_loaded_;
87   scoped_ptr<SharedWorkerDevToolsAgent> worker_devtools_agent_;
88
89   typedef std::vector<blink::WebMessagePortChannel*> PendingChannelList;
90   PendingChannelList pending_channels_;
91
92   DISALLOW_COPY_AND_ASSIGN(WebSharedWorkerStub);
93 };
94
95 }  // namespace content
96
97 #endif  // CONTENT_WORKER_WEBSHAREDWORKER_STUB_H_