OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/common/extensions/permissions/permission_set.h" | 5 #include "chrome/common/extensions/permissions/permission_set.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 } | 217 } |
218 | 218 |
219 bool PermissionSet::operator==( | 219 bool PermissionSet::operator==( |
220 const PermissionSet& rhs) const { | 220 const PermissionSet& rhs) const { |
221 return apis_ == rhs.apis_ && | 221 return apis_ == rhs.apis_ && |
222 scriptable_hosts_ == rhs.scriptable_hosts_ && | 222 scriptable_hosts_ == rhs.scriptable_hosts_ && |
223 explicit_hosts_ == rhs.explicit_hosts_; | 223 explicit_hosts_ == rhs.explicit_hosts_; |
224 } | 224 } |
225 | 225 |
226 bool PermissionSet::Contains(const PermissionSet& set) const { | 226 bool PermissionSet::Contains(const PermissionSet& set) const { |
227 // Every set includes the empty set. | 227 return apis_.Contains(set.apis()) && |
228 if (set.IsEmpty()) | 228 explicit_hosts().Contains(set.explicit_hosts()) && |
229 return true; | 229 scriptable_hosts().Contains(set.scriptable_hosts()); |
| 230 } |
230 | 231 |
231 if (!apis_.Contains(set.apis())) | 232 bool PermissionSet::ContainsOrEncompasses(const PermissionSet& set) const { |
232 return false; | 233 return apis_.Contains(set.apis()) && |
233 | 234 explicit_hosts().Encompasses(set.explicit_hosts()) && |
234 if (!explicit_hosts().Contains(set.explicit_hosts())) | 235 scriptable_hosts().Encompasses(set.scriptable_hosts()); |
235 return false; | |
236 | |
237 if (!scriptable_hosts().Contains(set.scriptable_hosts())) | |
238 return false; | |
239 | |
240 return true; | |
241 } | 236 } |
242 | 237 |
243 std::set<std::string> PermissionSet::GetAPIsAsStrings() const { | 238 std::set<std::string> PermissionSet::GetAPIsAsStrings() const { |
244 std::set<std::string> apis_str; | 239 std::set<std::string> apis_str; |
245 for (APIPermissionSet::const_iterator i = apis_.begin(); | 240 for (APIPermissionSet::const_iterator i = apis_.begin(); |
246 i != apis_.end(); ++i) { | 241 i != apis_.end(); ++i) { |
247 apis_str.insert(i->name()); | 242 apis_str.insert(i->name()); |
248 } | 243 } |
249 return apis_str; | 244 return apis_str; |
250 } | 245 } |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 std::set<std::string> new_hosts_only; | 606 std::set<std::string> new_hosts_only; |
612 | 607 |
613 std::set_difference(new_hosts_set.begin(), new_hosts_set.end(), | 608 std::set_difference(new_hosts_set.begin(), new_hosts_set.end(), |
614 old_hosts_set.begin(), old_hosts_set.end(), | 609 old_hosts_set.begin(), old_hosts_set.end(), |
615 std::inserter(new_hosts_only, new_hosts_only.begin())); | 610 std::inserter(new_hosts_only, new_hosts_only.begin())); |
616 | 611 |
617 return !new_hosts_only.empty(); | 612 return !new_hosts_only.empty(); |
618 } | 613 } |
619 | 614 |
620 } // namespace extensions | 615 } // namespace extensions |
OLD | NEW |