Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / common / extensions / permissions / socket_permission_entry.h
blob63a5c3bc8fd70a1bc0ede76be93467840e506df6
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 #ifndef CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_ENTRY_H_
5 #define CHROME_COMMON_EXTENSIONS_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 template <class T> struct FuzzTraits;
14 template <class T> struct GenerateTraits;
16 namespace extensions {
18 // Internal representation of a socket permission for a specific operation, such
19 // as UDP "bind", host 127.0.0.1, port *.
20 class SocketPermissionEntry {
21 public:
22 enum HostType {
23 ANY_HOST,
24 HOSTS_IN_DOMAINS,
25 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 FuzzTraits<SocketPermissionEntry>;
73 friend struct 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 // CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_ENTRY_H_