Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / extensions / common / permissions / socket_permission_entry.h
blobee4e21229401242b82017da105020feceaf34b96
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_ENTRY_H_
5 #define EXTENSIONS_COMMON_PERMISSIONS_SOCKET_PERMISSION_ENTRY_H_
7 #include <string>
8 #include <vector>
10 #include "content/public/common/socket_permission_request.h"
11 #include "ipc/ipc_param_traits.h"
13 namespace ipc_fuzzer {
14 template <class T>
15 struct FuzzTraits;
16 template <class T>
17 struct GenerateTraits;
18 } // namespace ipc_fuzzer
20 namespace extensions {
22 // Internal representation of a socket permission for a specific operation, such
23 // as UDP "bind", host 127.0.0.1, port *.
24 class SocketPermissionEntry {
25 public:
26 enum HostType { ANY_HOST, HOSTS_IN_DOMAINS, SPECIFIC_HOSTS, };
28 SocketPermissionEntry();
29 ~SocketPermissionEntry();
31 // operators <, == are needed by container std::set and algorithms
32 // std::set_includes and std::set_differences.
33 bool operator<(const SocketPermissionEntry& rhs) const;
34 bool operator==(const SocketPermissionEntry& rhs) const;
36 bool Check(const content::SocketPermissionRequest& request) const;
38 // Parse a host:port pattern for a given operation type.
39 // <pattern> := '' |
40 // <host> |
41 // ':' <port> |
42 // <host> ':' <port> |
44 // <host> := '*' |
45 // '*.' <anychar except '/' and '*'>+ |
46 // <anychar except '/' and '*'>+
48 // <port> := '*' |
49 // <port number between 0 and 65535>)
50 static bool ParseHostPattern(
51 content::SocketPermissionRequest::OperationType type,
52 const std::string& pattern,
53 SocketPermissionEntry* entry);
55 static bool ParseHostPattern(
56 content::SocketPermissionRequest::OperationType type,
57 const std::vector<std::string>& pattern_tokens,
58 SocketPermissionEntry* entry);
60 // Returns true if the permission type can be bound to a host or port.
61 bool IsAddressBoundType() const;
63 std::string GetHostPatternAsString() const;
64 HostType GetHostType() const;
66 const content::SocketPermissionRequest& pattern() const { return pattern_; }
67 bool match_subdomains() const { return match_subdomains_; }
69 private:
70 // Friend so ParamTraits can serialize us.
71 friend struct IPC::ParamTraits<SocketPermissionEntry>;
72 friend struct ipc_fuzzer::FuzzTraits<SocketPermissionEntry>;
73 friend struct ipc_fuzzer::GenerateTraits<SocketPermissionEntry>;
75 // The permission type, host and port.
76 content::SocketPermissionRequest pattern_;
78 // True if there was a wildcard in the host name.
79 bool match_subdomains_;
82 } // namespace extensions
84 #endif // EXTENSIONS_COMMON_PERMISSIONS_SOCKET_PERMISSION_ENTRY_H_