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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 &explicit_hosts); | 190 &explicit_hosts); |
191 | 191 |
192 URLPatternSet scriptable_hosts; | 192 URLPatternSet scriptable_hosts; |
193 URLPatternSet::CreateUnion(set1_safe->scriptable_hosts(), | 193 URLPatternSet::CreateUnion(set1_safe->scriptable_hosts(), |
194 set2_safe->scriptable_hosts(), | 194 set2_safe->scriptable_hosts(), |
195 &scriptable_hosts); | 195 &scriptable_hosts); |
196 | 196 |
197 return new PermissionSet(apis, explicit_hosts, scriptable_hosts); | 197 return new PermissionSet(apis, explicit_hosts, scriptable_hosts); |
198 } | 198 } |
199 | 199 |
| 200 // static |
| 201 PermissionSet* PermissionSet::ExcludeNotInManifestPermissions( |
| 202 const PermissionSet* set) { |
| 203 if (!set) |
| 204 return new PermissionSet(); |
| 205 |
| 206 APIPermissionSet apis; |
| 207 for (APIPermissionSet::const_iterator i = set->apis().begin(); |
| 208 i != set->apis().end(); ++i) { |
| 209 if (!i->ManifestEntryForbidden()) |
| 210 apis.insert(i->Clone()); |
| 211 } |
| 212 |
| 213 return new PermissionSet( |
| 214 apis, set->explicit_hosts(), set->scriptable_hosts()); |
| 215 } |
| 216 |
200 bool PermissionSet::operator==( | 217 bool PermissionSet::operator==( |
201 const PermissionSet& rhs) const { | 218 const PermissionSet& rhs) const { |
202 return apis_ == rhs.apis_ && | 219 return apis_ == rhs.apis_ && |
203 scriptable_hosts_ == rhs.scriptable_hosts_ && | 220 scriptable_hosts_ == rhs.scriptable_hosts_ && |
204 explicit_hosts_ == rhs.explicit_hosts_; | 221 explicit_hosts_ == rhs.explicit_hosts_; |
205 } | 222 } |
206 | 223 |
207 bool PermissionSet::Contains(const PermissionSet& set) const { | 224 bool PermissionSet::Contains(const PermissionSet& set) const { |
208 // Every set includes the empty set. | 225 // Every set includes the empty set. |
209 if (set.IsEmpty()) | 226 if (set.IsEmpty()) |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 std::set<std::string> new_hosts_only; | 606 std::set<std::string> new_hosts_only; |
590 | 607 |
591 std::set_difference(new_hosts_set.begin(), new_hosts_set.end(), | 608 std::set_difference(new_hosts_set.begin(), new_hosts_set.end(), |
592 old_hosts_set.begin(), old_hosts_set.end(), | 609 old_hosts_set.begin(), old_hosts_set.end(), |
593 std::inserter(new_hosts_only, new_hosts_only.begin())); | 610 std::inserter(new_hosts_only, new_hosts_only.begin())); |
594 | 611 |
595 return !new_hosts_only.empty(); | 612 return !new_hosts_only.empty(); |
596 } | 613 } |
597 | 614 |
598 } // namespace extensions | 615 } // namespace extensions |
OLD | NEW |