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 CHROME_BROWSER_PERMISSIONS_PERMISSION_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_MANAGER_H_ |
6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_MANAGER_H_ | 6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_MANAGER_H_ |
7 | 7 |
8 #include <unordered_map> | 8 #include <unordered_map> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 static PermissionManager* Get(Profile* profile); | 31 static PermissionManager* Get(Profile* profile); |
32 | 32 |
33 explicit PermissionManager(Profile* profile); | 33 explicit PermissionManager(Profile* profile); |
34 ~PermissionManager() override; | 34 ~PermissionManager() override; |
35 | 35 |
36 // content::PermissionManager implementation. | 36 // content::PermissionManager implementation. |
37 int RequestPermission( | 37 int RequestPermission( |
38 content::PermissionType permission, | 38 content::PermissionType permission, |
39 content::RenderFrameHost* render_frame_host, | 39 content::RenderFrameHost* render_frame_host, |
40 const GURL& requesting_origin, | 40 const GURL& requesting_origin, |
41 const base::Callback<void(blink::mojom::PermissionStatus)>& callback) | 41 const base::Callback<void(permissions::mojom::PermissionStatus)>& |
42 override; | 42 callback) override; |
43 int RequestPermissions( | 43 int RequestPermissions( |
44 const std::vector<content::PermissionType>& permissions, | 44 const std::vector<content::PermissionType>& permissions, |
45 content::RenderFrameHost* render_frame_host, | 45 content::RenderFrameHost* render_frame_host, |
46 const GURL& requesting_origin, | 46 const GURL& requesting_origin, |
47 const base::Callback< | 47 const base::Callback<void( |
48 void(const std::vector<blink::mojom::PermissionStatus>&)>& callback) | 48 const std::vector<permissions::mojom::PermissionStatus>&)>& callback) |
49 override; | 49 override; |
50 void CancelPermissionRequest(int request_id) override; | 50 void CancelPermissionRequest(int request_id) override; |
51 void ResetPermission(content::PermissionType permission, | 51 void ResetPermission(content::PermissionType permission, |
52 const GURL& requesting_origin, | 52 const GURL& requesting_origin, |
53 const GURL& embedding_origin) override; | 53 const GURL& embedding_origin) override; |
54 blink::mojom::PermissionStatus GetPermissionStatus( | 54 permissions::mojom::PermissionStatus GetPermissionStatus( |
55 content::PermissionType permission, | 55 content::PermissionType permission, |
56 const GURL& requesting_origin, | 56 const GURL& requesting_origin, |
57 const GURL& embedding_origin) override; | 57 const GURL& embedding_origin) override; |
58 void RegisterPermissionUsage(content::PermissionType permission, | 58 void RegisterPermissionUsage(content::PermissionType permission, |
59 const GURL& requesting_origin, | 59 const GURL& requesting_origin, |
60 const GURL& embedding_origin) override; | 60 const GURL& embedding_origin) override; |
61 int SubscribePermissionStatusChange( | 61 int SubscribePermissionStatusChange( |
62 content::PermissionType permission, | 62 content::PermissionType permission, |
63 const GURL& requesting_origin, | 63 const GURL& requesting_origin, |
64 const GURL& embedding_origin, | 64 const GURL& embedding_origin, |
65 const base::Callback<void(blink::mojom::PermissionStatus)>& callback) | 65 const base::Callback<void(permissions::mojom::PermissionStatus)>& |
66 override; | 66 callback) override; |
67 void UnsubscribePermissionStatusChange(int subscription_id) override; | 67 void UnsubscribePermissionStatusChange(int subscription_id) override; |
68 | 68 |
69 private: | 69 private: |
70 friend class GeolocationPermissionContextTests; | 70 friend class GeolocationPermissionContextTests; |
71 // TODO(raymes): Refactor MediaPermission to not call GetPermissionContext. | 71 // TODO(raymes): Refactor MediaPermission to not call GetPermissionContext. |
72 // See crbug.com/596786. | 72 // See crbug.com/596786. |
73 friend class MediaPermission; | 73 friend class MediaPermission; |
74 | 74 |
75 class PendingRequest; | 75 class PendingRequest; |
76 using PendingRequestsMap = IDMap<PendingRequest, IDMapOwnPointer>; | 76 using PendingRequestsMap = IDMap<PendingRequest, IDMapOwnPointer>; |
77 | 77 |
78 struct Subscription; | 78 struct Subscription; |
79 using SubscriptionsMap = IDMap<Subscription, IDMapOwnPointer>; | 79 using SubscriptionsMap = IDMap<Subscription, IDMapOwnPointer>; |
80 | 80 |
81 struct PermissionTypeHash { | 81 struct PermissionTypeHash { |
82 std::size_t operator()(const content::PermissionType& type) const; | 82 std::size_t operator()(const content::PermissionType& type) const; |
83 }; | 83 }; |
84 | 84 |
85 PermissionContextBase* GetPermissionContext(content::PermissionType type); | 85 PermissionContextBase* GetPermissionContext(content::PermissionType type); |
86 | 86 |
87 // Called when a permission was decided for a given PendingRequest. The | 87 // Called when a permission was decided for a given PendingRequest. The |
88 // PendingRequest is identified by its |request_id| and the permission is | 88 // PendingRequest is identified by its |request_id| and the permission is |
89 // identified by its |permission_id|. If the PendingRequest contains more than | 89 // identified by its |permission_id|. If the PendingRequest contains more than |
90 // one permission, it will wait for the remaining permissions to be resolved. | 90 // one permission, it will wait for the remaining permissions to be resolved. |
91 // When all the permissions have been resolved, the PendingRequest's callback | 91 // When all the permissions have been resolved, the PendingRequest's callback |
92 // is run. | 92 // is run. |
93 void OnPermissionsRequestResponseStatus( | 93 void OnPermissionsRequestResponseStatus( |
94 int request_id, | 94 int request_id, |
95 int permission_id, | 95 int permission_id, |
96 blink::mojom::PermissionStatus status); | 96 permissions::mojom::PermissionStatus status); |
97 | 97 |
98 // content_settings::Observer implementation. | 98 // content_settings::Observer implementation. |
99 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, | 99 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, |
100 const ContentSettingsPattern& secondary_pattern, | 100 const ContentSettingsPattern& secondary_pattern, |
101 ContentSettingsType content_type, | 101 ContentSettingsType content_type, |
102 std::string resource_identifier) override; | 102 std::string resource_identifier) override; |
103 | 103 |
104 Profile* profile_; | 104 Profile* profile_; |
105 PendingRequestsMap pending_requests_; | 105 PendingRequestsMap pending_requests_; |
106 SubscriptionsMap subscriptions_; | 106 SubscriptionsMap subscriptions_; |
107 | 107 |
108 std::unordered_map<content::PermissionType, | 108 std::unordered_map<content::PermissionType, |
109 std::unique_ptr<PermissionContextBase>, | 109 std::unique_ptr<PermissionContextBase>, |
110 PermissionTypeHash> | 110 PermissionTypeHash> |
111 permission_contexts_; | 111 permission_contexts_; |
112 | 112 |
113 base::WeakPtrFactory<PermissionManager> weak_ptr_factory_; | 113 base::WeakPtrFactory<PermissionManager> weak_ptr_factory_; |
114 | 114 |
115 DISALLOW_COPY_AND_ASSIGN(PermissionManager); | 115 DISALLOW_COPY_AND_ASSIGN(PermissionManager); |
116 }; | 116 }; |
117 | 117 |
118 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_MANAGER_H_ | 118 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_MANAGER_H_ |
OLD | NEW |