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

Side by Side Diff: chrome/common/extensions/extension_permission_set.h

Issue 10049006: Add OAuth2 scopes to the ExtensionPermissionSet and granted permissions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_PERMISSION_SET_H_ 5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_PERMISSION_SET_H_
6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_PERMISSION_SET_H_ 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_PERMISSION_SET_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/callback.h"
Yoyo Zhou 2012/04/24 23:16:36 You don't seem to use this.
jstritar 2012/04/24 23:33:34 Done.
14 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
15 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/singleton.h" 18 #include "base/memory/singleton.h"
18 #include "base/string16.h" 19 #include "base/string16.h"
19 #include "chrome/common/extensions/url_pattern_set.h" 20 #include "chrome/common/extensions/url_pattern_set.h"
20 21
21 // TODO(jstritar): Move each class to its own file in extensions/permissions. 22 // TODO(jstritar): Move each class to its own file in extensions/permissions.
22 23
23 class Extension; 24 class Extension;
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 IDMap id_map_; 266 IDMap id_map_;
266 NameMap name_map_; 267 NameMap name_map_;
267 268
268 size_t hosted_app_permission_count_; 269 size_t hosted_app_permission_count_;
269 size_t permission_count_; 270 size_t permission_count_;
270 271
271 friend struct DefaultSingletonTraits<ExtensionPermissionsInfo>; 272 friend struct DefaultSingletonTraits<ExtensionPermissionsInfo>;
272 DISALLOW_COPY_AND_ASSIGN(ExtensionPermissionsInfo); 273 DISALLOW_COPY_AND_ASSIGN(ExtensionPermissionsInfo);
273 }; 274 };
274 275
276 typedef std::set<std::string> ExtensionOAuth2Scopes;
277
275 // The ExtensionPermissionSet is an immutable class that encapsulates an 278 // The ExtensionPermissionSet is an immutable class that encapsulates an
276 // extension's permissions. The class exposes set operations for combining and 279 // extension's permissions. The class exposes set operations for combining and
277 // manipulating the permissions. 280 // manipulating the permissions.
278 class ExtensionPermissionSet 281 class ExtensionPermissionSet
279 : public base::RefCountedThreadSafe<ExtensionPermissionSet> { 282 : public base::RefCountedThreadSafe<ExtensionPermissionSet> {
280 public: 283 public:
284
Yoyo Zhou 2012/04/24 23:16:36 nit: why this extra line?
jstritar 2012/04/24 23:33:34 Done.
281 // Creates an empty permission set (e.g. default permissions). 285 // Creates an empty permission set (e.g. default permissions).
282 ExtensionPermissionSet(); 286 ExtensionPermissionSet();
283 287
284 // Creates a new permission set based on the |extension| manifest data, and 288 // Creates a new permission set based on the |extension| manifest data, and
285 // the api and host permissions (|apis| and |hosts|). The effective hosts 289 // the api and host permissions (|apis| and |hosts|). The effective hosts
286 // of the newly created permission set will be inferred from the |extension| 290 // of the newly created permission set will be inferred from the |extension|
287 // manifest, |apis| and |hosts|. 291 // manifest, |apis| and |hosts|.
288 ExtensionPermissionSet(const Extension* extension, 292 ExtensionPermissionSet(const Extension* extension,
289 const ExtensionAPIPermissionSet& apis, 293 const ExtensionAPIPermissionSet& apis,
290 const URLPatternSet& explicit_hosts); 294 const URLPatternSet& explicit_hosts,
295 const ExtensionOAuth2Scopes& scopes);
296
291 297
292 // Creates a new permission set based on the specified data. 298 // Creates a new permission set based on the specified data.
293 ExtensionPermissionSet(const ExtensionAPIPermissionSet& apis, 299 ExtensionPermissionSet(const ExtensionAPIPermissionSet& apis,
294 const URLPatternSet& explicit_hosts, 300 const URLPatternSet& explicit_hosts,
295 const URLPatternSet& scriptable_hosts); 301 const URLPatternSet& scriptable_hosts);
296 302
303 // Creates a new permission set that has oauth scopes in it.
304 ExtensionPermissionSet(const ExtensionAPIPermissionSet& apis,
305 const URLPatternSet& explicit_hosts,
306 const URLPatternSet& scriptable_hosts,
307 const ExtensionOAuth2Scopes& scopes);
308
309 // Creates a new permission set containing only oauth scopes.
310 explicit ExtensionPermissionSet(const ExtensionOAuth2Scopes& scopes);
311
297 ~ExtensionPermissionSet(); 312 ~ExtensionPermissionSet();
298 313
299 // Creates a new permission set equal to |set1| - |set2|, passing ownership of 314 // Creates a new permission set equal to |set1| - |set2|, passing ownership of
300 // the new set to the caller. 315 // the new set to the caller.
301 static ExtensionPermissionSet* CreateDifference( 316 static ExtensionPermissionSet* CreateDifference(
302 const ExtensionPermissionSet* set1, const ExtensionPermissionSet* set2); 317 const ExtensionPermissionSet* set1, const ExtensionPermissionSet* set2);
303 318
304 // Creates a new permission set equal to the intersection of |set1| and 319 // Creates a new permission set equal to the intersection of |set1| and
305 // |set2|, passing ownership of the new set to the caller. 320 // |set2|, passing ownership of the new set to the caller.
306 static ExtensionPermissionSet* CreateIntersection( 321 static ExtensionPermissionSet* CreateIntersection(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 bool HasLessPrivilegesThan(const ExtensionPermissionSet* permissions) const; 390 bool HasLessPrivilegesThan(const ExtensionPermissionSet* permissions) const;
376 391
377 const ExtensionAPIPermissionSet& apis() const { return apis_; } 392 const ExtensionAPIPermissionSet& apis() const { return apis_; }
378 393
379 const URLPatternSet& effective_hosts() const { return effective_hosts_; } 394 const URLPatternSet& effective_hosts() const { return effective_hosts_; }
380 395
381 const URLPatternSet& explicit_hosts() const { return explicit_hosts_; } 396 const URLPatternSet& explicit_hosts() const { return explicit_hosts_; }
382 397
383 const URLPatternSet& scriptable_hosts() const { return scriptable_hosts_; } 398 const URLPatternSet& scriptable_hosts() const { return scriptable_hosts_; }
384 399
400 const ExtensionOAuth2Scopes& scopes() const { return scopes_; }
401
385 private: 402 private:
386 FRIEND_TEST_ALL_PREFIXES(ExtensionPermissionsTest, 403 FRIEND_TEST_ALL_PREFIXES(ExtensionPermissionsTest,
387 HasLessHostPrivilegesThan); 404 HasLessHostPrivilegesThan);
388 405
389 friend class base::RefCountedThreadSafe<ExtensionPermissionSet>; 406 friend class base::RefCountedThreadSafe<ExtensionPermissionSet>;
390 407
391 static std::set<std::string> GetDistinctHosts( 408 static std::set<std::string> GetDistinctHosts(
392 const URLPatternSet& host_patterns, 409 const URLPatternSet& host_patterns,
393 bool include_rcd, 410 bool include_rcd,
394 bool exclude_file_scheme); 411 bool exclude_file_scheme);
(...skipping 10 matching lines...) Expand all
405 // Returns true if |permissions| has an elevated API privilege level than 422 // Returns true if |permissions| has an elevated API privilege level than
406 // this set. 423 // this set.
407 bool HasLessAPIPrivilegesThan( 424 bool HasLessAPIPrivilegesThan(
408 const ExtensionPermissionSet* permissions) const; 425 const ExtensionPermissionSet* permissions) const;
409 426
410 // Returns true if |permissions| has more host permissions compared to this 427 // Returns true if |permissions| has more host permissions compared to this
411 // set. 428 // set.
412 bool HasLessHostPrivilegesThan( 429 bool HasLessHostPrivilegesThan(
413 const ExtensionPermissionSet* permissions) const; 430 const ExtensionPermissionSet* permissions) const;
414 431
432 // Returns true if |permissions| has more oauth2 scopes compared to this set.
433 bool HasLessScopesThan(const ExtensionPermissionSet* permissions) const;
434
415 // The api list is used when deciding if an extension can access certain 435 // The api list is used when deciding if an extension can access certain
416 // extension APIs and features. 436 // extension APIs and features.
417 ExtensionAPIPermissionSet apis_; 437 ExtensionAPIPermissionSet apis_;
418 438
419 // The list of hosts that can be accessed directly from the extension. 439 // The list of hosts that can be accessed directly from the extension.
420 // TODO(jstritar): Rename to "hosts_"? 440 // TODO(jstritar): Rename to "hosts_"?
421 URLPatternSet explicit_hosts_; 441 URLPatternSet explicit_hosts_;
422 442
423 // The list of hosts that can be scripted by content scripts. 443 // The list of hosts that can be scripted by content scripts.
424 // TODO(jstritar): Rename to "user_script_hosts_"? 444 // TODO(jstritar): Rename to "user_script_hosts_"?
425 URLPatternSet scriptable_hosts_; 445 URLPatternSet scriptable_hosts_;
426 446
427 // The list of hosts this effectively grants access to. 447 // The list of hosts this effectively grants access to.
428 URLPatternSet effective_hosts_; 448 URLPatternSet effective_hosts_;
449
450 // A set of oauth2 scopes that are specific to Google Accounts.
Yoyo Zhou 2012/04/24 23:16:36 Can you elaborate on what these are used for in th
jstritar 2012/04/24 23:33:34 Done.
451 ExtensionOAuth2Scopes scopes_;
429 }; 452 };
430 453
431 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_PERMISSION_SET_H_ 454 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_PERMISSION_SET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698