1 // Copyright 2015 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 CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_PERMISSION_MANAGER_H_
6 #define CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_PERMISSION_MANAGER_H_
8 #include "base/callback_forward.h"
9 #include "base/containers/hash_tables.h"
10 #include "base/id_map.h"
11 #include "base/macros.h"
12 #include "base/synchronization/lock.h"
13 #include "content/public/browser/permission_manager.h"
18 class LayoutTestPermissionManager
: public PermissionManager
{
20 LayoutTestPermissionManager();
21 ~LayoutTestPermissionManager() override
;
23 // PermissionManager overrides.
24 void RequestPermission(
25 PermissionType permission
,
26 WebContents
* web_contents
,
28 const GURL
& requesting_origin
,
30 const base::Callback
<void(PermissionStatus
)>& callback
) override
;
31 void CancelPermissionRequest(PermissionType permission
,
32 WebContents
* web_contents
,
34 const GURL
& requesting_origin
) override
;
35 void ResetPermission(PermissionType permission
,
36 const GURL
& requesting_origin
,
37 const GURL
& embedding_origin
) override
;
38 PermissionStatus
GetPermissionStatus(PermissionType permission
,
39 const GURL
& requesting_origin
,
40 const GURL
& embedding_origin
) override
;
41 void RegisterPermissionUsage(PermissionType permission
,
42 const GURL
& requesting_origin
,
43 const GURL
& embedding_origin
) override
;
44 int SubscribePermissionStatusChange(
45 PermissionType permission
,
46 const GURL
& requesting_origin
,
47 const GURL
& embedding_origin
,
48 const base::Callback
<void(PermissionStatus
)>& callback
) override
;
49 void UnsubscribePermissionStatusChange(int subscription_id
) override
;
51 void SetPermission(PermissionType permission
,
52 PermissionStatus status
,
54 const GURL
& embedding_origin
);
55 void ResetPermissions();
58 // Representation of a permission for the LayoutTestPermissionManager.
59 struct PermissionDescription
{
60 PermissionDescription() = default;
61 PermissionDescription(PermissionType type
,
63 const GURL
& embedding_origin
);
64 bool operator==(const PermissionDescription
& other
) const;
65 bool operator!=(const PermissionDescription
& other
) const;
67 // Hash operator for hash maps.
69 size_t operator()(const PermissionDescription
& description
) const;
74 GURL embedding_origin
;
78 using SubscriptionsMap
= IDMap
<Subscription
, IDMapOwnPointer
>;
79 using PermissionsMap
= base::hash_map
<PermissionDescription
,
81 PermissionDescription::Hash
>;
83 void OnPermissionChanged(const PermissionDescription
& permission
,
84 PermissionStatus status
);
86 // Mutex for permissions access. Unfortunately, the permissions can be
87 // accessed from the IO thread because of Notifications' synchronous IPC.
88 base::Lock permissions_lock_
;
90 // List of permissions currently known by the LayoutTestPermissionManager and
91 // their associated |PermissionStatus|.
92 PermissionsMap permissions_
;
94 // List of subscribers currently listening to permission changes.
95 SubscriptionsMap subscriptions_
;
97 DISALLOW_COPY_AND_ASSIGN(LayoutTestPermissionManager
);
100 } // namespace content
102 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_PERMISSION_MANAGER_H_