| 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_INSTANCE_H_ | 5 #ifndef CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_INSTANCE_H_ |
| 6 #define CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_INSTANCE_H_ | 6 #define CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_INSTANCE_H_ |
| 7 | 7 |
| 8 #include <list> | |
| 9 #include <string> | 8 #include <string> |
| 10 | 9 |
| 11 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 12 #include "content/browser/worker_host/worker_document_set.h" | |
| 13 #include "content/browser/worker_host/worker_storage_partition.h" | 11 #include "content/browser/worker_host/worker_storage_partition.h" |
| 14 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 15 #include "third_party/WebKit/public/web/WebContentSecurityPolicy.h" | 13 #include "third_party/WebKit/public/web/WebContentSecurityPolicy.h" |
| 16 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 17 | 15 |
| 18 namespace content { | 16 namespace content { |
| 19 class ResourceContext; | 17 class ResourceContext; |
| 20 class SharedWorkerMessageFilter; | |
| 21 | 18 |
| 22 class CONTENT_EXPORT SharedWorkerInstance { | 19 class CONTENT_EXPORT SharedWorkerInstance { |
| 23 public: | 20 public: |
| 24 // Unique identifier for a worker client. | |
| 25 class FilterInfo { | |
| 26 public: | |
| 27 FilterInfo(SharedWorkerMessageFilter* filter, int route_id) | |
| 28 : filter_(filter), route_id_(route_id), message_port_id_(0) { } | |
| 29 SharedWorkerMessageFilter* filter() const { return filter_; } | |
| 30 int route_id() const { return route_id_; } | |
| 31 int message_port_id() const { return message_port_id_; } | |
| 32 void set_message_port_id(int id) { message_port_id_ = id; } | |
| 33 | |
| 34 private: | |
| 35 SharedWorkerMessageFilter* filter_; | |
| 36 int route_id_; | |
| 37 int message_port_id_; | |
| 38 }; | |
| 39 | |
| 40 typedef std::list<FilterInfo> FilterList; | |
| 41 | |
| 42 SharedWorkerInstance(const GURL& url, | 21 SharedWorkerInstance(const GURL& url, |
| 43 const base::string16& name, | 22 const base::string16& name, |
| 44 const base::string16& content_security_policy, | 23 const base::string16& content_security_policy, |
| 45 blink::WebContentSecurityPolicyType security_policy_type, | 24 blink::WebContentSecurityPolicyType security_policy_type, |
| 46 ResourceContext* resource_context, | 25 ResourceContext* resource_context, |
| 47 const WorkerStoragePartition& partition); | 26 const WorkerStoragePartition& partition); |
| 48 ~SharedWorkerInstance(); | 27 ~SharedWorkerInstance(); |
| 49 | 28 |
| 50 void AddFilter(SharedWorkerMessageFilter* filter, int route_id); | |
| 51 void RemoveFilters(SharedWorkerMessageFilter* filter); | |
| 52 bool HasFilter(SharedWorkerMessageFilter* filter, int route_id) const; | |
| 53 void SetMessagePortID(SharedWorkerMessageFilter* filter, | |
| 54 int route_id, | |
| 55 int message_port_id); | |
| 56 const FilterList& filters() const { return filters_; } | |
| 57 | |
| 58 // Checks if this SharedWorkerInstance matches the passed url/name params | 29 // Checks if this SharedWorkerInstance matches the passed url/name params |
| 59 // based on the algorithm in the WebWorkers spec - an instance matches if the | 30 // based on the algorithm in the WebWorkers spec - an instance matches if the |
| 60 // origins of the URLs match, and: | 31 // origins of the URLs match, and: |
| 61 // a) the names are non-empty and equal. | 32 // a) the names are non-empty and equal. |
| 62 // -or- | 33 // -or- |
| 63 // b) the names are both empty, and the urls are equal. | 34 // b) the names are both empty, and the urls are equal. |
| 64 bool Matches( | 35 bool Matches( |
| 65 const GURL& url, | 36 const GURL& url, |
| 66 const base::string16& name, | 37 const base::string16& name, |
| 67 const WorkerStoragePartition& partition, | 38 const WorkerStoragePartition& partition, |
| 68 ResourceContext* resource_context) const; | 39 ResourceContext* resource_context) const; |
| 69 | 40 |
| 70 // Accessors. | 41 // Accessors. |
| 71 bool closed() const { return closed_; } | |
| 72 void set_closed(bool closed) { closed_ = closed; } | |
| 73 const GURL& url() const { return url_; } | 42 const GURL& url() const { return url_; } |
| 74 const base::string16 name() const { return name_; } | 43 const base::string16 name() const { return name_; } |
| 75 const base::string16 content_security_policy() const { | 44 const base::string16 content_security_policy() const { |
| 76 return content_security_policy_; | 45 return content_security_policy_; |
| 77 } | 46 } |
| 78 blink::WebContentSecurityPolicyType security_policy_type() const { | 47 blink::WebContentSecurityPolicyType security_policy_type() const { |
| 79 return security_policy_type_; | 48 return security_policy_type_; |
| 80 } | 49 } |
| 81 WorkerDocumentSet* worker_document_set() const { | |
| 82 return worker_document_set_.get(); | |
| 83 } | |
| 84 ResourceContext* resource_context() const { | 50 ResourceContext* resource_context() const { |
| 85 return resource_context_; | 51 return resource_context_; |
| 86 } | 52 } |
| 87 const WorkerStoragePartition& partition() const { | 53 const WorkerStoragePartition& partition() const { |
| 88 return partition_; | 54 return partition_; |
| 89 } | 55 } |
| 90 void set_load_failed(bool failed) { load_failed_ = failed; } | |
| 91 bool load_failed() { return load_failed_; } | |
| 92 | 56 |
| 93 private: | 57 private: |
| 94 GURL url_; | 58 const GURL url_; |
| 95 bool closed_; | 59 const base::string16 name_; |
| 96 base::string16 name_; | 60 const base::string16 content_security_policy_; |
| 97 base::string16 content_security_policy_; | 61 const blink::WebContentSecurityPolicyType security_policy_type_; |
| 98 blink::WebContentSecurityPolicyType security_policy_type_; | |
| 99 FilterList filters_; | |
| 100 scoped_refptr<WorkerDocumentSet> worker_document_set_; | |
| 101 ResourceContext* const resource_context_; | 62 ResourceContext* const resource_context_; |
| 102 WorkerStoragePartition partition_; | 63 const WorkerStoragePartition partition_; |
| 103 bool load_failed_; | |
| 104 }; | 64 }; |
| 105 | 65 |
| 106 } // namespace content | 66 } // namespace content |
| 107 | 67 |
| 108 | 68 |
| 109 #endif // CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_INSTANCE_H_ | 69 #endif // CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_INSTANCE_H_ |
| OLD | NEW |