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