Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 | 4 |
| 5 #ifndef CHROME_COMMON_EXTENSIONS_API_SOCKETS_SOCKETS_HANDLER_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_API_SOCKETS_SOCKETS_HANDLER_H_ |
| 6 #define CHROME_COMMON_EXTENSIONS_API_SOCKETS_SOCKETS_HANDLER_H_ | 6 #define CHROME_COMMON_EXTENSIONS_API_SOCKETS_SOCKETS_HANDLER_H_ |
| 7 | 7 |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "chrome/common/extensions/extension.h" | 9 #include "chrome/common/extensions/extension.h" |
| 10 #include "chrome/common/extensions/permissions/socket_permission_data.h" | 10 #include "chrome/common/extensions/permissions/socket_permission_data.h" |
| 11 #include "extensions/common/manifest_handler.h" | 11 #include "extensions/common/manifest_handler.h" |
| 12 | 12 |
| 13 namespace extensions { | 13 namespace extensions { |
| 14 | 14 |
| 15 // Parses the "sockets" manifest key. | 15 // Parses the "sockets" manifest key. |
| 16 class SocketsHandler : public ManifestHandler { | 16 class SocketsHandler : public ManifestHandler { |
| 17 public: | 17 public: |
| 18 SocketsHandler(); | 18 SocketsHandler(); |
| 19 virtual ~SocketsHandler(); | 19 virtual ~SocketsHandler(); |
| 20 | 20 |
| 21 virtual bool Parse(Extension* extension, string16* error) OVERRIDE; | 21 virtual bool Parse(Extension* extension, string16* error) OVERRIDE; |
| 22 virtual ManifestPermission* CreatePermission() OVERRIDE; | |
| 23 virtual ManifestPermission* CreateInitialRequiredPermission( | |
| 24 const Extension* extension) OVERRIDE; | |
| 22 | 25 |
| 23 private: | 26 private: |
| 24 virtual const std::vector<std::string> Keys() const OVERRIDE; | 27 virtual const std::vector<std::string> Keys() const OVERRIDE; |
| 25 | 28 |
| 26 DISALLOW_COPY_AND_ASSIGN(SocketsHandler); | 29 DISALLOW_COPY_AND_ASSIGN(SocketsHandler); |
| 27 }; | 30 }; |
| 28 | 31 |
| 29 // The parsed form of the "sockets" manifest entry. | 32 // The parsed form of the "sockets" manifest entry. |
| 30 class SocketsManifestData : public Extension::ManifestData { | 33 class SocketsManifestData : public Extension::ManifestData { |
| 31 public: | 34 public: |
| 35 typedef std::set<SocketPermissionEntry> SocketPermissionEntrySet; | |
| 36 enum PermissionKind { | |
| 37 kNone = 0x0000, | |
|
Yoyo Zhou
2013/11/12 02:39:29
nit: we usually write (1<<0), (1<<1), etc. for the
rpaquay
2013/11/12 21:40:31
Done.
| |
| 38 kTcpPermission = 0x0001, | |
| 39 kUdpPermission = 0x0002, | |
| 40 kTcpServerPermission = 0x0004 | |
| 41 }; | |
| 42 | |
| 32 SocketsManifestData(); | 43 SocketsManifestData(); |
| 33 virtual ~SocketsManifestData(); | 44 virtual ~SocketsManifestData(); |
| 34 | 45 |
| 35 // Gets the ExternallyConnectableInfo for |extension|, or NULL if none was | 46 // Gets the SocketsManifestData for |extension|, or NULL if none was |
| 36 // specified. | 47 // specified. |
| 37 static SocketsManifestData* Get(const Extension* extension); | 48 static SocketsManifestData* Get(const Extension* extension); |
| 38 | 49 |
| 39 static bool CheckRequest(const Extension* extension, | 50 static bool CheckRequest(const Extension* extension, |
| 40 const content::SocketPermissionRequest& request); | 51 const content::SocketPermissionRequest& request); |
| 41 | 52 |
| 42 // Tries to construct the info based on |value|, as it would have appeared in | 53 // Tries to construct the info based on |value|, as it would have appeared in |
| 43 // the manifest. Sets |error| and returns an empty scoped_ptr on failure. | 54 // the manifest. Sets |error| and returns an empty scoped_ptr on failure. |
| 44 static scoped_ptr<SocketsManifestData> FromValue( | 55 static scoped_ptr<SocketsManifestData> FromValue( |
| 45 const base::Value& value, | 56 const base::Value& value, |
| 46 std::vector<InstallWarning>* install_warnings, | 57 std::vector<InstallWarning>* install_warnings, |
| 47 string16* error); | 58 string16* error); |
| 48 | 59 |
| 60 bool HasMessages() const; | |
| 61 PermissionMessages GetPermissionMessages() const; | |
| 62 | |
| 63 SocketsManifestData* Diff(const SocketsManifestData* rhs) const; | |
| 64 SocketsManifestData* Union(const SocketsManifestData* rhs) const; | |
| 65 SocketsManifestData* Intersect(const SocketsManifestData* rhs) const; | |
| 66 bool Contains(const SocketsManifestData* rhs) const; | |
| 67 bool Equal(const SocketsManifestData* rhs) const; | |
| 68 SocketsManifestData* Clone() const; | |
| 69 | |
| 70 // IPC functions | |
| 71 void Write(IPC::Message* m) const; | |
| 72 bool Read(const IPC::Message* m, PickleIterator* iter); | |
| 73 void Log(std::string* log) const; | |
| 74 | |
| 75 const SocketPermissionEntrySet& entries() const { return permissions_; } | |
| 76 | |
| 77 bool is_udp() const { return (kinds_ & kUdpPermission) != 0; } | |
|
Yoyo Zhou
2013/11/12 02:39:29
Is "is" or "has" better for this if it's a bitmask
rpaquay
2013/11/12 21:40:31
Done.
| |
| 78 bool is_tcp() const { return (kinds_ & kTcpPermission) != 0; } | |
| 79 bool is_tcp_server() const { return (kinds_ & kTcpServerPermission) != 0; } | |
| 80 | |
| 49 private: | 81 private: |
| 50 typedef std::set<SocketPermissionEntry> PermissionSet; | |
| 51 | |
| 52 static bool ParseHostPattern( | 82 static bool ParseHostPattern( |
| 53 SocketsManifestData* manifest_data, | 83 SocketsManifestData* manifest_data, |
| 54 content::SocketPermissionRequest::OperationType operation_type, | 84 content::SocketPermissionRequest::OperationType operation_type, |
| 55 const scoped_ptr<std::string>& value, | 85 const scoped_ptr<std::string>& value, |
| 56 string16* error); | 86 string16* error); |
| 57 | 87 |
| 58 void AddPermission(const SocketPermissionEntry& entry); | 88 void AddPermission(const SocketPermissionEntry& entry); |
| 59 | 89 |
| 60 bool CheckRequestImpl(const Extension* extension, | 90 bool CheckRequestImpl(const Extension* extension, |
| 61 const content::SocketPermissionRequest& request); | 91 const content::SocketPermissionRequest& request); |
| 62 | 92 |
| 63 PermissionSet permissions_; | 93 bool AddAnyHostMessage(PermissionMessages& messages) const; |
| 94 void AddSubdomainHostMessage(PermissionMessages& messages) const; | |
| 95 void AddSpecificHostMessage(PermissionMessages& messages) const; | |
| 96 void AddNetworkListMessage(PermissionMessages& messages) const; | |
| 97 | |
| 98 SocketPermissionEntrySet permissions_; | |
| 99 int kinds_; // PermissionKind bits | |
| 64 }; | 100 }; |
| 65 | 101 |
| 66 } // namespace extensions | 102 } // namespace extensions |
| 67 | 103 |
| 68 #endif // CHROME_COMMON_EXTENSIONS_API_SOCKETS_SOCKETS_HANDLER_H_ | 104 #endif // CHROME_COMMON_EXTENSIONS_API_SOCKETS_SOCKETS_HANDLER_H_ |
| OLD | NEW |