| 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 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // Indicates if the permission implies full access (native code). | 112 // Indicates if the permission implies full access (native code). |
| 99 kFlagImpliesFullAccess = 1 << 0, | 113 kFlagImpliesFullAccess = 1 << 0, |
| 100 | 114 |
| 101 // Indicates if the permission implies full URL access. | 115 // Indicates if the permission implies full URL access. |
| 102 kFlagImpliesFullURLAccess = 1 << 1, | 116 kFlagImpliesFullURLAccess = 1 << 1, |
| 103 | 117 |
| 104 // Indicates that extensions cannot specify the permission as optional. | 118 // Indicates that extensions cannot specify the permission as optional. |
| 105 kFlagCannotBeOptional = 1 << 3 | 119 kFlagCannotBeOptional = 1 << 3 |
| 106 }; | 120 }; |
| 107 | 121 |
| 122 typedef APIPermissionDetail* (*DetailConstructor)(const APIPermission*); |
| 123 |
| 108 typedef std::set<ID> IDSet; | 124 typedef std::set<ID> IDSet; |
| 109 | 125 |
| 110 ~APIPermission(); | 126 ~APIPermission(); |
| 111 | 127 |
| 128 // Creates a permission detail instance. |
| 129 scoped_refptr<APIPermissionDetail> CreateDetail() const; |
| 130 |
| 112 // Returns the localized permission message associated with this api. | 131 // Returns the localized permission message associated with this api. |
| 113 // Use GetMessage_ to avoid name conflict with macro GetMessage on Windows. | 132 // Use GetMessage_ to avoid name conflict with macro GetMessage on Windows. |
| 114 PermissionMessage GetMessage_() const; | 133 PermissionMessage GetMessage_() const; |
| 115 | 134 |
| 116 int flags() const { return flags_; } | 135 int flags() const { return flags_; } |
| 117 | 136 |
| 118 ID id() const { return id_; } | 137 ID id() const { return id_; } |
| 119 | 138 |
| 120 // Returns the message id associated with this permission. | 139 // Returns the message id associated with this permission. |
| 121 PermissionMessage::ID message_id() const { | 140 PermissionMessage::ID message_id() const { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 143 | 162 |
| 144 private: | 163 private: |
| 145 // Instances should only be constructed from within PermissionsInfo. | 164 // Instances should only be constructed from within PermissionsInfo. |
| 146 friend class PermissionsInfo; | 165 friend class PermissionsInfo; |
| 147 | 166 |
| 148 explicit APIPermission( | 167 explicit APIPermission( |
| 149 ID id, | 168 ID id, |
| 150 const char* name, | 169 const char* name, |
| 151 int l10n_message_id, | 170 int l10n_message_id, |
| 152 PermissionMessage::ID message_id, | 171 PermissionMessage::ID message_id, |
| 153 int flags); | 172 int flags, |
| 173 DetailConstructor detail_constructor); |
| 154 | 174 |
| 155 // Register ALL the permissions! | 175 // Register ALL the permissions! |
| 156 static void RegisterAllPermissions(PermissionsInfo* info); | 176 static void RegisterAllPermissions(PermissionsInfo* info); |
| 157 | 177 |
| 158 ID id_; | 178 const ID id_; |
| 159 const char* name_; | 179 const char* const name_; |
| 160 int flags_; | 180 const int flags_; |
| 161 int l10n_message_id_; | 181 const int l10n_message_id_; |
| 162 PermissionMessage::ID message_id_; | 182 const PermissionMessage::ID message_id_; |
| 183 const DetailConstructor detail_constructor_; |
| 163 }; | 184 }; |
| 164 | 185 |
| 165 typedef std::set<APIPermission::ID> APIPermissionSet; | 186 // TODO(penghuang): Rename APIPermissionDetail to APIPermission, |
| 187 // and APIPermssion to APIPermissionInfo. |
| 188 class APIPermissionDetail : public base::RefCounted<APIPermissionDetail> { |
| 189 public: |
| 190 struct CheckParam { |
| 191 }; |
| 192 |
| 193 explicit APIPermissionDetail(const APIPermission* permission) |
| 194 : permission_(permission) { |
| 195 DCHECK(permission); |
| 196 } |
| 197 |
| 198 // Returns the id of this permission. |
| 199 APIPermission::ID id() const { |
| 200 return permission()->id(); |
| 201 } |
| 202 |
| 203 // Returns the name of this permission. |
| 204 const char* name() const { |
| 205 return permission()->name(); |
| 206 } |
| 207 |
| 208 // Returns the APIPermission of this permission. |
| 209 const APIPermission* permission() const { |
| 210 return permission_; |
| 211 } |
| 212 |
| 213 // Returns true if the given permission detail is allowed. |
| 214 virtual bool Check(const CheckParam* param) const = 0; |
| 215 |
| 216 // Returns true if |detail| is a subset of this. |
| 217 virtual bool Contains(const APIPermissionDetail* detail) const = 0; |
| 218 |
| 219 // Returns true if |detail| is equal to this. |
| 220 virtual bool Equal(const APIPermissionDetail* detail) const = 0; |
| 221 |
| 222 // Parses the detail from |value|. Returns false if error happens. |
| 223 virtual bool FromValue(const base::Value* value) = 0; |
| 224 |
| 225 // Stores this into a new created |value|. |
| 226 virtual void ToValue(base::Value** value) const = 0; |
| 227 |
| 228 // Clones this. |
| 229 virtual APIPermissionDetail* Clone() const = 0; |
| 230 |
| 231 // Returns a new API permission detail which equals this - |detail|. |
| 232 virtual APIPermissionDetail* Diff( |
| 233 const APIPermissionDetail* detail) const = 0; |
| 234 |
| 235 // Returns a new API permission detail which equals the union of this and |
| 236 // |detail|. |
| 237 virtual APIPermissionDetail* Union( |
| 238 const APIPermissionDetail* detail) const = 0; |
| 239 |
| 240 // Returns a new API permission detail which equals the intersect of this and |
| 241 // |detail|. |
| 242 virtual APIPermissionDetail* Intersect( |
| 243 const APIPermissionDetail* detail) const = 0; |
| 244 |
| 245 // IPC functions |
| 246 // Writes this into the given IPC message |m|. |
| 247 virtual void Write(IPC::Message* m) const = 0; |
| 248 |
| 249 // Reads from the given IPC message |m|. |
| 250 virtual bool Read(const IPC::Message* m, PickleIterator* iter) = 0; |
| 251 |
| 252 // Logs this detail. |
| 253 virtual void Log(std::string* log) const = 0; |
| 254 |
| 255 protected: |
| 256 friend class base::RefCounted<APIPermissionDetail>; |
| 257 virtual ~APIPermissionDetail(); |
| 258 |
| 259 private: |
| 260 const APIPermission* const permission_; |
| 261 }; |
| 166 | 262 |
| 167 } // namespace extensions | 263 } // namespace extensions |
| 168 | 264 |
| 169 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_API_PERMISSION_H_ | 265 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_API_PERMISSION_H_ |
| OLD | NEW |