1 // Copyright 2014 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 EXTENSIONS_COMMON_PERMISSIONS_SOCKET_PERMISSION_DATA_H_
5 #define EXTENSIONS_COMMON_PERMISSIONS_SOCKET_PERMISSION_DATA_H_
9 #include "extensions/common/permissions/api_permission.h"
10 #include "extensions/common/permissions/socket_permission_entry.h"
11 #include "ipc/ipc_param_traits.h"
13 namespace ipc_fuzzer
{
17 struct GenerateTraits
;
18 } // namespace ipc_fuzzer
20 namespace extensions
{
22 // A pattern that can be used to match socket permission.
23 // <socket-permission-pattern>
26 // <op> ':' ':' <port> |
27 // <op> ':' <host> ':' <port> |
28 // 'udp-multicast-membership'
29 // <op> := 'tcp-connect' |
33 // 'udp-multicast-membership' |
38 // '*.' <anychar except '/' and '*'>+ |
39 // <anychar except '/' and '*'>+
41 // <port number between 0 and 65535>)
42 // The multicast membership permission implies a permission to any address.
43 class SocketPermissionData
{
45 SocketPermissionData();
46 ~SocketPermissionData();
48 // operators <, == are needed by container std::set and algorithms
49 // std::set_includes and std::set_differences.
50 bool operator<(const SocketPermissionData
& rhs
) const;
51 bool operator==(const SocketPermissionData
& rhs
) const;
53 // Check if |param| (which must be a SocketPermissionData::CheckParam)
54 // matches the spec of |this|.
55 bool Check(const APIPermission::CheckParam
* param
) const;
57 // Convert |this| into a base::Value.
58 scoped_ptr
<base::Value
> ToValue() const;
60 // Populate |this| from a base::Value.
61 bool FromValue(const base::Value
* value
);
63 // TODO(bryeung): SocketPermissionData should be encoded as a base::Value
64 // instead of a string. Until that is done, expose these methods for
66 bool ParseForTest(const std::string
& permission
) { return Parse(permission
); }
67 const std::string
& GetAsStringForTest() const { return GetAsString(); }
69 const SocketPermissionEntry
& entry() const { return entry_
; }
72 // Friend so ParamTraits can serialize us.
73 friend struct IPC::ParamTraits
<SocketPermissionData
>;
74 friend struct ipc_fuzzer::FuzzTraits
<SocketPermissionData
>;
75 friend struct ipc_fuzzer::GenerateTraits
<SocketPermissionData
>;
77 SocketPermissionEntry
& entry();
79 bool Parse(const std::string
& permission
);
80 const std::string
& GetAsString() const;
83 SocketPermissionEntry entry_
;
84 mutable std::string spec_
;
87 } // namespace extensions
89 #endif // EXTENSIONS_COMMON_PERMISSIONS_SOCKET_PERMISSION_DATA_H_