Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 | |
| 19 class Value; | |
| 20 | |
|
miket_OOO
2012/07/31 18:18:37
Vertical whitespace inside forward-declaration nam
Peng
2012/07/31 19:32:28
Done.
| |
| 21 } | |
| 22 | |
| 23 namespace IPC { | |
| 24 | |
| 25 class Message; | |
| 26 | |
| 27 } | |
| 28 | |
| 12 namespace extensions { | 29 namespace extensions { |
| 13 | 30 |
| 31 class APIPermissionDetail; | |
| 14 class PermissionsInfo; | 32 class PermissionsInfo; |
| 15 | 33 |
| 16 // The APIPermission is an immutable class that describes a single | 34 // The APIPermission is an immutable class that describes a single |
| 17 // named permission (API permission). | 35 // named permission (API permission). |
| 18 class APIPermission { | 36 class APIPermission { |
| 19 public: | 37 public: |
| 20 enum ID { | 38 enum ID { |
| 21 // Error codes. | 39 // Error codes. |
| 22 kInvalid = -2, | 40 kInvalid = -2, |
| 23 kUnknown = -1, | 41 kUnknown = -1, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 // Indicates if the permission implies full access (native code). | 115 // Indicates if the permission implies full access (native code). |
| 98 kFlagImpliesFullAccess = 1 << 0, | 116 kFlagImpliesFullAccess = 1 << 0, |
| 99 | 117 |
| 100 // Indicates if the permission implies full URL access. | 118 // Indicates if the permission implies full URL access. |
| 101 kFlagImpliesFullURLAccess = 1 << 1, | 119 kFlagImpliesFullURLAccess = 1 << 1, |
| 102 | 120 |
| 103 // Indicates that extensions cannot specify the permission as optional. | 121 // Indicates that extensions cannot specify the permission as optional. |
| 104 kFlagCannotBeOptional = 1 << 3 | 122 kFlagCannotBeOptional = 1 << 3 |
| 105 }; | 123 }; |
| 106 | 124 |
| 125 typedef base::Callback<APIPermissionDetail *(void)> DetailConstructor; | |
| 126 | |
| 107 typedef std::set<ID> IDSet; | 127 typedef std::set<ID> IDSet; |
| 108 | 128 |
| 109 ~APIPermission(); | 129 ~APIPermission(); |
| 110 | 130 |
| 131 // Creates a permission detail instance. | |
| 132 scoped_refptr<APIPermissionDetail> CreateDetail() const; | |
| 133 | |
| 111 // Returns the localized permission message associated with this api. | 134 // Returns the localized permission message associated with this api. |
| 112 // Use GetMessage_ to avoid name conflict with macro GetMessage on Windows. | 135 // Use GetMessage_ to avoid name conflict with macro GetMessage on Windows. |
| 113 PermissionMessage GetMessage_() const; | 136 PermissionMessage GetMessage_() const; |
| 114 | 137 |
| 115 int flags() const { return flags_; } | 138 int flags() const { return flags_; } |
| 116 | 139 |
| 117 ID id() const { return id_; } | 140 ID id() const { return id_; } |
| 118 | 141 |
| 119 // Returns the message id associated with this permission. | 142 // Returns the message id associated with this permission. |
| 120 PermissionMessage::ID message_id() const { | 143 PermissionMessage::ID message_id() const { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 142 | 165 |
| 143 private: | 166 private: |
| 144 // Instances should only be constructed from within PermissionsInfo. | 167 // Instances should only be constructed from within PermissionsInfo. |
| 145 friend class PermissionsInfo; | 168 friend class PermissionsInfo; |
| 146 | 169 |
| 147 explicit APIPermission( | 170 explicit APIPermission( |
| 148 ID id, | 171 ID id, |
| 149 const char* name, | 172 const char* name, |
| 150 int l10n_message_id, | 173 int l10n_message_id, |
| 151 PermissionMessage::ID message_id, | 174 PermissionMessage::ID message_id, |
| 152 int flags); | 175 int flags, |
| 176 const DetailConstructor& detail_constructor); | |
| 153 | 177 |
| 154 // Register ALL the permissions! | 178 // Register ALL the permissions! |
| 155 static void RegisterAllPermissions(PermissionsInfo* info); | 179 static void RegisterAllPermissions(PermissionsInfo* info); |
| 156 | 180 |
| 157 ID id_; | 181 ID id_; |
| 158 const char* name_; | 182 const char* name_; |
| 159 int flags_; | 183 int flags_; |
| 160 int l10n_message_id_; | 184 int l10n_message_id_; |
| 161 PermissionMessage::ID message_id_; | 185 PermissionMessage::ID message_id_; |
| 186 DetailConstructor detail_constructor_; | |
| 162 }; | 187 }; |
| 163 | 188 |
| 164 typedef std::set<APIPermission::ID> APIPermissionSet; | 189 class APIPermissionDetail : public base::RefCounted<APIPermissionDetail> { |
| 190 public: | |
| 191 struct DetailParam { | |
| 192 }; | |
| 193 | |
| 194 APIPermissionDetail(const APIPermission* permission) | |
| 195 : permission_(permission) { } | |
|
miket_OOO
2012/07/31 18:18:37
As long as you have a constructor body, might as w
Peng
2012/07/31 19:32:28
Done.
| |
| 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 DetailParam* detail) const = 0; | |
| 214 | |
| 215 // Returns true if |detail| is a subset of this. | |
| 216 virtual bool Contains(const APIPermissionDetail*detail) const = 0; | |
|
miket_OOO
2012/07/31 18:18:37
space after *
Peng
2012/07/31 19:32:28
Done.
| |
| 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 created differences detail objectbetween this and | |
|
miket_OOO
2012/07/31 18:18:37
typo. Also, this description is not fluent. "Retur
Peng
2012/07/31 19:32:28
Done.
| |
| 231 // |detail| (this - |detal|). | |
|
miket_OOO
2012/07/31 18:18:37
typo
Peng
2012/07/31 19:32:28
Done.
| |
| 232 virtual APIPermissionDetail* Diff( | |
| 233 const APIPermissionDetail* detail) const = 0; | |
| 234 | |
| 235 // Returns a new created union detail of this and |detail|. | |
|
miket_OOO
2012/07/31 18:18:37
same (et seq.)
Peng
2012/07/31 19:32:28
Done.
| |
| 236 virtual APIPermissionDetail* Union( | |
| 237 const APIPermissionDetail* detail) const = 0; | |
| 238 | |
| 239 // Returns a new created intersect detail of this and |detail|. | |
| 240 virtual APIPermissionDetail* Intersect( | |
| 241 const APIPermissionDetail* detail) const = 0; | |
| 242 | |
| 243 // IPC functions | |
| 244 // Writes this into the given IPC message |m|. | |
| 245 virtual void Write(IPC::Message *m) const = 0; | |
| 246 | |
| 247 // Reads from the given IPC message |m|. | |
| 248 virtual bool Read(const IPC::Message *m, PickleIterator *iter) = 0; | |
| 249 | |
| 250 // Logs this detail. | |
| 251 virtual void Log(std::string *l) const = 0; | |
|
miket_OOO
2012/07/31 18:18:37
As a general readability rule, avoid lowercase L a
Peng
2012/07/31 19:32:28
Done.
| |
| 252 | |
| 253 protected: | |
| 254 friend base::RefCounted<APIPermissionDetail>; | |
| 255 virtual ~APIPermissionDetail(); | |
| 256 | |
| 257 private: | |
| 258 const APIPermission* const permission_; | |
| 259 }; | |
| 165 | 260 |
| 166 } // namespace extensions | 261 } // namespace extensions |
| 167 | 262 |
| 168 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_API_PERMISSION_H_ | 263 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_API_PERMISSION_H_ |
| OLD | NEW |