OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_HOST_H_ |
6 #define CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_HOST_H_ | 6 #define CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_HOST_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/strings/string16.h" |
| 12 #include "content/browser/shared_worker/shared_worker_message_filter.h" |
| 13 |
| 14 class GURL; |
| 15 |
| 16 namespace IPC { |
| 17 class Message; |
| 18 } |
11 | 19 |
12 namespace content { | 20 namespace content { |
13 class SharedWorkerMessageFilter; | 21 class SharedWorkerMessageFilter; |
14 class SharedWorkerInstance; | 22 class SharedWorkerInstance; |
15 | 23 |
16 // The SharedWorkerHost is the interface that represents the browser side of | 24 // The SharedWorkerHost is the interface that represents the browser side of |
17 // the browser <-> worker communication channel. | 25 // the browser <-> worker communication channel. |
18 class SharedWorkerHost { | 26 class SharedWorkerHost { |
19 public: | 27 public: |
20 explicit SharedWorkerHost(SharedWorkerInstance* instance); | 28 explicit SharedWorkerHost(SharedWorkerInstance* instance); |
21 ~SharedWorkerHost(); | 29 ~SharedWorkerHost(); |
22 | 30 |
| 31 // Sends |message| to the SharedWorker. |
| 32 bool Send(IPC::Message* message); |
| 33 |
23 // Starts the SharedWorker in the renderer process which is associated with | 34 // Starts the SharedWorker in the renderer process which is associated with |
24 // |filter|. | 35 // |filter|. |
25 void Init(SharedWorkerMessageFilter* filter); | 36 void Init(SharedWorkerMessageFilter* filter); |
26 | 37 |
| 38 // Returns true iff the given message from a renderer process was forwarded to |
| 39 // the worker. |
| 40 bool FilterMessage(const IPC::Message& message, |
| 41 SharedWorkerMessageFilter* filter); |
| 42 |
| 43 // Handles the shutdown of the filter. If the worker has no other client, |
| 44 // sends TerminateWorkerContext message to shut it down. |
| 45 void FilterShutdown(SharedWorkerMessageFilter* filter); |
| 46 |
| 47 // Shuts down any shared workers that are no longer referenced by active |
| 48 // documents. |
| 49 void DocumentDetached(SharedWorkerMessageFilter* filter, |
| 50 unsigned long long document_id); |
| 51 |
| 52 void WorkerContextClosed(); |
| 53 void WorkerScriptLoaded(); |
| 54 void WorkerScriptLoadFailed(); |
| 55 void WorkerConnected(int message_port_id); |
| 56 void WorkerContextDestroyed(); |
| 57 void AllowDatabase(const GURL& url, |
| 58 const base::string16& name, |
| 59 const base::string16& display_name, |
| 60 unsigned long estimated_size, |
| 61 bool* result); |
| 62 void AllowFileSystem(const GURL& url, bool* result); |
| 63 void AllowIndexedDB(const GURL& url, |
| 64 const base::string16& name, |
| 65 bool* result); |
| 66 |
27 SharedWorkerInstance* instance() { return instance_.get(); } | 67 SharedWorkerInstance* instance() { return instance_.get(); } |
| 68 SharedWorkerMessageFilter* container_render_filter() const { |
| 69 return container_render_filter_; |
| 70 } |
| 71 int process_id() const { |
| 72 return container_render_filter_->render_process_id(); |
| 73 } |
28 int worker_route_id() const { return worker_route_id_; } | 74 int worker_route_id() const { return worker_route_id_; } |
29 | 75 |
30 private: | 76 private: |
| 77 // Relays |message| to the SharedWorker. Takes care of parsing the message if |
| 78 // it contains a message port and sending it a valid route id. |
| 79 void RelayMessage(const IPC::Message& message, |
| 80 SharedWorkerMessageFilter* incoming_filter); |
| 81 |
31 scoped_ptr<SharedWorkerInstance> instance_; | 82 scoped_ptr<SharedWorkerInstance> instance_; |
| 83 SharedWorkerMessageFilter* container_render_filter_; |
32 int worker_route_id_; | 84 int worker_route_id_; |
33 | |
34 DISALLOW_COPY_AND_ASSIGN(SharedWorkerHost); | 85 DISALLOW_COPY_AND_ASSIGN(SharedWorkerHost); |
35 }; | 86 }; |
36 } // namespace content | 87 } // namespace content |
37 | 88 |
38 #endif // CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_HOST_H_ | 89 #endif // CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_HOST_H_ |
OLD | NEW |