Upstream version 7.36.149.0
[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 WebSharedWorker;
18 }
19
20 namespace content {
21
22 class SharedWorkerDevToolsAgent;
23 class WebMessagePortChannelImpl;
24
25 // This class creates a WebSharedWorker, and translates incoming IPCs to the
26 // appropriate WebSharedWorker APIs.
27 class WebSharedWorkerStub : public IPC::Listener {
28  public:
29   WebSharedWorkerStub(const GURL& url,
30                       const base::string16& name,
31                       const base::string16& content_security_policy,
32                       blink::WebContentSecurityPolicyType security_policy_type,
33                       bool pause_on_start,
34                       int route_id);
35
36   // IPC::Listener implementation.
37   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
38   virtual void OnChannelError() OVERRIDE;
39
40   // Invoked when the WebSharedWorkerClientProxy is shutting down.
41   void Shutdown();
42
43   void WorkerScriptLoaded();
44   void WorkerScriptLoadFailed();
45
46   // Called after terminating the worker context to make sure that the worker
47   // actually terminates (is not stuck in an infinite loop).
48   void EnsureWorkerContextTerminates();
49
50   WebSharedWorkerClientProxy* client() { return &client_; }
51
52   // Returns the script url of this worker.
53   const GURL& url();
54
55
56  private:
57   virtual ~WebSharedWorkerStub();
58
59   void OnConnect(int sent_message_port_id, int routing_id);
60
61   void OnTerminateWorkerContext();
62
63   ScopedChildProcessReference process_ref_;
64
65   int route_id_;
66
67   // WebSharedWorkerClient that responds to outgoing API calls
68   // from the worker object.
69   WebSharedWorkerClientProxy client_;
70
71   blink::WebSharedWorker* impl_;
72   bool running_;
73   GURL url_;
74   scoped_ptr<SharedWorkerDevToolsAgent> worker_devtools_agent_;
75
76   typedef std::vector<WebMessagePortChannelImpl*> PendingChannelList;
77   PendingChannelList pending_channels_;
78
79   DISALLOW_COPY_AND_ASSIGN(WebSharedWorkerStub);
80 };
81
82 }  // namespace content
83
84 #endif  // CONTENT_WORKER_WEBSHAREDWORKER_STUB_H_