OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 #ifndef CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_DATA_H_ | |
5 #define CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_DATA_H_ | |
6 | |
7 #include <string> | |
8 | |
9 #include "chrome/common/extensions/permissions/socket_permission_entry.h" | |
10 #include "extensions/common/permissions/api_permission.h" | |
11 #include "ipc/ipc_param_traits.h" | |
12 | |
13 namespace ipc_fuzzer { | |
14 template <class T> struct FuzzTraits; | |
15 template <class T> struct GenerateTraits; | |
16 } // namespace ipc_fuzzer | |
17 | |
18 namespace extensions { | |
19 | |
20 // A pattern that can be used to match socket permission. | |
21 // <socket-permission-pattern> | |
22 // := <op> | | |
23 // <op> ':' <host> | | |
24 // <op> ':' ':' <port> | | |
25 // <op> ':' <host> ':' <port> | | |
26 // 'udp-multicast-membership' | |
27 // <op> := 'tcp-connect' | | |
28 // 'tcp-listen' | | |
29 // 'udp-bind' | | |
30 // 'udp-send-to' | | |
31 // 'udp-multicast-membership' | | |
32 // 'resolve-host' | | |
33 // 'resolve-proxy' | | |
34 // 'network-state' | |
35 // <host> := '*' | | |
36 // '*.' <anychar except '/' and '*'>+ | | |
37 // <anychar except '/' and '*'>+ | |
38 // <port> := '*' | | |
39 // <port number between 0 and 65535>) | |
40 // The multicast membership permission implies a permission to any address. | |
41 class SocketPermissionData { | |
42 public: | |
43 SocketPermissionData(); | |
44 ~SocketPermissionData(); | |
45 | |
46 // operators <, == are needed by container std::set and algorithms | |
47 // std::set_includes and std::set_differences. | |
48 bool operator<(const SocketPermissionData& rhs) const; | |
49 bool operator==(const SocketPermissionData& rhs) const; | |
50 | |
51 // Check if |param| (which must be a SocketPermissionData::CheckParam) | |
52 // matches the spec of |this|. | |
53 bool Check(const APIPermission::CheckParam* param) const; | |
54 | |
55 // Convert |this| into a base::Value. | |
56 scoped_ptr<base::Value> ToValue() const; | |
57 | |
58 // Populate |this| from a base::Value. | |
59 bool FromValue(const base::Value* value); | |
60 | |
61 // TODO(bryeung): SocketPermissionData should be encoded as a base::Value | |
62 // instead of a string. Until that is done, expose these methods for | |
63 // testing. | |
64 bool ParseForTest(const std::string& permission) { return Parse(permission); } | |
65 const std::string& GetAsStringForTest() const { return GetAsString(); } | |
66 | |
67 const SocketPermissionEntry& entry() const { return entry_; } | |
68 | |
69 private: | |
70 // Friend so ParamTraits can serialize us. | |
71 friend struct IPC::ParamTraits<SocketPermissionData>; | |
72 friend struct ipc_fuzzer::FuzzTraits<SocketPermissionData>; | |
73 friend struct ipc_fuzzer::GenerateTraits<SocketPermissionData>; | |
74 | |
75 SocketPermissionEntry& entry(); | |
76 | |
77 bool Parse(const std::string& permission); | |
78 const std::string& GetAsString() const; | |
79 void Reset(); | |
80 | |
81 SocketPermissionEntry entry_; | |
82 mutable std::string spec_; | |
83 }; | |
84 | |
85 } // namespace extensions | |
86 | |
87 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_DATA_H_ | |
OLD | NEW |