OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_PERMISSION_MANAGER_H_ | 5 #ifndef CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_PERMISSION_MANAGER_H_ |
6 #define CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_PERMISSION_MANAGER_H_ | 6 #define CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_PERMISSION_MANAGER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
12 #include "base/id_map.h" | 12 #include "base/id_map.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
15 #include "content/public/browser/permission_manager.h" | 15 #include "content/public/browser/permission_manager.h" |
16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 | 19 |
20 class LayoutTestPermissionManager : public PermissionManager { | 20 class LayoutTestPermissionManager : public PermissionManager { |
21 public: | 21 public: |
22 LayoutTestPermissionManager(); | 22 LayoutTestPermissionManager(); |
23 ~LayoutTestPermissionManager() override; | 23 ~LayoutTestPermissionManager() override; |
24 | 24 |
25 // PermissionManager overrides. | 25 // PermissionManager overrides. |
26 int RequestPermission( | 26 int RequestPermission( |
27 PermissionType permission, | 27 PermissionType permission, |
28 RenderFrameHost* render_frame_host, | 28 RenderFrameHost* render_frame_host, |
29 const GURL& requesting_origin, | 29 const GURL& requesting_origin, |
30 const base::Callback<void(PermissionStatus)>& callback) override; | 30 const base::Callback<void(blink::mojom::PermissionStatus)>& callback) |
| 31 override; |
31 int RequestPermissions( | 32 int RequestPermissions( |
32 const std::vector<PermissionType>& permission, | 33 const std::vector<PermissionType>& permission, |
33 RenderFrameHost* render_frame_host, | 34 RenderFrameHost* render_frame_host, |
34 const GURL& requesting_origin, | 35 const GURL& requesting_origin, |
35 const base::Callback<void( | 36 const base::Callback< |
36 const std::vector<PermissionStatus>&)>& callback) override; | 37 void(const std::vector<blink::mojom::PermissionStatus>&)>& callback) |
| 38 override; |
37 void CancelPermissionRequest(int request_id) override; | 39 void CancelPermissionRequest(int request_id) override; |
38 void ResetPermission(PermissionType permission, | 40 void ResetPermission(PermissionType permission, |
39 const GURL& requesting_origin, | 41 const GURL& requesting_origin, |
40 const GURL& embedding_origin) override; | 42 const GURL& embedding_origin) override; |
41 PermissionStatus GetPermissionStatus(PermissionType permission, | 43 blink::mojom::PermissionStatus GetPermissionStatus( |
42 const GURL& requesting_origin, | 44 PermissionType permission, |
43 const GURL& embedding_origin) override; | 45 const GURL& requesting_origin, |
| 46 const GURL& embedding_origin) override; |
44 void RegisterPermissionUsage(PermissionType permission, | 47 void RegisterPermissionUsage(PermissionType permission, |
45 const GURL& requesting_origin, | 48 const GURL& requesting_origin, |
46 const GURL& embedding_origin) override; | 49 const GURL& embedding_origin) override; |
47 int SubscribePermissionStatusChange( | 50 int SubscribePermissionStatusChange( |
48 PermissionType permission, | 51 PermissionType permission, |
49 const GURL& requesting_origin, | 52 const GURL& requesting_origin, |
50 const GURL& embedding_origin, | 53 const GURL& embedding_origin, |
51 const base::Callback<void(PermissionStatus)>& callback) override; | 54 const base::Callback<void(blink::mojom::PermissionStatus)>& callback) |
| 55 override; |
52 void UnsubscribePermissionStatusChange(int subscription_id) override; | 56 void UnsubscribePermissionStatusChange(int subscription_id) override; |
53 | 57 |
54 void SetPermission(PermissionType permission, | 58 void SetPermission(PermissionType permission, |
55 PermissionStatus status, | 59 blink::mojom::PermissionStatus status, |
56 const GURL& origin, | 60 const GURL& origin, |
57 const GURL& embedding_origin); | 61 const GURL& embedding_origin); |
58 void ResetPermissions(); | 62 void ResetPermissions(); |
59 | 63 |
60 private: | 64 private: |
61 // Representation of a permission for the LayoutTestPermissionManager. | 65 // Representation of a permission for the LayoutTestPermissionManager. |
62 struct PermissionDescription { | 66 struct PermissionDescription { |
63 PermissionDescription() = default; | 67 PermissionDescription() = default; |
64 PermissionDescription(PermissionType type, | 68 PermissionDescription(PermissionType type, |
65 const GURL& origin, | 69 const GURL& origin, |
66 const GURL& embedding_origin); | 70 const GURL& embedding_origin); |
67 bool operator==(const PermissionDescription& other) const; | 71 bool operator==(const PermissionDescription& other) const; |
68 bool operator!=(const PermissionDescription& other) const; | 72 bool operator!=(const PermissionDescription& other) const; |
69 | 73 |
70 // Hash operator for hash maps. | 74 // Hash operator for hash maps. |
71 struct Hash { | 75 struct Hash { |
72 size_t operator()(const PermissionDescription& description) const; | 76 size_t operator()(const PermissionDescription& description) const; |
73 }; | 77 }; |
74 | 78 |
75 PermissionType type; | 79 PermissionType type; |
76 GURL origin; | 80 GURL origin; |
77 GURL embedding_origin; | 81 GURL embedding_origin; |
78 }; | 82 }; |
79 | 83 |
80 struct Subscription; | 84 struct Subscription; |
81 using SubscriptionsMap = IDMap<Subscription, IDMapOwnPointer>; | 85 using SubscriptionsMap = IDMap<Subscription, IDMapOwnPointer>; |
82 using PermissionsMap = base::hash_map<PermissionDescription, | 86 using PermissionsMap = base::hash_map<PermissionDescription, |
83 PermissionStatus, | 87 blink::mojom::PermissionStatus, |
84 PermissionDescription::Hash>; | 88 PermissionDescription::Hash>; |
85 | 89 |
86 void OnPermissionChanged(const PermissionDescription& permission, | 90 void OnPermissionChanged(const PermissionDescription& permission, |
87 PermissionStatus status); | 91 blink::mojom::PermissionStatus status); |
88 | 92 |
89 // Mutex for permissions access. Unfortunately, the permissions can be | 93 // Mutex for permissions access. Unfortunately, the permissions can be |
90 // accessed from the IO thread because of Notifications' synchronous IPC. | 94 // accessed from the IO thread because of Notifications' synchronous IPC. |
91 base::Lock permissions_lock_; | 95 base::Lock permissions_lock_; |
92 | 96 |
93 // List of permissions currently known by the LayoutTestPermissionManager and | 97 // List of permissions currently known by the LayoutTestPermissionManager and |
94 // their associated |PermissionStatus|. | 98 // their associated |blink::mojom::PermissionStatus|. |
95 PermissionsMap permissions_; | 99 PermissionsMap permissions_; |
96 | 100 |
97 // List of subscribers currently listening to permission changes. | 101 // List of subscribers currently listening to permission changes. |
98 SubscriptionsMap subscriptions_; | 102 SubscriptionsMap subscriptions_; |
99 | 103 |
100 DISALLOW_COPY_AND_ASSIGN(LayoutTestPermissionManager); | 104 DISALLOW_COPY_AND_ASSIGN(LayoutTestPermissionManager); |
101 }; | 105 }; |
102 | 106 |
103 } // namespace content | 107 } // namespace content |
104 | 108 |
105 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_PERMISSION_MANAGER_H_ | 109 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_PERMISSION_MANAGER_H_ |
OLD | NEW |