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

Side by Side Diff: extensions/common/permissions/api_permission_set.h

Issue 51433002: Enable permission warnings from ManifestHandlers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Working on adding ManifestPermissionSet to PermissionSet. Created 7 years, 1 month 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_ 5 #ifndef EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_
6 #define EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_ 6 #define EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_
7 7
8 #include <iterator> 8 #include <iterator>
9 #include <map> 9 #include <map>
10 10
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 APIPermissionSet* api_permissions, 161 APIPermissionSet* api_permissions,
162 string16* error, 162 string16* error,
163 std::vector<std::string>* unhandled_permissions); 163 std::vector<std::string>* unhandled_permissions);
164 164
165 void AddImpliedPermissions(); 165 void AddImpliedPermissions();
166 166
167 private: 167 private:
168 APIPermissionMap map_; 168 APIPermissionMap map_;
169 }; 169 };
170 170
171
172 // TODO(rpaquay): Is ManifestPermission abstraction really needed, or should we
173 // delegate everything to ManifestHandlers?
174 class ManifestPermission {
175 public:
176 virtual std::string id() const = 0;
177
178 virtual std::string name() const = 0;
179
180 // Stores this into a new created |value|.
181 virtual scoped_ptr<base::Value> ToValue() const = 0;
182
183 // Clones this.
184 virtual ManifestPermission* Clone() const = 0;
185
186 // Returns a new API permission which equals this - |rhs|.
187 virtual ManifestPermission* Diff(const ManifestPermission* rhs)
188 const = 0;
189
190 // Returns a new API permission which equals the union of this and |rhs|.
191 virtual ManifestPermission* Union(const ManifestPermission* rhs)
192 const = 0;
193
194 // Returns a new API permission which equals the intersect of this and |rhs|.
195 virtual ManifestPermission* Intersect(const ManifestPermission* rhs)
196 const = 0;
197
198 // Returns true if |rhs| is a subset of this.
199 virtual bool Contains(const ManifestPermission* rhs) const = 0;
200
201 // Returns true if |rhs| is equal to this.
202 virtual bool Equal(const ManifestPermission* rhs) const = 0;
203 };
204
205 typedef std::map<std::string,
206 linked_ptr<ManifestPermission> > ManifestPermissionMap;
207
208 class ManifestPermissionSet {
Yoyo Zhou 2013/11/06 04:02:36 Would it make more sense to have the generic at th
rpaquay 2013/11/06 16:16:16 I *think* it might make sense. At the very least,
209 public:
210 class const_iterator :
211 public std::iterator<std::input_iterator_tag, const APIPermission*> {
212 public:
213 const_iterator(const ManifestPermissionMap::const_iterator& it);
214 const_iterator(const const_iterator& ids_it);
215
216 const_iterator& operator++() {
217 ++it_;
218 return *this;
219 }
220
221 const_iterator operator++(int) {
222 const_iterator tmp(it_++);
223 return tmp;
224 }
225
226 bool operator==(const const_iterator& rhs) const {
227 return it_ == rhs.it_;
228 }
229
230 bool operator!=(const const_iterator& rhs) const {
231 return it_ != rhs.it_;
232 }
233
234 const ManifestPermission* operator*() const {
235 return it_->second.get();
236 }
237
238 const ManifestPermission* operator->() const {
239 return it_->second.get();
240 }
241
242 private:
243 ManifestPermissionMap::const_iterator it_;
244 };
245
246 ManifestPermissionSet();
247
248 ManifestPermissionSet(const ManifestPermissionSet& set);
249
250 ~ManifestPermissionSet();
251
252 const_iterator begin() const {
253 return const_iterator(map().begin());
254 }
255
256 const_iterator end() const {
257 return map().end();
258 }
259
260 const_iterator find(std::string id) const {
261 return map().find(id);
262 }
263
264 const ManifestPermissionMap& map() const {
265 return map_;
266 }
267
268 ManifestPermissionMap& map() {
269 return map_;
270 }
271
272 void clear() {
273 map_.clear();
274 }
275
276 size_t count(std::string id) const {
277 return map().count(id);
278 }
279
280 bool empty() const {
281 return map().empty();
282 }
283
284 size_t erase(std::string id) {
285 return map().erase(id);
286 }
287
288 size_t size() const {
289 return map().size();
290 }
291
292 ManifestPermissionSet& operator=(const ManifestPermissionSet& rhs);
293
294 bool operator==(const ManifestPermissionSet& rhs) const;
295
296 bool operator!=(const ManifestPermissionSet& rhs) const {
297 return !operator==(rhs);
298 }
299
300 void insert(std::string id);
301
302 // Insert |permission| into the APIPermissionSet. The APIPermissionSet will
303 // take the ownership of |permission|,
304 void insert(ManifestPermission* permission);
305
306 bool Contains(const ManifestPermissionSet& rhs) const;
307
308 static void Difference(
309 const ManifestPermissionSet& set1,
310 const ManifestPermissionSet& set2,
311 ManifestPermissionSet* set3);
312
313 static void Intersection(
314 const ManifestPermissionSet& set1,
315 const ManifestPermissionSet& set2,
316 ManifestPermissionSet* set3);
317
318 static void Union(
319 const ManifestPermissionSet& set1,
320 const ManifestPermissionSet& set2,
321 ManifestPermissionSet* set3);
322
323 // Parses permissions from |permissions| and adds the parsed permissions to
324 // |manifest_permissions|. If |unhandled_permissions| is not NULL, the names
325 // of all permissions that couldn't be parsed will be added to this vector.
326 // If |error| is NULL, parsing will continue with the next permission if
327 // invalid data is detected. If |error| is not NULL, it will be set to an
328 // error message and false is returned when an invalid permission is found.
329 static bool ParseFromJSON(
330 const base::ListValue* permissions,
331 ManifestPermissionSet* manifest_permissions,
332 string16* error,
333 std::vector<std::string>* unhandled_permissions);
334
335 private:
336 static bool CreateManifestPermission(
337 const std::string& permission_name,
338 const base::Value* permission_value,
339 ManifestPermissionSet* manifest_permissions,
340 string16* error,
341 std::vector<std::string>* unhandled_permissions);
342
343 ManifestPermissionMap map_;
344 };
345
171 } // namespace extensions 346 } // namespace extensions
172 347
173 #endif // EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_ 348 #endif // EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698