OLD | NEW |
---|---|
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_PERMISSION_SET_H_ | 5 #ifndef EXTENSIONS_COMMON_PERMISSIONS_PERMISSION_SET_H_ |
6 #define EXTENSIONS_COMMON_PERMISSIONS_PERMISSION_SET_H_ | 6 #define EXTENSIONS_COMMON_PERMISSIONS_PERMISSION_SET_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "extensions/common/permissions/api_permission.h" | 13 #include "extensions/common/permissions/api_permission.h" |
14 #include "extensions/common/permissions/api_permission_set.h" | 14 #include "extensions/common/permissions/api_permission_set.h" |
15 #include "extensions/common/permissions/manifest_permission.h" | 15 #include "extensions/common/permissions/manifest_permission.h" |
16 #include "extensions/common/permissions/manifest_permission_set.h" | 16 #include "extensions/common/permissions/manifest_permission_set.h" |
17 #include "extensions/common/url_pattern_set.h" | 17 #include "extensions/common/url_pattern_set.h" |
18 | 18 |
19 namespace extensions { | 19 namespace extensions { |
20 | 20 |
21 // The PermissionSet is an immutable class that encapsulates an | 21 // The PermissionSet is an immutable class that encapsulates an |
22 // extension's permissions. The class exposes set operations for combining and | 22 // extension's permissions. The class exposes set operations for combining and |
23 // manipulating the permissions. | 23 // manipulating the permissions. |
24 // TODO(sashab): PermissionIDSet should be called PermissionSet. Once | 24 // TODO(sashab): PermissionIDSet should be called PermissionSet. Once |
25 // PermissionMessageProvider::GetCoalescedPermissionMessages() is the only | 25 // PermissionMessageProvider::GetCoalescedPermissionMessages() is the only |
26 // method used for generating permission messages, find the other users of this | 26 // method used for generating permission messages, find the other users of this |
27 // class and deprecate or rename it as appropriate. | 27 // class and deprecate or rename it as appropriate. |
28 class PermissionSet | 28 class PermissionSet { |
29 : public base::RefCountedThreadSafe<PermissionSet> { | |
30 public: | 29 public: |
31 // Creates an empty permission set (e.g. default permissions). | 30 // Creates an empty permission set (e.g. default permissions). |
32 PermissionSet(); | 31 PermissionSet(); |
33 | 32 |
34 // Creates a new permission set based on the specified data: the API | 33 // Creates a new permission set based on the specified data: the API |
35 // permissions, manifest key permissions, host permissions, and scriptable | 34 // permissions, manifest key permissions, host permissions, and scriptable |
36 // hosts. The effective hosts of the newly created permission set will be | 35 // hosts. The effective hosts of the newly created permission set will be |
37 // inferred from the given host permissions. | 36 // inferred from the given host permissions. |
38 PermissionSet(const APIPermissionSet& apis, | 37 PermissionSet(const APIPermissionSet& apis, |
39 const ManifestPermissionSet& manifest_permissions, | 38 const ManifestPermissionSet& manifest_permissions, |
40 const URLPatternSet& explicit_hosts, | 39 const URLPatternSet& explicit_hosts, |
41 const URLPatternSet& scriptable_hosts); | 40 const URLPatternSet& scriptable_hosts); |
41 ~PermissionSet(); | |
42 | 42 |
43 // Creates a new permission set equal to |set1| - |set2|. | 43 // Creates a new permission set equal to |set1| - |set2|. |
44 static scoped_refptr<const PermissionSet> CreateDifference( | 44 static scoped_ptr<const PermissionSet> CreateDifference( |
45 const PermissionSet& set1, | 45 const PermissionSet& set1, |
46 const PermissionSet& set2); | 46 const PermissionSet& set2); |
47 | 47 |
48 // Creates a new permission set equal to the intersection of |set1| and | 48 // Creates a new permission set equal to the intersection of |set1| and |
49 // |set2|. | 49 // |set2|. |
50 static scoped_refptr<const PermissionSet> CreateIntersection( | 50 static scoped_ptr<const PermissionSet> CreateIntersection( |
51 const PermissionSet& set1, | 51 const PermissionSet& set1, |
52 const PermissionSet& set2); | 52 const PermissionSet& set2); |
53 | 53 |
54 // Creates a new permission set equal to the union of |set1| and |set2|. | 54 // Creates a new permission set equal to the union of |set1| and |set2|. |
55 static scoped_refptr<const PermissionSet> CreateUnion( | 55 static scoped_ptr<const PermissionSet> CreateUnion(const PermissionSet& set1, |
56 const PermissionSet& set1, | 56 const PermissionSet& set2); |
57 const PermissionSet& set2); | |
58 | 57 |
59 bool operator==(const PermissionSet& rhs) const; | 58 bool operator==(const PermissionSet& rhs) const; |
60 bool operator!=(const PermissionSet& rhs) const; | 59 bool operator!=(const PermissionSet& rhs) const; |
61 | 60 |
61 // Returns a copy of this PermissionSet. | |
62 scoped_ptr<const PermissionSet> Clone() const; | |
not at google - send to devlin
2015/09/22 21:51:26
It's a bit odd to have a Clone() method but no DIS
Devlin
2015/09/23 17:08:59
Done.
| |
63 | |
62 // Returns true if every API or host permission available to |set| is also | 64 // Returns true if every API or host permission available to |set| is also |
63 // available to this. In other words, if the API permissions of |set| are a | 65 // available to this. In other words, if the API permissions of |set| are a |
64 // subset of this, and the host permissions in this encompass those in |set|. | 66 // subset of this, and the host permissions in this encompass those in |set|. |
65 bool Contains(const PermissionSet& set) const; | 67 bool Contains(const PermissionSet& set) const; |
66 | 68 |
67 // Gets the API permissions in this set as a set of strings. | 69 // Gets the API permissions in this set as a set of strings. |
68 std::set<std::string> GetAPIsAsStrings() const; | 70 std::set<std::string> GetAPIsAsStrings() const; |
69 | 71 |
70 // Returns true if this is an empty set (e.g., the default permission set). | 72 // Returns true if this is an empty set (e.g., the default permission set). |
71 bool IsEmpty() const; | 73 bool IsEmpty() const; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 | 118 |
117 const URLPatternSet& effective_hosts() const { return effective_hosts_; } | 119 const URLPatternSet& effective_hosts() const { return effective_hosts_; } |
118 | 120 |
119 const URLPatternSet& explicit_hosts() const { return explicit_hosts_; } | 121 const URLPatternSet& explicit_hosts() const { return explicit_hosts_; } |
120 | 122 |
121 const URLPatternSet& scriptable_hosts() const { return scriptable_hosts_; } | 123 const URLPatternSet& scriptable_hosts() const { return scriptable_hosts_; } |
122 | 124 |
123 private: | 125 private: |
124 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, GetWarningMessages_AudioVideo); | 126 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, GetWarningMessages_AudioVideo); |
125 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, AccessToDevicesMessages); | 127 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, AccessToDevicesMessages); |
126 friend class base::RefCountedThreadSafe<PermissionSet>; | |
127 | |
128 ~PermissionSet(); | |
129 | 128 |
130 // Adds permissions implied independently of other context. | 129 // Adds permissions implied independently of other context. |
131 void InitImplicitPermissions(); | 130 void InitImplicitPermissions(); |
132 | 131 |
133 // Initializes the effective host permission based on the data in this set. | 132 // Initializes the effective host permission based on the data in this set. |
134 void InitEffectiveHosts(); | 133 void InitEffectiveHosts(); |
135 | 134 |
136 // Initializes |has_access_to_most_hosts_|. | 135 // Initializes |has_access_to_most_hosts_|. |
137 void InitShouldWarnAllHosts() const; | 136 void InitShouldWarnAllHosts() const; |
138 | 137 |
(...skipping 14 matching lines...) Expand all Loading... | |
153 URLPatternSet scriptable_hosts_; | 152 URLPatternSet scriptable_hosts_; |
154 | 153 |
155 // The list of hosts this effectively grants access to. | 154 // The list of hosts this effectively grants access to. |
156 URLPatternSet effective_hosts_; | 155 URLPatternSet effective_hosts_; |
157 | 156 |
158 enum ShouldWarnAllHostsType { | 157 enum ShouldWarnAllHostsType { |
159 UNINITIALIZED = 0, | 158 UNINITIALIZED = 0, |
160 WARN_ALL_HOSTS, | 159 WARN_ALL_HOSTS, |
161 DONT_WARN_ALL_HOSTS | 160 DONT_WARN_ALL_HOSTS |
162 }; | 161 }; |
163 // Whether or not this permission set includes access to so many origins, we | 162 // Whether or not this permission set includes access to so many origins, we |
not at google - send to devlin
2015/09/22 21:51:26
Unrelated: this comment is wrong. It should just b
Devlin
2015/09/23 17:08:59
Done.
| |
164 // should treat it as all_hosts for warning purposes. | 163 // should treat it as all_hosts for warning purposes. |
165 // Lazily initialized (and therefore mutable). | 164 // Lazily initialized (and therefore mutable). |
166 mutable ShouldWarnAllHostsType should_warn_all_hosts_; | 165 mutable ShouldWarnAllHostsType should_warn_all_hosts_; |
167 }; | 166 }; |
168 | 167 |
169 } // namespace extensions | 168 } // namespace extensions |
170 | 169 |
171 #endif // EXTENSIONS_COMMON_PERMISSIONS_PERMISSION_SET_H_ | 170 #endif // EXTENSIONS_COMMON_PERMISSIONS_PERMISSION_SET_H_ |
OLD | NEW |