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.
5 #ifndef CHROME_COMMON_EXTENSIONS_API_SOCKETS_SOCKETS_HANDLER_H_
6 #define CHROME_COMMON_EXTENSIONS_API_SOCKETS_SOCKETS_HANDLER_H_
8 #include "base/strings/string16.h"
9 #include "chrome/common/extensions/extension.h"
10 #include "chrome/common/extensions/manifest_handler.h"
11 #include "chrome/common/extensions/permissions/socket_permission_data.h"
13 namespace extensions {
15 // Parses the "sockets" manifest key.
16 class SocketsHandler : public ManifestHandler {
19 virtual ~SocketsHandler();
21 virtual bool Parse(Extension* extension, string16* error) OVERRIDE;
24 virtual const std::vector<std::string> Keys() const OVERRIDE;
26 DISALLOW_COPY_AND_ASSIGN(SocketsHandler);
29 // The parsed form of the "sockets" manifest entry.
30 class SocketsManifestData : public Extension::ManifestData {
32 SocketsManifestData();
33 virtual ~SocketsManifestData();
35 // Gets the ExternallyConnectableInfo for |extension|, or NULL if none was
37 static SocketsManifestData* Get(const Extension* extension);
39 static bool CheckRequest(const Extension* extension,
40 const content::SocketPermissionRequest& request);
42 // 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.
44 static scoped_ptr<SocketsManifestData> FromValue(
45 const base::Value& value,
46 std::vector<InstallWarning>* install_warnings,
50 typedef std::set<SocketPermissionEntry> PermissionSet;
52 static bool ParseHostPattern(
53 SocketsManifestData* manifest_data,
54 content::SocketPermissionRequest::OperationType operation_type,
55 const scoped_ptr<std::string>& value,
58 void AddPermission(const SocketPermissionEntry& entry);
60 bool CheckRequestImpl(const Extension* extension,
61 const content::SocketPermissionRequest& request);
63 PermissionSet permissions_;
66 } // namespace extensions
68 #endif // CHROME_COMMON_EXTENSIONS_API_SOCKETS_SOCKETS_HANDLER_H_