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