Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: chrome/common/extensions/permissions/permission_set.cc

Issue 12209094: Support requesting subsets of host permissions using the permissions API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix urlpatternsettest Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
231 if (!apis_.Contains(set.apis()))
232 return false;
233
234 if (!explicit_hosts().Contains(set.explicit_hosts()))
235 return false;
236
237 if (!scriptable_hosts().Contains(set.scriptable_hosts()))
238 return false;
239
240 return true;
241 } 230 }
242 231
243 std::set<std::string> PermissionSet::GetAPIsAsStrings() const { 232 std::set<std::string> PermissionSet::GetAPIsAsStrings() const {
244 std::set<std::string> apis_str; 233 std::set<std::string> apis_str;
245 for (APIPermissionSet::const_iterator i = apis_.begin(); 234 for (APIPermissionSet::const_iterator i = apis_.begin();
246 i != apis_.end(); ++i) { 235 i != apis_.end(); ++i) {
247 apis_str.insert(i->name()); 236 apis_str.insert(i->name());
248 } 237 }
249 return apis_str; 238 return apis_str;
250 } 239 }
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 std::set<std::string> new_hosts_only; 600 std::set<std::string> new_hosts_only;
612 601
613 std::set_difference(new_hosts_set.begin(), new_hosts_set.end(), 602 std::set_difference(new_hosts_set.begin(), new_hosts_set.end(),
614 old_hosts_set.begin(), old_hosts_set.end(), 603 old_hosts_set.begin(), old_hosts_set.end(),
615 std::inserter(new_hosts_only, new_hosts_only.begin())); 604 std::inserter(new_hosts_only, new_hosts_only.begin()));
616 605
617 return !new_hosts_only.empty(); 606 return !new_hosts_only.empty();
618 } 607 }
619 608
620 } // namespace extensions 609 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698