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(mojom::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(const std::vector<mojom::PermissionStatus>&)>& | 36 const base::Callback< |
36 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 mojom::PermissionStatus GetPermissionStatus( | 43 blink::mojom::PermissionStatus GetPermissionStatus( |
42 PermissionType permission, | 44 PermissionType permission, |
43 const GURL& requesting_origin, | 45 const GURL& requesting_origin, |
44 const GURL& embedding_origin) override; | 46 const GURL& embedding_origin) override; |
45 void RegisterPermissionUsage(PermissionType permission, | 47 void RegisterPermissionUsage(PermissionType permission, |
46 const GURL& requesting_origin, | 48 const GURL& requesting_origin, |
47 const GURL& embedding_origin) override; | 49 const GURL& embedding_origin) override; |
48 int SubscribePermissionStatusChange( | 50 int SubscribePermissionStatusChange( |
49 PermissionType permission, | 51 PermissionType permission, |
50 const GURL& requesting_origin, | 52 const GURL& requesting_origin, |
51 const GURL& embedding_origin, | 53 const GURL& embedding_origin, |
52 const base::Callback<void(mojom::PermissionStatus)>& callback) override; | 54 const base::Callback<void(blink::mojom::PermissionStatus)>& callback) |
| 55 override; |
53 void UnsubscribePermissionStatusChange(int subscription_id) override; | 56 void UnsubscribePermissionStatusChange(int subscription_id) override; |
54 | 57 |
55 void SetPermission(PermissionType permission, | 58 void SetPermission(PermissionType permission, |
56 mojom::PermissionStatus status, | 59 blink::mojom::PermissionStatus status, |
57 const GURL& origin, | 60 const GURL& origin, |
58 const GURL& embedding_origin); | 61 const GURL& embedding_origin); |
59 void ResetPermissions(); | 62 void ResetPermissions(); |
60 | 63 |
61 private: | 64 private: |
62 // Representation of a permission for the LayoutTestPermissionManager. | 65 // Representation of a permission for the LayoutTestPermissionManager. |
63 struct PermissionDescription { | 66 struct PermissionDescription { |
64 PermissionDescription() = default; | 67 PermissionDescription() = default; |
65 PermissionDescription(PermissionType type, | 68 PermissionDescription(PermissionType type, |
66 const GURL& origin, | 69 const GURL& origin, |
67 const GURL& embedding_origin); | 70 const GURL& embedding_origin); |
68 bool operator==(const PermissionDescription& other) const; | 71 bool operator==(const PermissionDescription& other) const; |
69 bool operator!=(const PermissionDescription& other) const; | 72 bool operator!=(const PermissionDescription& other) const; |
70 | 73 |
71 // Hash operator for hash maps. | 74 // Hash operator for hash maps. |
72 struct Hash { | 75 struct Hash { |
73 size_t operator()(const PermissionDescription& description) const; | 76 size_t operator()(const PermissionDescription& description) const; |
74 }; | 77 }; |
75 | 78 |
76 PermissionType type; | 79 PermissionType type; |
77 GURL origin; | 80 GURL origin; |
78 GURL embedding_origin; | 81 GURL embedding_origin; |
79 }; | 82 }; |
80 | 83 |
81 struct Subscription; | 84 struct Subscription; |
82 using SubscriptionsMap = IDMap<Subscription, IDMapOwnPointer>; | 85 using SubscriptionsMap = IDMap<Subscription, IDMapOwnPointer>; |
83 using PermissionsMap = base::hash_map<PermissionDescription, | 86 using PermissionsMap = base::hash_map<PermissionDescription, |
84 mojom::PermissionStatus, | 87 blink::mojom::PermissionStatus, |
85 PermissionDescription::Hash>; | 88 PermissionDescription::Hash>; |
86 | 89 |
87 void OnPermissionChanged(const PermissionDescription& permission, | 90 void OnPermissionChanged(const PermissionDescription& permission, |
88 mojom::PermissionStatus status); | 91 blink::mojom::PermissionStatus status); |
89 | 92 |
90 // Mutex for permissions access. Unfortunately, the permissions can be | 93 // Mutex for permissions access. Unfortunately, the permissions can be |
91 // accessed from the IO thread because of Notifications' synchronous IPC. | 94 // accessed from the IO thread because of Notifications' synchronous IPC. |
92 base::Lock permissions_lock_; | 95 base::Lock permissions_lock_; |
93 | 96 |
94 // List of permissions currently known by the LayoutTestPermissionManager and | 97 // List of permissions currently known by the LayoutTestPermissionManager and |
95 // their associated |PermissionStatus|. | 98 // their associated |PermissionStatus|. |
96 PermissionsMap permissions_; | 99 PermissionsMap permissions_; |
97 | 100 |
98 // List of subscribers currently listening to permission changes. | 101 // List of subscribers currently listening to permission changes. |
99 SubscriptionsMap subscriptions_; | 102 SubscriptionsMap subscriptions_; |
100 | 103 |
101 DISALLOW_COPY_AND_ASSIGN(LayoutTestPermissionManager); | 104 DISALLOW_COPY_AND_ASSIGN(LayoutTestPermissionManager); |
102 }; | 105 }; |
103 | 106 |
104 } // namespace content | 107 } // namespace content |
105 | 108 |
106 #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 |