OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 #ifndef CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_DATA_H_ | 4 #ifndef CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_DATA_H_ |
5 #define CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_DATA_H_ | 5 #define CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_DATA_H_ |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
| 9 #include "content/public/common/socket_permission_request.h" |
| 10 |
9 namespace extensions { | 11 namespace extensions { |
10 | 12 |
11 // A pattern that can be used to match socket permission. | 13 // A pattern that can be used to match socket permission. |
12 // <socket-permission-pattern> | 14 // <socket-permission-pattern> |
13 // := <op> | | 15 // := <op> | |
14 // <op> ':' <host> | | 16 // <op> ':' <host> | |
15 // <op> ':' ':' <port> | | 17 // <op> ':' ':' <port> | |
16 // <op> ':' <host> ':' <port> | 18 // <op> ':' <host> ':' <port> |
17 // <op> := 'tcp-connect' | | 19 // <op> := 'tcp-connect' | |
18 // 'tcp-listen' | | 20 // 'tcp-listen' | |
19 // 'udp-bind' | | 21 // 'udp-bind' | |
20 // 'udp-send-to' | 22 // 'udp-send-to' |
21 // <host> := '*' | | 23 // <host> := '*' | |
22 // '*.' <anychar except '/' and '*'>+ | | 24 // '*.' <anychar except '/' and '*'>+ | |
23 // <anychar except '/' and '*'>+ | 25 // <anychar except '/' and '*'>+ |
24 // <port> := '*' | | 26 // <port> := '*' | |
25 // <port number between 0 and 65535>) | 27 // <port number between 0 and 65535>) |
26 class SocketPermissionData { | 28 class SocketPermissionData { |
27 public: | 29 public: |
28 enum OperationType { | |
29 NONE = 0, | |
30 TCP_CONNECT, | |
31 TCP_LISTEN, | |
32 UDP_BIND, | |
33 UDP_SEND_TO, | |
34 }; | |
35 | |
36 enum HostType { | 30 enum HostType { |
37 ANY_HOST, | 31 ANY_HOST, |
38 HOSTS_IN_DOMAINS, | 32 HOSTS_IN_DOMAINS, |
39 SPECIFIC_HOSTS, | 33 SPECIFIC_HOSTS, |
40 }; | 34 }; |
41 | 35 |
42 SocketPermissionData(); | 36 SocketPermissionData(); |
43 ~SocketPermissionData(); | 37 ~SocketPermissionData(); |
44 | 38 |
45 // operators <, == are needed by container std::set and algorithms | 39 // operators <, == are needed by container std::set and algorithms |
46 // std::set_includes and std::set_differences. | 40 // std::set_includes and std::set_differences. |
47 bool operator<(const SocketPermissionData& rhs) const; | 41 bool operator<(const SocketPermissionData& rhs) const; |
48 bool operator==(const SocketPermissionData& rhs) const; | 42 bool operator==(const SocketPermissionData& rhs) const; |
49 | 43 |
50 bool Match(OperationType type, const std::string& host, int port) const; | 44 bool Match(content::SocketPermissionRequest request) const; |
51 | 45 |
52 bool Parse(const std::string& permission); | 46 bool Parse(const std::string& permission); |
53 | 47 |
54 HostType GetHostType() const; | 48 HostType GetHostType() const; |
55 const std::string GetHost() const; | 49 const std::string GetHost() const; |
56 | 50 |
57 const std::string& GetAsString() const; | 51 const std::string& GetAsString() const; |
58 | 52 |
59 private: | 53 private: |
60 void Reset(); | 54 void Reset(); |
61 | 55 |
62 OperationType type_; | 56 content::SocketPermissionRequest pattern_; |
63 std::string host_; | |
64 bool match_subdomains_; | 57 bool match_subdomains_; |
65 int port_; | |
66 mutable std::string spec_; | 58 mutable std::string spec_; |
67 }; | 59 }; |
68 | 60 |
69 } // namespace extensions | 61 } // namespace extensions |
70 | 62 |
71 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_DATA_H_ | 63 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_DATA_H_ |
OLD | NEW |