OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_COMMON_EXTENSIONS_API_SOCKETS_SOCKETS_MANIFEST_PERMISSION_H_ |
| 6 #define CHROME_COMMON_EXTENSIONS_API_SOCKETS_SOCKETS_MANIFEST_PERMISSION_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "chrome/common/extensions/permissions/socket_permission_entry.h" |
| 11 #include "extensions/common/install_warning.h" |
| 12 #include "extensions/common/permissions/manifest_permission.h" |
| 13 |
| 14 namespace content { |
| 15 struct SocketPermissionRequest; |
| 16 } |
| 17 |
| 18 namespace extensions { |
| 19 class Extension; |
| 20 } |
| 21 |
| 22 namespace extensions { |
| 23 |
| 24 class SocketsManifestPermission : public ManifestPermission { |
| 25 public: |
| 26 typedef std::set<SocketPermissionEntry> SocketPermissionEntrySet; |
| 27 enum PermissionKind { |
| 28 kNone = 0, |
| 29 kTcpPermission = 1 << 0, |
| 30 kUdpPermission = 1 << 1, |
| 31 kTcpServerPermission = 1 << 2 |
| 32 }; |
| 33 |
| 34 SocketsManifestPermission(); |
| 35 ~SocketsManifestPermission(); |
| 36 |
| 37 // Tries to construct the info based on |value|, as it would have appeared in |
| 38 // the manifest. Sets |error| and returns an empty scoped_ptr on failure. |
| 39 static scoped_ptr<SocketsManifestPermission> FromValue( |
| 40 const base::Value& value, |
| 41 std::vector<InstallWarning>* install_warnings, |
| 42 string16* error); |
| 43 |
| 44 bool CheckRequest(const Extension* extension, |
| 45 const content::SocketPermissionRequest& request) const; |
| 46 |
| 47 // extensions::ManifestPermission overrides. |
| 48 virtual std::string name() const OVERRIDE; |
| 49 virtual std::string id() const OVERRIDE; |
| 50 virtual bool HasMessages() const OVERRIDE; |
| 51 virtual PermissionMessages GetMessages() const; |
| 52 virtual bool FromValue(const base::Value* value) OVERRIDE; |
| 53 virtual scoped_ptr<base::Value> ToValue() const OVERRIDE; |
| 54 virtual ManifestPermission* Clone() const OVERRIDE; |
| 55 virtual ManifestPermission* Diff(const ManifestPermission* rhs) const |
| 56 OVERRIDE; |
| 57 virtual ManifestPermission* Union(const ManifestPermission* rhs) const |
| 58 OVERRIDE; |
| 59 virtual ManifestPermission* Intersect(const ManifestPermission* rhs) const |
| 60 OVERRIDE; |
| 61 virtual bool Contains(const ManifestPermission* rhs) const OVERRIDE; |
| 62 virtual bool Equal(const ManifestPermission* rhs) const OVERRIDE; |
| 63 virtual void Write(IPC::Message* m) const OVERRIDE; |
| 64 virtual bool Read(const IPC::Message* m, PickleIterator* iter) OVERRIDE; |
| 65 virtual void Log(std::string* log) const OVERRIDE; |
| 66 |
| 67 bool has_udp() const { return (kinds_ & kUdpPermission) != 0; } |
| 68 bool has_tcp() const { return (kinds_ & kTcpPermission) != 0; } |
| 69 bool has_tcp_server() const { return (kinds_ & kTcpServerPermission) != 0; } |
| 70 const SocketPermissionEntrySet& entries() const { return permissions_; } |
| 71 |
| 72 private: |
| 73 static bool ParseHostPattern( |
| 74 SocketsManifestPermission* manifest_data, |
| 75 content::SocketPermissionRequest::OperationType operation_type, |
| 76 const scoped_ptr<std::string>& value, |
| 77 string16* error); |
| 78 |
| 79 scoped_ptr<std::string> CreateHostPattern( |
| 80 content::SocketPermissionRequest::OperationType operation_type) const; |
| 81 |
| 82 void AddPermission(const SocketPermissionEntry& entry); |
| 83 |
| 84 bool AddAnyHostMessage(PermissionMessages& messages) const; |
| 85 void AddSubdomainHostMessage(PermissionMessages& messages) const; |
| 86 void AddSpecificHostMessage(PermissionMessages& messages) const; |
| 87 void AddNetworkListMessage(PermissionMessages& messages) const; |
| 88 |
| 89 SocketPermissionEntrySet permissions_; |
| 90 int kinds_; // PermissionKind bits |
| 91 }; |
| 92 |
| 93 } // namespace extensions |
| 94 |
| 95 #endif // CHROME_COMMON_EXTENSIONS_API_SOCKETS_SOCKETS_MANIFEST_PERMISSION_H_ |
OLD | NEW |