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 = 0, | |
| 38 kTcpPermission = 1 << 0, | |
| 39 kUdpPermission = 1 << 1, | |
| 40 kTcpServerPermission = 1 << 2 | |
| 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 // Stores this into a new created |value|. | |
|
Yoyo Zhou
2013/11/13 02:57:07
nit: |value| would be used to name an argument. Sa
rpaquay
2013/11/13 21:28:55
Done.
| |
| 61 scoped_ptr<base::Value> ToValue() const; | |
| 62 | |
| 63 bool HasMessages() const; | |
| 64 PermissionMessages GetPermissionMessages() const; | |
| 65 | |
| 66 SocketsManifestData* Diff(const SocketsManifestData* rhs) const; | |
| 67 SocketsManifestData* Union(const SocketsManifestData* rhs) const; | |
| 68 SocketsManifestData* Intersect(const SocketsManifestData* rhs) const; | |
| 69 bool Contains(const SocketsManifestData* rhs) const; | |
| 70 bool Equal(const SocketsManifestData* rhs) const; | |
| 71 SocketsManifestData* Clone() const; | |
| 72 | |
| 73 // IPC functions | |
| 74 void Write(IPC::Message* m) const; | |
| 75 bool Read(const IPC::Message* m, PickleIterator* iter); | |
| 76 void Log(std::string* log) const; | |
| 77 | |
| 78 const SocketPermissionEntrySet& entries() const { return permissions_; } | |
| 79 | |
| 80 bool has_udp() const { return (kinds_ & kUdpPermission) != 0; } | |
| 81 bool has_tcp() const { return (kinds_ & kTcpPermission) != 0; } | |
| 82 bool has_tcp_server() const { return (kinds_ & kTcpServerPermission) != 0; } | |
| 83 | |
| 49 private: | 84 private: |
| 50 typedef std::set<SocketPermissionEntry> PermissionSet; | |
| 51 | |
| 52 static bool ParseHostPattern( | 85 static bool ParseHostPattern( |
| 53 SocketsManifestData* manifest_data, | 86 SocketsManifestData* manifest_data, |
| 54 content::SocketPermissionRequest::OperationType operation_type, | 87 content::SocketPermissionRequest::OperationType operation_type, |
| 55 const scoped_ptr<std::string>& value, | 88 const scoped_ptr<std::string>& value, |
| 56 string16* error); | 89 string16* error); |
| 57 | 90 |
| 91 scoped_ptr<std::string> CreateHostPattern( | |
| 92 content::SocketPermissionRequest::OperationType operation_type) const; | |
| 93 | |
| 58 void AddPermission(const SocketPermissionEntry& entry); | 94 void AddPermission(const SocketPermissionEntry& entry); |
| 59 | 95 |
| 60 bool CheckRequestImpl(const Extension* extension, | 96 bool CheckRequestImpl(const Extension* extension, |
| 61 const content::SocketPermissionRequest& request); | 97 const content::SocketPermissionRequest& request); |
| 62 | 98 |
| 63 PermissionSet permissions_; | 99 bool AddAnyHostMessage(PermissionMessages& messages) const; |
| 100 void AddSubdomainHostMessage(PermissionMessages& messages) const; | |
| 101 void AddSpecificHostMessage(PermissionMessages& messages) const; | |
| 102 void AddNetworkListMessage(PermissionMessages& messages) const; | |
| 103 | |
| 104 SocketPermissionEntrySet permissions_; | |
| 105 int kinds_; // PermissionKind bits | |
| 64 }; | 106 }; |
| 65 | 107 |
| 66 } // namespace extensions | 108 } // namespace extensions |
| 67 | 109 |
| 68 #endif // CHROME_COMMON_EXTENSIONS_API_SOCKETS_SOCKETS_HANDLER_H_ | 110 #endif // CHROME_COMMON_EXTENSIONS_API_SOCKETS_SOCKETS_HANDLER_H_ |
| OLD | NEW |