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

Side by Side Diff: chrome/common/extensions/permissions/api_permission.h

Issue 10692160: Support socket endpoint permissions for AppsV2 Socket API. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix review issues and add some unit tests Created 8 years, 4 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
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_PERMISSIONS_API_PERMISSION_H_ 5 #ifndef CHROME_COMMON_EXTENSIONS_PERMISSIONS_API_PERMISSION_H_
6 #define CHROME_COMMON_EXTENSIONS_PERMISSIONS_API_PERMISSION_H_ 6 #define CHROME_COMMON_EXTENSIONS_PERMISSIONS_API_PERMISSION_H_
7 7
8 #include <map>
8 #include <set> 9 #include <set>
10 #include <string>
9 11
12 #include "base/callback.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/pickle.h"
10 #include "chrome/common/extensions/permissions/permission_message.h" 15 #include "chrome/common/extensions/permissions/permission_message.h"
11 16
17 namespace base {
18 class Value;
19 }
20
21 namespace IPC {
22 class Message;
23 }
24
12 namespace extensions { 25 namespace extensions {
13 26
27 class APIPermissionDetail;
14 class PermissionsInfo; 28 class PermissionsInfo;
15 29
16 // The APIPermission is an immutable class that describes a single 30 // The APIPermission is an immutable class that describes a single
17 // named permission (API permission). 31 // named permission (API permission).
18 class APIPermission { 32 class APIPermission {
19 public: 33 public:
20 enum ID { 34 enum ID {
21 // Error codes. 35 // Error codes.
22 kInvalid = -2, 36 kInvalid = -2,
23 kUnknown = -1, 37 kUnknown = -1,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // Indicates if the permission implies full access (native code). 111 // Indicates if the permission implies full access (native code).
98 kFlagImpliesFullAccess = 1 << 0, 112 kFlagImpliesFullAccess = 1 << 0,
99 113
100 // Indicates if the permission implies full URL access. 114 // Indicates if the permission implies full URL access.
101 kFlagImpliesFullURLAccess = 1 << 1, 115 kFlagImpliesFullURLAccess = 1 << 1,
102 116
103 // Indicates that extensions cannot specify the permission as optional. 117 // Indicates that extensions cannot specify the permission as optional.
104 kFlagCannotBeOptional = 1 << 3 118 kFlagCannotBeOptional = 1 << 3
105 }; 119 };
106 120
121 typedef APIPermissionDetail* (*DetailConstructor)(const APIPermission*);
122
107 typedef std::set<ID> IDSet; 123 typedef std::set<ID> IDSet;
108 124
109 ~APIPermission(); 125 ~APIPermission();
110 126
127 // Creates a permission detail instance.
128 scoped_refptr<APIPermissionDetail> CreateDetail() const;
129
111 // Returns the localized permission message associated with this api. 130 // Returns the localized permission message associated with this api.
112 // Use GetMessage_ to avoid name conflict with macro GetMessage on Windows. 131 // Use GetMessage_ to avoid name conflict with macro GetMessage on Windows.
113 PermissionMessage GetMessage_() const; 132 PermissionMessage GetMessage_() const;
114 133
115 int flags() const { return flags_; } 134 int flags() const { return flags_; }
116 135
117 ID id() const { return id_; } 136 ID id() const { return id_; }
118 137
119 // Returns the message id associated with this permission. 138 // Returns the message id associated with this permission.
120 PermissionMessage::ID message_id() const { 139 PermissionMessage::ID message_id() const {
(...skipping 21 matching lines...) Expand all
142 161
143 private: 162 private:
144 // Instances should only be constructed from within PermissionsInfo. 163 // Instances should only be constructed from within PermissionsInfo.
145 friend class PermissionsInfo; 164 friend class PermissionsInfo;
146 165
147 explicit APIPermission( 166 explicit APIPermission(
148 ID id, 167 ID id,
149 const char* name, 168 const char* name,
150 int l10n_message_id, 169 int l10n_message_id,
151 PermissionMessage::ID message_id, 170 PermissionMessage::ID message_id,
152 int flags); 171 int flags,
172 DetailConstructor detail_constructor);
153 173
154 // Register ALL the permissions! 174 // Register ALL the permissions!
155 static void RegisterAllPermissions(PermissionsInfo* info); 175 static void RegisterAllPermissions(PermissionsInfo* info);
156 176
157 ID id_; 177 const ID id_;
158 const char* name_; 178 const char* const name_;
159 int flags_; 179 const int flags_;
160 int l10n_message_id_; 180 const int l10n_message_id_;
161 PermissionMessage::ID message_id_; 181 const PermissionMessage::ID message_id_;
182 const DetailConstructor detail_constructor_;
162 }; 183 };
163 184
164 typedef std::set<APIPermission::ID> APIPermissionSet; 185 // TODO(penghuang): Rename APIPermissionDetail to APIPermission,
186 // and APIPermssion to APIPermissionInfo.
187 class APIPermissionDetail : public base::RefCounted<APIPermissionDetail> {
188 public:
189 struct CheckParam {
190 };
191
192 explicit APIPermissionDetail(const APIPermission* permission)
193 : permission_(permission) {
194 DCHECK(permission);
195 }
196
197 // Returns the id of this permission.
198 APIPermission::ID id() const {
199 return permission()->id();
200 }
201
202 // Returns the name of this permission.
203 const char* name() const {
204 return permission()->name();
205 }
206
207 // Returns the APIPermission of this permission.
208 const APIPermission* permission() const {
209 return permission_;
210 }
211
212 // Returns true if the given permission detail is allowed.
213 virtual bool Check(const CheckParam* param) const = 0;
214
215 // Returns true if |detail| is a subset of this.
216 virtual bool Contains(const APIPermissionDetail* detail) const = 0;
217
218 // Returns true if |detail| is equal to this.
219 virtual bool Equal(const APIPermissionDetail* detail) const = 0;
220
221 // Parses the detail from |value|. Returns false if error happens.
222 virtual bool FromValue(const base::Value* value) = 0;
223
224 // Stores this into a new created |value|.
225 virtual void ToValue(base::Value** value) const = 0;
226
227 // Clones this.
228 virtual APIPermissionDetail* Clone() const = 0;
229
230 // Returns a new API permission detail which equals this - |detail|.
231 virtual APIPermissionDetail* Diff(
232 const APIPermissionDetail* detail) const = 0;
233
234 // Returns a new API permission detail which equals the union of this and
235 // |detail|.
236 virtual APIPermissionDetail* Union(
237 const APIPermissionDetail* detail) const = 0;
238
239 // Returns a new API permission detail which equals the intersect of this and
240 // |detail|.
241 virtual APIPermissionDetail* Intersect(
242 const APIPermissionDetail* detail) const = 0;
243
244 // IPC functions
245 // Writes this into the given IPC message |m|.
246 virtual void Write(IPC::Message* m) const = 0;
247
248 // Reads from the given IPC message |m|.
249 virtual bool Read(const IPC::Message* m, PickleIterator* iter) = 0;
250
251 // Logs this detail.
252 virtual void Log(std::string* log) const = 0;
253
254 protected:
255 friend base::RefCounted<APIPermissionDetail>;
256 virtual ~APIPermissionDetail();
257
258 private:
259 const APIPermission* const permission_;
260 };
165 261
166 } // namespace extensions 262 } // namespace extensions
167 263
168 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_API_PERMISSION_H_ 264 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_API_PERMISSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698