1 // Copyright (c) 2012 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_PERMISSIONS_SOCKET_PERMISSION_H_
6 #define CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_H_
11 #include "chrome/common/extensions/permissions/api_permission.h"
12 #include "chrome/common/extensions/permissions/socket_permission_data.h"
22 namespace extensions
{
24 // There's room to share code with related classes, see http://crbug.com/147531
26 class SocketPermission
: public APIPermission
{
28 struct CheckParam
: APIPermission::CheckParam
{
29 CheckParam(content::SocketPermissionRequest::OperationType type
,
30 const std::string
& host
,
32 : request(type
, host
, port
) { }
33 content::SocketPermissionRequest request
;
36 explicit SocketPermission(const APIPermissionInfo
* info
);
38 virtual ~SocketPermission();
40 // Returns true if this permission has PermissionMessages.
41 virtual bool HasMessages() const OVERRIDE
;
43 // Returns the localized permission messages of this permission.
44 virtual PermissionMessages
GetMessages() const OVERRIDE
;
46 // Returns true if the given permission in param is allowed.
48 const APIPermission::CheckParam
* param
) const OVERRIDE
;
50 // Returns true if |rhs| is a subset of this.
51 virtual bool Contains(const APIPermission
* rhs
) const OVERRIDE
;
53 // Returns true if |rhs| is equal to this.
54 virtual bool Equal(const APIPermission
* rhs
) const OVERRIDE
;
56 // Parses the rhs from |value|. Returns false if error happens.
57 virtual bool FromValue(const base::Value
* value
) OVERRIDE
;
59 // Stores this into a new created |value|.
60 virtual void ToValue(base::Value
** value
) const OVERRIDE
;
63 virtual APIPermission
* Clone() const OVERRIDE
;
65 // Returns a new API permission rhs which equals this - |rhs|.
66 virtual APIPermission
* Diff(const APIPermission
* rhs
) const OVERRIDE
;
68 // Returns a new API permission rhs which equals the union of this and
70 virtual APIPermission
* Union(const APIPermission
* rhs
) const OVERRIDE
;
72 // Returns a new API permission rhs which equals the intersect of this and
74 virtual APIPermission
* Intersect(const APIPermission
* rhs
) const OVERRIDE
;
77 // Writes this into the given IPC message |m|.
78 virtual void Write(IPC::Message
* m
) const OVERRIDE
;
80 // Reads from the given IPC message |m|.
81 virtual bool Read(const IPC::Message
* m
, PickleIterator
* iter
) OVERRIDE
;
84 virtual void Log(std::string
* log
) const OVERRIDE
;
87 bool AddAnyHostMessage(PermissionMessages
& messages
) const;
88 void AddSubdomainHostMessage(PermissionMessages
& messages
) const;
89 void AddSpecificHostMessage(PermissionMessages
& messages
) const;
91 std::set
<SocketPermissionData
> data_set_
;
94 } // namespace extensions
96 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_H_