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 #include "content/browser/shared_worker/shared_worker_instance.h" | 5 #include "content/browser/shared_worker/shared_worker_instance.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/browser/worker_host/worker_document_set.h" | 8 #include "content/browser/worker_host/worker_document_set.h" |
9 | 9 |
10 namespace content { | 10 namespace content { |
(...skipping 28 matching lines...) Expand all Loading... |
39 if (i->filter() == filter && i->route_id() == route_id) { | 39 if (i->filter() == filter && i->route_id() == route_id) { |
40 i->set_message_port_id(message_port_id); | 40 i->set_message_port_id(message_port_id); |
41 return; | 41 return; |
42 } | 42 } |
43 } | 43 } |
44 } | 44 } |
45 | 45 |
46 bool SharedWorkerInstance::Matches(const GURL& match_url, | 46 bool SharedWorkerInstance::Matches(const GURL& match_url, |
47 const base::string16& match_name, | 47 const base::string16& match_name, |
48 const WorkerStoragePartition& partition, | 48 const WorkerStoragePartition& partition, |
49 ResourceContext* resource_context) const { | 49 ResourceContext* resource_context) const { |
50 // Only match open shared workers. | 50 // Only match open shared workers. |
51 if (closed_) | 51 if (closed_) |
52 return false; | 52 return false; |
53 | 53 |
54 // ResourceContext equivalence is being used as a proxy to ensure we only | 54 // ResourceContext equivalence is being used as a proxy to ensure we only |
55 // matched shared workers within the same BrowserContext. | 55 // matched shared workers within the same BrowserContext. |
56 if (resource_context_ != resource_context) | 56 if (resource_context_ != resource_context) |
57 return false; | 57 return false; |
58 | 58 |
59 // We must be in the same storage partition otherwise sharing will violate | 59 // We must be in the same storage partition otherwise sharing will violate |
60 // isolation. | 60 // isolation. |
61 if (!partition_.Equals(partition)) | 61 if (!partition_.Equals(partition)) |
62 return false; | 62 return false; |
63 | 63 |
64 if (url_.GetOrigin() != match_url.GetOrigin()) | 64 return UrlNameMatches(url_, name_, match_url, match_name); |
| 65 } |
| 66 |
| 67 // static |
| 68 bool SharedWorkerInstance::UrlNameMatches(const GURL& url1, |
| 69 const base::string16& name1, |
| 70 const GURL& url2, |
| 71 const base::string16& name2) { |
| 72 if (url1.GetOrigin() != url2.GetOrigin()) |
65 return false; | 73 return false; |
66 | 74 |
67 if (name_.empty() && match_name.empty()) | 75 if (name1.empty() && name2.empty()) |
68 return url_ == match_url; | 76 return url1 == url2; |
69 | 77 |
70 return name_ == match_name; | 78 return name1 == name2; |
71 } | 79 } |
72 | 80 |
73 void SharedWorkerInstance::AddFilter(SharedWorkerMessageFilter* filter, | 81 void SharedWorkerInstance::AddFilter(SharedWorkerMessageFilter* filter, |
74 int route_id) { | 82 int route_id) { |
75 CHECK(filter); | 83 CHECK(filter); |
76 if (!HasFilter(filter, route_id)) { | 84 if (!HasFilter(filter, route_id)) { |
77 FilterInfo info(filter, route_id); | 85 FilterInfo info(filter, route_id); |
78 filters_.push_back(info); | 86 filters_.push_back(info); |
79 } | 87 } |
80 } | 88 } |
(...skipping 11 matching lines...) Expand all Loading... |
92 int route_id) const { | 100 int route_id) const { |
93 for (FilterList::const_iterator i = filters_.begin(); i != filters_.end(); | 101 for (FilterList::const_iterator i = filters_.begin(); i != filters_.end(); |
94 ++i) { | 102 ++i) { |
95 if (i->filter() == filter && i->route_id() == route_id) | 103 if (i->filter() == filter && i->route_id() == route_id) |
96 return true; | 104 return true; |
97 } | 105 } |
98 return false; | 106 return false; |
99 } | 107 } |
100 | 108 |
101 } // namespace content | 109 } // namespace content |
OLD | NEW |