OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_CONTEXT_BASE_H_ | 5 #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ |
6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ | 6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <unordered_map> | 9 #include <unordered_map> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 class PermissionQueueController; | 21 class PermissionQueueController; |
22 #endif | 22 #endif |
23 class GURL; | 23 class GURL; |
24 class PermissionRequestID; | 24 class PermissionRequestID; |
25 class Profile; | 25 class Profile; |
26 | 26 |
27 namespace content { | 27 namespace content { |
28 class WebContents; | 28 class WebContents; |
29 } | 29 } |
30 | 30 |
31 namespace safe_browsing { | |
32 class SafeBrowsingDatabaseManager; | |
33 } | |
34 | |
35 using BrowserPermissionCallback = base::Callback<void(ContentSetting)>; | 31 using BrowserPermissionCallback = base::Callback<void(ContentSetting)>; |
36 | 32 |
37 // This base class contains common operations for granting permissions. | 33 // This base class contains common operations for granting permissions. |
38 // It offers the following functionality: | 34 // It offers the following functionality: |
39 // - Creates a permission request when needed. | 35 // - Creates a permission request when needed. |
40 // - If accepted/denied the permission is saved in content settings for | 36 // - If accepted/denied the permission is saved in content settings for |
41 // future uses (for the domain that requested it). | 37 // future uses (for the domain that requested it). |
42 // - If dismissed the permission is not saved but it's considered denied for | 38 // - If dismissed the permission is not saved but it's considered denied for |
43 // this one request | 39 // this one request |
44 // - In any case the BrowserPermissionCallback is executed once a decision | 40 // - In any case the BrowserPermissionCallback is executed once a decision |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 ContentSetting content_setting); | 153 ContentSetting content_setting); |
158 | 154 |
159 // Whether the permission should be restricted to secure origins. | 155 // Whether the permission should be restricted to secure origins. |
160 virtual bool IsRestrictedToSecureOrigins() const = 0; | 156 virtual bool IsRestrictedToSecureOrigins() const = 0; |
161 | 157 |
162 content::PermissionType permission_type() const { return permission_type_; } | 158 content::PermissionType permission_type() const { return permission_type_; } |
163 ContentSettingsType content_settings_type() const { | 159 ContentSettingsType content_settings_type() const { |
164 return content_settings_type_; | 160 return content_settings_type_; |
165 } | 161 } |
166 | 162 |
167 // Virtual to allow for mocking in tests. | |
168 virtual scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> | |
169 GetSafeBrowsingDatabaseManager(); | |
170 | |
171 private: | 163 private: |
172 friend class PermissionContextBaseTests; | 164 friend class PermissionContextBaseTests; |
173 | 165 |
174 // Called when a request is no longer used so it can be cleaned up. | 166 // Called when a request is no longer used so it can be cleaned up. |
175 void CleanUpRequest(const PermissionRequestID& id); | 167 void CleanUpRequest(const PermissionRequestID& id); |
176 | 168 |
177 // Called when the requesting origin and permission have been checked by Safe | 169 // Called when the requesting origin and permission have been checked by Safe |
178 // Browsing. |permission_blocked| determines whether to auto-block the | 170 // Browsing. |permission_blocked| determines whether to auto-block the |
179 // permission request without prompting the user for a decision. | 171 // permission request without prompting the user for a decision. |
180 void ContinueRequestPermission(content::WebContents* web_contents, | 172 void ContinueRequestPermission(content::WebContents* web_contents, |
181 const PermissionRequestID& id, | 173 const PermissionRequestID& id, |
182 const GURL& requesting_origin, | 174 const GURL& requesting_origin, |
183 const GURL& embedding_origin, | 175 const GURL& embedding_origin, |
184 bool user_gesture, | 176 bool user_gesture, |
185 const BrowserPermissionCallback& callback, | 177 const BrowserPermissionCallback& callback, |
186 bool permission_blocked); | 178 bool permission_blocked); |
187 | 179 |
188 void SetSafeBrowsingDatabaseManagerAndTimeoutForTest( | |
189 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | |
190 int timeout); | |
191 | |
192 Profile* profile_; | 180 Profile* profile_; |
193 const content::PermissionType permission_type_; | 181 const content::PermissionType permission_type_; |
194 const ContentSettingsType content_settings_type_; | 182 const ContentSettingsType content_settings_type_; |
195 int safe_browsing_timeout_; | |
196 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager_; | |
197 #if defined(OS_ANDROID) | 183 #if defined(OS_ANDROID) |
198 std::unique_ptr<PermissionQueueController> permission_queue_controller_; | 184 std::unique_ptr<PermissionQueueController> permission_queue_controller_; |
199 #endif | 185 #endif |
200 std::unordered_map<std::string, std::unique_ptr<PermissionRequest>> | 186 std::unordered_map<std::string, std::unique_ptr<PermissionRequest>> |
201 pending_requests_; | 187 pending_requests_; |
202 | 188 |
203 // Must be the last member, to ensure that it will be | 189 // Must be the last member, to ensure that it will be |
204 // destroyed first, which will invalidate weak pointers | 190 // destroyed first, which will invalidate weak pointers |
205 base::WeakPtrFactory<PermissionContextBase> weak_factory_; | 191 base::WeakPtrFactory<PermissionContextBase> weak_factory_; |
206 }; | 192 }; |
207 | 193 |
208 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ | 194 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ |
OLD | NEW |