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_MESSAGE_FILTER_H_ | 5 #ifndef CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_INSTANCE_H_ |
6 #define CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_MESSAGE_FILTER_H_ | 6 #define CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_INSTANCE_H_ |
7 | 7 |
8 #include <list> | |
9 #include <string> | |
10 | |
11 #include "base/basictypes.h" | |
8 #include "content/browser/worker_host/worker_storage_partition.h" | 12 #include "content/browser/worker_host/worker_storage_partition.h" |
9 #include "content/public/browser/browser_message_filter.h" | 13 #include "third_party/WebKit/public/web/WebContentSecurityPolicy.h" |
10 | 14 #include "url/gurl.h" |
11 class GURL; | |
12 struct ViewHostMsg_CreateWorker_Params; | |
13 | 15 |
14 namespace content { | 16 namespace content { |
15 class MessagePortMessageFilter; | |
16 class ResourceContext; | 17 class ResourceContext; |
18 class SharedWorkerMessageFilter; | |
19 class WorkerDocumentSet; | |
17 | 20 |
18 // If "enable-embedded-shared-worker" is set this class will be used instead of | 21 class SharedWorkerInstance { |
19 // WorkerMessageFilter. | |
20 class SharedWorkerMessageFilter : public BrowserMessageFilter { | |
21 public: | 22 public: |
22 SharedWorkerMessageFilter(int render_process_id, | 23 SharedWorkerInstance(const GURL& url, |
23 ResourceContext* resource_context, | 24 const base::string16& name, |
24 const WorkerStoragePartition& partition, | 25 const base::string16& content_security_policy, |
25 MessagePortMessageFilter* message_port_filter); | 26 blink::WebContentSecurityPolicyType security_policy_type, |
27 ResourceContext* resource_context, | |
28 const WorkerStoragePartition& partition); | |
29 ~SharedWorkerInstance(); | |
30 // Unique identifier for a worker client. | |
31 class FilterInfo { | |
32 public: | |
33 FilterInfo(SharedWorkerMessageFilter* filter, int route_id) | |
34 : filter_(filter), route_id_(route_id), message_port_id_(0) { } | |
35 SharedWorkerMessageFilter* filter() const { return filter_; } | |
36 int route_id() const { return route_id_; } | |
37 int message_port_id() const { return message_port_id_; } | |
38 void set_message_port_id(int id) { message_port_id_ = id; } | |
26 | 39 |
27 // BrowserMessageFilter implementation. | 40 private: |
28 virtual void OnChannelClosing() OVERRIDE; | 41 SharedWorkerMessageFilter* filter_; |
29 virtual bool OnMessageReceived(const IPC::Message& message, | 42 int route_id_; |
30 bool* message_was_ok) OVERRIDE; | 43 int message_port_id_; |
44 }; | |
kinuko
2014/02/26 08:51:17
nit: can we insert one-line space before line 30 a
horo
2014/02/26 10:36:19
Done.
| |
45 void AddFilter(SharedWorkerMessageFilter* filter, int route_id); | |
46 void RemoveFilters(SharedWorkerMessageFilter* filter); | |
47 bool HasFilter(SharedWorkerMessageFilter* filter, int route_id) const; | |
48 void SetMessagePortID(SharedWorkerMessageFilter* filter, | |
49 int route_id, | |
50 int message_port_id); | |
31 | 51 |
32 int GetNextRoutingID(); | 52 typedef std::list<FilterInfo> FilterList; |
kinuko
2014/02/26 08:51:17
style-nit: basically we prefer having all typedefs
horo
2014/02/26 10:36:19
Done.
| |
33 int render_process_id() const { return render_process_id_; } | 53 const FilterList& filters() const { return filters_; } |
34 | 54 |
35 MessagePortMessageFilter* message_port_message_filter() const { | 55 // Checks if this SharedWorkerInstance matches the passed url/name params |
36 return message_port_message_filter_; | 56 // (per the comparison algorithm in the WebWorkers spec). This API only |
57 // applies to shared workers. | |
kinuko
2014/02/26 08:51:17
The last line (only applies to shared workers) loo
horo
2014/02/26 10:36:19
Done.
| |
58 bool Matches( | |
59 const GURL& url, | |
60 const base::string16& name, | |
61 const WorkerStoragePartition& partition, | |
62 ResourceContext* resource_context) const; | |
63 | |
64 // Accessors | |
kinuko
2014/02/26 08:51:17
nit: end comment with period
horo
2014/02/26 10:36:19
Done.
| |
65 bool closed() const { return closed_; } | |
66 void set_closed(bool closed) { closed_ = closed; } | |
67 const GURL& url() const { return url_; } | |
68 const base::string16 name() const { return name_; } | |
69 const base::string16 content_security_policy() const { | |
70 return content_security_policy_; | |
37 } | 71 } |
72 blink::WebContentSecurityPolicyType security_policy_type() const { | |
73 return security_policy_type_; | |
kinuko
2014/02/26 08:51:17
nit: indent (line 70 and 73)
horo
2014/02/26 10:36:19
Done.
| |
74 } | |
75 WorkerDocumentSet* worker_document_set() const { | |
76 return worker_document_set_.get(); | |
77 } | |
78 ResourceContext* resource_context() const { | |
79 return resource_context_; | |
80 } | |
81 const WorkerStoragePartition& partition() const { | |
82 return partition_; | |
83 } | |
84 void set_load_failed(bool failed) { load_failed_ = failed; } | |
85 bool load_failed() { return load_failed_; } | |
38 | 86 |
39 private: | 87 private: |
40 virtual ~SharedWorkerMessageFilter(); | 88 GURL url_; |
41 | 89 bool closed_; |
42 // Message handlers. | 90 base::string16 name_; |
43 void OnCreateWorker(const ViewHostMsg_CreateWorker_Params& params, | 91 base::string16 content_security_policy_; |
44 int* route_id); | 92 blink::WebContentSecurityPolicyType security_policy_type_; |
45 void OnForwardToWorker(const IPC::Message& message); | 93 FilterList filters_; |
46 void OnDocumentDetached(unsigned long long document_id); | 94 scoped_refptr<WorkerDocumentSet> worker_document_set_; |
47 void OnWorkerContextClosed(int worker_route_id); | |
48 void OnWorkerContextDestroyed(int worker_route_id); | |
49 void OnWorkerScriptLoaded(int worker_route_id); | |
50 void OnWorkerScriptLoadFailed(int worker_route_id); | |
51 void OnWorkerConnected(int message_port_id, int worker_route_id); | |
52 void OnAllowDatabase(int worker_route_id, | |
53 const GURL& url, | |
54 const base::string16& name, | |
55 const base::string16& display_name, | |
56 unsigned long estimated_size, | |
57 bool* result); | |
58 void OnAllowFileSystem(int worker_route_id, | |
59 const GURL& url, | |
60 bool* result); | |
61 void OnAllowIndexedDB(int worker_route_id, | |
62 const GURL& url, | |
63 const base::string16& name, | |
64 bool* result); | |
65 | |
66 const int render_process_id_; | |
67 ResourceContext* const resource_context_; | 95 ResourceContext* const resource_context_; |
68 const WorkerStoragePartition partition_; | 96 WorkerStoragePartition partition_; |
69 MessagePortMessageFilter* const message_port_message_filter_; | 97 bool load_failed_; |
70 | |
71 DISALLOW_IMPLICIT_CONSTRUCTORS(SharedWorkerMessageFilter); | |
72 }; | 98 }; |
73 | 99 |
74 } // namespace content | 100 } // namespace content |
75 | 101 |
76 #endif // CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_MESSAGE_FILTER_H_ | 102 |
103 #endif // CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_INSTANCE_H_ | |
OLD | NEW |