1// Copyright 2014 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
5#ifndef EXTENSIONS_COMMON_API_SOCKETS_SOCKETS_MANIFEST_PERMISSION_H_
6#define EXTENSIONS_COMMON_API_SOCKETS_SOCKETS_MANIFEST_PERMISSION_H_
7
8#include <set>
9#include <vector>
10
11#include "extensions/common/install_warning.h"
12#include "extensions/common/permissions/manifest_permission.h"
13#include "extensions/common/permissions/socket_permission_entry.h"
14
15namespace content {
16struct SocketPermissionRequest;
17}
18
19namespace extensions {
20class Extension;
21}
22
23namespace extensions {
24
25class SocketsManifestPermission : public ManifestPermission {
26 public:
27  typedef std::set<SocketPermissionEntry> SocketPermissionEntrySet;
28  SocketsManifestPermission();
29  virtual ~SocketsManifestPermission();
30
31  // Tries to construct the info based on |value|, as it would have appeared in
32  // the manifest. Sets |error| and returns an empty scoped_ptr on failure.
33  static scoped_ptr<SocketsManifestPermission> FromValue(
34      const base::Value& value,
35      base::string16* error);
36
37  bool CheckRequest(const Extension* extension,
38                    const content::SocketPermissionRequest& request) const;
39
40  void AddPermission(const SocketPermissionEntry& entry);
41
42  // extensions::ManifestPermission overrides.
43  virtual std::string name() const OVERRIDE;
44  virtual std::string id() const OVERRIDE;
45  virtual bool HasMessages() const OVERRIDE;
46  virtual PermissionMessages GetMessages() const OVERRIDE;
47  virtual bool FromValue(const base::Value* value) OVERRIDE;
48  virtual scoped_ptr<base::Value> ToValue() const OVERRIDE;
49  virtual ManifestPermission* Diff(const ManifestPermission* rhs) const
50      OVERRIDE;
51  virtual ManifestPermission* Union(const ManifestPermission* rhs) const
52      OVERRIDE;
53  virtual ManifestPermission* Intersect(const ManifestPermission* rhs) const
54      OVERRIDE;
55
56  const SocketPermissionEntrySet& entries() const { return permissions_; }
57
58 private:
59  bool AddAnyHostMessage(PermissionMessages& messages) const;
60  void AddSubdomainHostMessage(PermissionMessages& messages) const;
61  void AddSpecificHostMessage(PermissionMessages& messages) const;
62  void AddNetworkListMessage(PermissionMessages& messages) const;
63
64  SocketPermissionEntrySet permissions_;
65};
66
67}  // namespace extensions
68
69#endif  // EXTENSIONS_COMMON_API_SOCKETS_SOCKETS_MANIFEST_PERMISSION_H_
70