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

Unified Diff: chrome/common/extensions/permissions/socket_permission_data.h

Issue 10692160: Support socket endpoint permissions for AppsV2 Socket API. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase and fix a unit test Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/permissions/socket_permission_data.h
diff --git a/chrome/common/extensions/permissions/socket_permission_data.h b/chrome/common/extensions/permissions/socket_permission_data.h
new file mode 100644
index 0000000000000000000000000000000000000000..99d4b06fb28931787630e1a7856ebddd4dcd6894
--- /dev/null
+++ b/chrome/common/extensions/permissions/socket_permission_data.h
@@ -0,0 +1,54 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+#ifndef CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_DATA_H_
+#define CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_DATA_H_
+
+#include <string>
+
+namespace extensions {
+
+// A pattern that can be used to match socket permission.
+// <socket-permission-pattern>
+// := <op> | <op> ':' <host> | <op> ':' ':' <port> |
+// <op> ':' <host> ':' <port>
+// <op> := 'tcp-connect' | 'tcp-listen' | 'udp-bind' | 'udp-send-to'
+// <host> := '*' | '*.' <anychar except '/' and '*'>+
+// <port> := '*' | <port number between 0 and 65535>)
+class SocketPermissionData {
+ public:
+ enum OperationType {
+ NONE = 0,
+ TCP_CONNECT,
+ TCP_LISTEN,
+ UDP_BIND,
+ UDP_SEND_TO,
+ };
+
+ SocketPermissionData();
+ ~SocketPermissionData();
+
+ // operators <, == are needed by container std::set and algorithms
+ // std::set_includes and std::set_differences.
+ bool operator<(const SocketPermissionData& rhs) const;
+ bool operator==(const SocketPermissionData& rhs) const;
+
+ bool Match(OperationType type, const std::string& host, int port) const;
+
+ bool Parse(const std::string& permission);
+
+ const std::string& GetAsString() const;
+
+ private:
+ void Reset();
+
+ OperationType type_;
+ std::string host_;
+ bool match_subdomains_;
+ int port_;
+ mutable std::string spec_;
+};
+
+} // namespace extensions
+
+#endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_DATA_H_

Powered by Google App Engine
This is Rietveld 408576698