Chromium Code Reviews| 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_API_PERMISSION_SET_H_ | 5 #ifndef EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_ |
| 6 #define EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_ | 6 #define EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_ |
| 7 | 7 |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 APIPermissionSet* api_permissions, | 161 APIPermissionSet* api_permissions, |
| 162 string16* error, | 162 string16* error, |
| 163 std::vector<std::string>* unhandled_permissions); | 163 std::vector<std::string>* unhandled_permissions); |
| 164 | 164 |
| 165 void AddImpliedPermissions(); | 165 void AddImpliedPermissions(); |
| 166 | 166 |
| 167 private: | 167 private: |
| 168 APIPermissionMap map_; | 168 APIPermissionMap map_; |
| 169 }; | 169 }; |
| 170 | 170 |
| 171 | |
| 172 // Represent the custom behavior of a top-level manifest entry contributing to | |
| 173 // permission messages and storage. | |
| 174 class ManifestPermission { | |
|
Yoyo Zhou
2013/11/09 01:15:30
This has grown large enough to need its own file,
rpaquay
2013/11/11 18:37:35
Agreed, I have been working on this in a follow up
Yoyo Zhou
2013/11/12 02:39:29
I think this is important enough that it should be
rpaquay
2013/11/12 21:40:31
Done.
| |
| 175 public: | |
| 176 // The manifest key this permission applies to. | |
| 177 virtual std::string name() const = 0; | |
| 178 | |
| 179 // Same as name(), needed for compatibility with APIPermission. | |
| 180 virtual std::string id() const = 0; | |
| 181 | |
| 182 // Returns true if this permission has any PermissionMessages. | |
| 183 virtual bool HasMessages() const = 0; | |
| 184 | |
| 185 // Returns the localized permission messages of this permission. | |
| 186 virtual PermissionMessages GetMessages() const = 0; | |
| 187 | |
| 188 // Parses the ManifestPermission from |value|. Returns false if error happens. | |
| 189 virtual bool FromValue(const base::Value* value) = 0; | |
| 190 | |
| 191 // Stores this into a new created |value|. | |
| 192 virtual scoped_ptr<base::Value> ToValue() const = 0; | |
| 193 | |
| 194 // Clones this. | |
| 195 virtual ManifestPermission* Clone() const = 0; | |
| 196 | |
| 197 // Returns a new API permission which equals this - |rhs|. | |
| 198 virtual ManifestPermission* Diff(const ManifestPermission* rhs) | |
| 199 const = 0; | |
| 200 | |
| 201 // Returns a new API permission which equals the union of this and |rhs|. | |
| 202 virtual ManifestPermission* Union(const ManifestPermission* rhs) | |
| 203 const = 0; | |
| 204 | |
| 205 // Returns a new API permission which equals the intersect of this and |rhs|. | |
| 206 virtual ManifestPermission* Intersect(const ManifestPermission* rhs) | |
| 207 const = 0; | |
| 208 | |
| 209 // Returns true if |rhs| is a subset of this. | |
| 210 virtual bool Contains(const ManifestPermission* rhs) const = 0; | |
| 211 | |
| 212 // Returns true if |rhs| is equal to this. | |
| 213 virtual bool Equal(const ManifestPermission* rhs) const = 0; | |
| 214 | |
| 215 // IPC functions | |
| 216 // Writes this into the given IPC message |m|. | |
| 217 virtual void Write(IPC::Message* m) const = 0; | |
| 218 | |
| 219 // Reads from the given IPC message |m|. | |
| 220 virtual bool Read(const IPC::Message* m, PickleIterator* iter) = 0; | |
| 221 | |
| 222 // Logs this permission. | |
| 223 virtual void Log(std::string* log) const = 0; | |
| 224 }; | |
| 225 | |
| 226 typedef std::map<std::string, | |
| 227 linked_ptr<ManifestPermission> > ManifestPermissionMap; | |
| 228 | |
| 229 class ManifestPermissionSet { | |
|
Yoyo Zhou
2013/11/09 01:15:30
It looks like there is really a lot of duplicated
rpaquay
2013/11/11 18:37:35
Agreed. I have been working on this (along with un
rpaquay
2013/11/12 21:40:31
The latest patchset (#5) addresses this to a large
| |
| 230 public: | |
| 231 class const_iterator : | |
| 232 public std::iterator<std::input_iterator_tag, const APIPermission*> { | |
| 233 public: | |
| 234 const_iterator(const ManifestPermissionMap::const_iterator& it); | |
| 235 const_iterator(const const_iterator& ids_it); | |
| 236 | |
| 237 const_iterator& operator++() { | |
| 238 ++it_; | |
| 239 return *this; | |
| 240 } | |
| 241 | |
| 242 const_iterator operator++(int) { | |
| 243 const_iterator tmp(it_++); | |
| 244 return tmp; | |
| 245 } | |
| 246 | |
| 247 bool operator==(const const_iterator& rhs) const { | |
| 248 return it_ == rhs.it_; | |
| 249 } | |
| 250 | |
| 251 bool operator!=(const const_iterator& rhs) const { | |
| 252 return it_ != rhs.it_; | |
| 253 } | |
| 254 | |
| 255 const ManifestPermission* operator*() const { | |
| 256 return it_->second.get(); | |
| 257 } | |
| 258 | |
| 259 const ManifestPermission* operator->() const { | |
| 260 return it_->second.get(); | |
| 261 } | |
| 262 | |
| 263 private: | |
| 264 ManifestPermissionMap::const_iterator it_; | |
| 265 }; | |
| 266 | |
| 267 ManifestPermissionSet(); | |
| 268 | |
| 269 ManifestPermissionSet(const ManifestPermissionSet& set); | |
| 270 | |
| 271 ~ManifestPermissionSet(); | |
| 272 | |
| 273 const_iterator begin() const { | |
| 274 return const_iterator(map().begin()); | |
| 275 } | |
| 276 | |
| 277 const_iterator end() const { | |
| 278 return map().end(); | |
| 279 } | |
| 280 | |
| 281 const_iterator find(std::string id) const { | |
| 282 return map().find(id); | |
| 283 } | |
| 284 | |
| 285 const ManifestPermissionMap& map() const { | |
| 286 return map_; | |
| 287 } | |
| 288 | |
| 289 ManifestPermissionMap& map() { | |
| 290 return map_; | |
| 291 } | |
| 292 | |
| 293 void clear() { | |
| 294 map_.clear(); | |
| 295 } | |
| 296 | |
| 297 size_t count(std::string id) const { | |
| 298 return map().count(id); | |
| 299 } | |
| 300 | |
| 301 bool empty() const { | |
| 302 return map().empty(); | |
| 303 } | |
| 304 | |
| 305 size_t erase(std::string id) { | |
| 306 return map().erase(id); | |
| 307 } | |
| 308 | |
| 309 size_t size() const { | |
| 310 return map().size(); | |
| 311 } | |
| 312 | |
| 313 ManifestPermissionSet& operator=(const ManifestPermissionSet& rhs); | |
| 314 | |
| 315 bool operator==(const ManifestPermissionSet& rhs) const; | |
| 316 | |
| 317 bool operator!=(const ManifestPermissionSet& rhs) const { | |
| 318 return !operator==(rhs); | |
| 319 } | |
| 320 | |
| 321 // Take ownership and insert |permission| into the set. | |
| 322 void insert(ManifestPermission* permission); | |
| 323 | |
| 324 bool Contains(const ManifestPermissionSet& rhs) const; | |
| 325 | |
| 326 static void Difference( | |
| 327 const ManifestPermissionSet& set1, | |
| 328 const ManifestPermissionSet& set2, | |
| 329 ManifestPermissionSet* set3); | |
| 330 | |
| 331 static void Intersection( | |
| 332 const ManifestPermissionSet& set1, | |
| 333 const ManifestPermissionSet& set2, | |
| 334 ManifestPermissionSet* set3); | |
| 335 | |
| 336 static void Union( | |
| 337 const ManifestPermissionSet& set1, | |
| 338 const ManifestPermissionSet& set2, | |
| 339 ManifestPermissionSet* set3); | |
| 340 | |
| 341 private: | |
| 342 ManifestPermissionMap map_; | |
| 343 }; | |
| 344 | |
| 171 } // namespace extensions | 345 } // namespace extensions |
| 172 | 346 |
| 173 #endif // EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_ | 347 #endif // EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_ |
| OLD | NEW |