OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_INSTANCE_H_ |
| 6 #define CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_INSTANCE_H_ |
| 7 |
| 8 #include <list> |
| 9 #include <string> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "content/browser/worker_host/worker_document_set.h" |
| 13 #include "content/browser/worker_host/worker_storage_partition.h" |
| 14 #include "content/common/content_export.h" |
| 15 #include "third_party/WebKit/public/web/WebContentSecurityPolicy.h" |
| 16 #include "url/gurl.h" |
| 17 |
| 18 namespace content { |
| 19 class ResourceContext; |
| 20 class SharedWorkerMessageFilter; |
| 21 |
| 22 class CONTENT_EXPORT SharedWorkerInstance { |
| 23 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, |
| 43 const base::string16& name, |
| 44 const base::string16& content_security_policy, |
| 45 blink::WebContentSecurityPolicyType security_policy_type, |
| 46 ResourceContext* resource_context, |
| 47 const WorkerStoragePartition& partition); |
| 48 ~SharedWorkerInstance(); |
| 49 |
| 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 |
| 59 // based on the algorithm in the WebWorkers spec - an instance matches if the |
| 60 // origins of the URLs match, and: |
| 61 // a) the names are non-empty and equal. |
| 62 // -or- |
| 63 // b) the names are both empty, and the urls are equal. |
| 64 bool Matches( |
| 65 const GURL& url, |
| 66 const base::string16& name, |
| 67 const WorkerStoragePartition& partition, |
| 68 ResourceContext* resource_context) const; |
| 69 |
| 70 // Accessors. |
| 71 bool closed() const { return closed_; } |
| 72 void set_closed(bool closed) { closed_ = closed; } |
| 73 const GURL& url() const { return url_; } |
| 74 const base::string16 name() const { return name_; } |
| 75 const base::string16 content_security_policy() const { |
| 76 return content_security_policy_; |
| 77 } |
| 78 blink::WebContentSecurityPolicyType security_policy_type() const { |
| 79 return security_policy_type_; |
| 80 } |
| 81 WorkerDocumentSet* worker_document_set() const { |
| 82 return worker_document_set_.get(); |
| 83 } |
| 84 ResourceContext* resource_context() const { |
| 85 return resource_context_; |
| 86 } |
| 87 const WorkerStoragePartition& partition() const { |
| 88 return partition_; |
| 89 } |
| 90 void set_load_failed(bool failed) { load_failed_ = failed; } |
| 91 bool load_failed() { return load_failed_; } |
| 92 |
| 93 private: |
| 94 GURL url_; |
| 95 bool closed_; |
| 96 base::string16 name_; |
| 97 base::string16 content_security_policy_; |
| 98 blink::WebContentSecurityPolicyType security_policy_type_; |
| 99 FilterList filters_; |
| 100 scoped_refptr<WorkerDocumentSet> worker_document_set_; |
| 101 ResourceContext* const resource_context_; |
| 102 WorkerStoragePartition partition_; |
| 103 bool load_failed_; |
| 104 }; |
| 105 |
| 106 } // namespace content |
| 107 |
| 108 |
| 109 #endif // CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_INSTANCE_H_ |
OLD | NEW |