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 15 matching lines...) Expand all Loading... |
26 | 26 |
27 class PermissionManager : public KeyedService, | 27 class PermissionManager : public KeyedService, |
28 public content::PermissionManager, | 28 public content::PermissionManager, |
29 public content_settings::Observer { | 29 public content_settings::Observer { |
30 public: | 30 public: |
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 // Callers from within chrome/ should use the methods which take the |
| 37 // ContentSettingsType enum. The methods which take PermissionType values |
| 38 // are for the content::PermissionManager overrides and shouldn't be used |
| 39 // from chrome/. |
| 40 int RequestPermission( |
| 41 ContentSettingsType permission, |
| 42 content::RenderFrameHost* render_frame_host, |
| 43 const GURL& requesting_origin, |
| 44 bool user_gesture, |
| 45 const base::Callback<void(blink::mojom::PermissionStatus)>& callback); |
| 46 blink::mojom::PermissionStatus GetPermissionStatus( |
| 47 ContentSettingsType permission, |
| 48 const GURL& requesting_origin, |
| 49 const GURL& embedding_origin); |
| 50 |
36 // content::PermissionManager implementation. | 51 // content::PermissionManager implementation. |
37 int RequestPermission( | 52 int RequestPermission( |
38 content::PermissionType permission, | 53 content::PermissionType permission, |
39 content::RenderFrameHost* render_frame_host, | 54 content::RenderFrameHost* render_frame_host, |
40 const GURL& requesting_origin, | 55 const GURL& requesting_origin, |
41 bool user_gesture, | 56 bool user_gesture, |
42 const base::Callback<void(blink::mojom::PermissionStatus)>& callback) | 57 const base::Callback<void(blink::mojom::PermissionStatus)>& callback) |
43 override; | 58 override; |
44 int RequestPermissions( | 59 int RequestPermissions( |
45 const std::vector<content::PermissionType>& permissions, | 60 const std::vector<content::PermissionType>& permissions, |
(...skipping 18 matching lines...) Expand all Loading... |
64 content::PermissionType permission, | 79 content::PermissionType permission, |
65 const GURL& requesting_origin, | 80 const GURL& requesting_origin, |
66 const GURL& embedding_origin, | 81 const GURL& embedding_origin, |
67 const base::Callback<void(blink::mojom::PermissionStatus)>& callback) | 82 const base::Callback<void(blink::mojom::PermissionStatus)>& callback) |
68 override; | 83 override; |
69 void UnsubscribePermissionStatusChange(int subscription_id) override; | 84 void UnsubscribePermissionStatusChange(int subscription_id) override; |
70 | 85 |
71 // TODO(raymes): Rather than exposing this, expose a denial reason from | 86 // TODO(raymes): Rather than exposing this, expose a denial reason from |
72 // GetPermissionStatus so that callers can determine whether a permission is | 87 // GetPermissionStatus so that callers can determine whether a permission is |
73 // denied due to the kill switch. | 88 // denied due to the kill switch. |
74 bool IsPermissionKillSwitchOn(content::PermissionType permission); | 89 bool IsPermissionKillSwitchOn(ContentSettingsType); |
75 | 90 |
76 private: | 91 private: |
77 friend class GeolocationPermissionContextTests; | 92 friend class GeolocationPermissionContextTests; |
78 | 93 |
79 class PendingRequest; | 94 class PendingRequest; |
80 using PendingRequestsMap = IDMap<std::unique_ptr<PendingRequest>>; | 95 using PendingRequestsMap = IDMap<std::unique_ptr<PendingRequest>>; |
81 | 96 |
82 struct Subscription; | 97 struct Subscription; |
83 using SubscriptionsMap = IDMap<std::unique_ptr<Subscription>>; | 98 using SubscriptionsMap = IDMap<std::unique_ptr<Subscription>>; |
84 | 99 |
85 PermissionContextBase* GetPermissionContext(content::PermissionType type); | 100 PermissionContextBase* GetPermissionContext(ContentSettingsType type); |
86 | 101 |
87 // Called when a permission was decided for a given PendingRequest. The | 102 // Called when a permission was decided for a given PendingRequest. The |
88 // PendingRequest is identified by its |request_id| and the permission is | 103 // PendingRequest is identified by its |request_id| and the permission is |
89 // identified by its |permission_id|. If the PendingRequest contains more than | 104 // identified by its |permission_id|. If the PendingRequest contains more than |
90 // one permission, it will wait for the remaining permissions to be resolved. | 105 // one permission, it will wait for the remaining permissions to be resolved. |
91 // When all the permissions have been resolved, the PendingRequest's callback | 106 // When all the permissions have been resolved, the PendingRequest's callback |
92 // is run. | 107 // is run. |
93 void OnPermissionsRequestResponseStatus( | 108 void OnPermissionsRequestResponseStatus( |
94 int request_id, | 109 int request_id, |
95 int permission_id, | 110 int permission_id, |
96 blink::mojom::PermissionStatus status); | 111 blink::mojom::PermissionStatus status); |
97 | 112 |
98 // content_settings::Observer implementation. | 113 // content_settings::Observer implementation. |
99 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, | 114 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, |
100 const ContentSettingsPattern& secondary_pattern, | 115 const ContentSettingsPattern& secondary_pattern, |
101 ContentSettingsType content_type, | 116 ContentSettingsType content_type, |
102 std::string resource_identifier) override; | 117 std::string resource_identifier) override; |
103 | 118 |
104 ContentSetting GetPermissionStatusInternal(content::PermissionType permission, | |
105 const GURL& requesting_origin, | |
106 const GURL& embedding_origin); | |
107 | |
108 Profile* profile_; | 119 Profile* profile_; |
109 PendingRequestsMap pending_requests_; | 120 PendingRequestsMap pending_requests_; |
110 SubscriptionsMap subscriptions_; | 121 SubscriptionsMap subscriptions_; |
111 | 122 |
112 std::unordered_map<content::PermissionType, | 123 std::unordered_map<ContentSettingsType, |
113 std::unique_ptr<PermissionContextBase>, | 124 std::unique_ptr<PermissionContextBase>, |
114 PermissionTypeHash> | 125 ContentSettingsTypeHash> |
115 permission_contexts_; | 126 permission_contexts_; |
116 | 127 |
117 base::WeakPtrFactory<PermissionManager> weak_ptr_factory_; | 128 base::WeakPtrFactory<PermissionManager> weak_ptr_factory_; |
118 | 129 |
119 DISALLOW_COPY_AND_ASSIGN(PermissionManager); | 130 DISALLOW_COPY_AND_ASSIGN(PermissionManager); |
120 }; | 131 }; |
121 | 132 |
122 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_MANAGER_H_ | 133 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_MANAGER_H_ |
OLD | NEW |