Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(558)

Side by Side Diff: chrome/common/extensions/permissions/socket_permission_entry.h

Issue 201203006: Move basic API permissions code out of //chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move moar things Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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_
6
7 #include <string>
8 #include <vector>
9
10 #include "content/public/common/socket_permission_request.h"
11 #include "ipc/ipc_param_traits.h"
12
13 namespace ipc_fuzzer {
14 template <class T> struct FuzzTraits;
15 template <class T> struct GenerateTraits;
16 } // namespace ipc_fuzzer
17
18 namespace extensions {
19
20 // Internal representation of a socket permission for a specific operation, such
21 // as UDP "bind", host 127.0.0.1, port *.
22 class SocketPermissionEntry {
23 public:
24 enum HostType {
25 ANY_HOST,
26 HOSTS_IN_DOMAINS,
27 SPECIFIC_HOSTS,
28 };
29
30 SocketPermissionEntry();
31 ~SocketPermissionEntry();
32
33 // operators <, == are needed by container std::set and algorithms
34 // std::set_includes and std::set_differences.
35 bool operator<(const SocketPermissionEntry& rhs) const;
36 bool operator==(const SocketPermissionEntry& rhs) const;
37
38 bool Check(const content::SocketPermissionRequest& request) const;
39
40 // Parse a host:port pattern for a given operation type.
41 // <pattern> := '' |
42 // <host> |
43 // ':' <port> |
44 // <host> ':' <port> |
45 //
46 // <host> := '*' |
47 // '*.' <anychar except '/' and '*'>+ |
48 // <anychar except '/' and '*'>+
49 //
50 // <port> := '*' |
51 // <port number between 0 and 65535>)
52 static bool ParseHostPattern(
53 content::SocketPermissionRequest::OperationType type,
54 const std::string& pattern,
55 SocketPermissionEntry* entry);
56
57 static bool ParseHostPattern(
58 content::SocketPermissionRequest::OperationType type,
59 const std::vector<std::string>& pattern_tokens,
60 SocketPermissionEntry* entry);
61
62 // Returns true if the permission type can be bound to a host or port.
63 bool IsAddressBoundType() const;
64
65 std::string GetHostPatternAsString() const;
66 HostType GetHostType() const;
67
68 const content::SocketPermissionRequest& pattern() const { return pattern_; }
69 bool match_subdomains() const { return match_subdomains_; }
70
71 private:
72 // Friend so ParamTraits can serialize us.
73 friend struct IPC::ParamTraits<SocketPermissionEntry>;
74 friend struct ipc_fuzzer::FuzzTraits<SocketPermissionEntry>;
75 friend struct ipc_fuzzer::GenerateTraits<SocketPermissionEntry>;
76
77 // The permission type, host and port.
78 content::SocketPermissionRequest pattern_;
79
80 // True if there was a wildcard in the host name.
81 bool match_subdomains_;
82 };
83
84 } // namespace extensions
85
86 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_ENTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698