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_
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"
13 template <class T
> struct FuzzTraits
;
14 template <class T
> struct GenerateTraits
;
16 namespace extensions
{
18 // A pattern that can be used to match socket permission.
19 // <socket-permission-pattern>
22 // <op> ':' ':' <port> |
23 // <op> ':' <host> ':' <port> |
24 // 'udp-multicast-membership'
25 // <op> := 'tcp-connect' |
29 // 'udp-multicast-membership' |
34 // '*.' <anychar except '/' and '*'>+ |
35 // <anychar except '/' and '*'>+
37 // <port number between 0 and 65535>)
38 // The multicast membership permission implies a permission to any address.
39 class SocketPermissionData
{
41 SocketPermissionData();
42 ~SocketPermissionData();
44 // operators <, == are needed by container std::set and algorithms
45 // std::set_includes and std::set_differences.
46 bool operator<(const SocketPermissionData
& rhs
) const;
47 bool operator==(const SocketPermissionData
& rhs
) const;
49 // Check if |param| (which must be a SocketPermissionData::CheckParam)
50 // matches the spec of |this|.
51 bool Check(const APIPermission::CheckParam
* param
) const;
53 // Convert |this| into a base::Value.
54 scoped_ptr
<base::Value
> ToValue() const;
56 // Populate |this| from a base::Value.
57 bool FromValue(const base::Value
* value
);
59 // TODO(bryeung): SocketPermissionData should be encoded as a base::Value
60 // instead of a string. Until that is done, expose these methods for
62 bool ParseForTest(const std::string
& permission
) { return Parse(permission
); }
63 const std::string
& GetAsStringForTest() const { return GetAsString(); }
65 const SocketPermissionEntry
& entry() const { return entry_
; }
68 // Friend so ParamTraits can serialize us.
69 friend struct IPC::ParamTraits
<SocketPermissionData
>;
70 friend struct FuzzTraits
<SocketPermissionData
>;
71 friend struct GenerateTraits
<SocketPermissionData
>;
73 SocketPermissionEntry
& entry();
75 bool Parse(const std::string
& permission
);
76 const std::string
& GetAsString() const;
79 SocketPermissionEntry entry_
;
80 mutable std::string spec_
;
83 } // namespace extensions
85 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_DATA_H_