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 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
(...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 | |
31 using BrowserPermissionCallback = base::Callback<void(ContentSetting)>; | 35 using BrowserPermissionCallback = base::Callback<void(ContentSetting)>; |
32 | 36 |
33 // This base class contains common operations for granting permissions. | 37 // This base class contains common operations for granting permissions. |
34 // It offers the following functionality: | 38 // It offers the following functionality: |
35 // - Creates a permission request when needed. | 39 // - Creates a permission request when needed. |
36 // - If accepted/denied the permission is saved in content settings for | 40 // - If accepted/denied the permission is saved in content settings for |
37 // future uses (for the domain that requested it). | 41 // future uses (for the domain that requested it). |
38 // - If dismissed the permission is not saved but it's considered denied for | 42 // - If dismissed the permission is not saved but it's considered denied for |
39 // this one request | 43 // this one request |
40 // - In any case the BrowserPermissionCallback is executed once a decision | 44 // - In any case the BrowserPermissionCallback is executed once a decision |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 | 77 |
74 // The renderer is requesting permission to push messages. | 78 // The renderer is requesting permission to push messages. |
75 // When the answer to a permission request has been determined, |callback| | 79 // When the answer to a permission request has been determined, |callback| |
76 // should be called with the result. | 80 // should be called with the result. |
77 virtual void RequestPermission(content::WebContents* web_contents, | 81 virtual void RequestPermission(content::WebContents* web_contents, |
78 const PermissionRequestID& id, | 82 const PermissionRequestID& id, |
79 const GURL& requesting_frame, | 83 const GURL& requesting_frame, |
80 bool user_gesture, | 84 bool user_gesture, |
81 const BrowserPermissionCallback& callback); | 85 const BrowserPermissionCallback& callback); |
82 | 86 |
83 // Returns whether the permission has been granted, denied... | 87 // Returns whether the permission has been granted, denied etc. This method |
88 // does not take into account the Safe Browsing blacklist, as it is executed | |
89 // synchronously. | |
84 ContentSetting GetPermissionStatus(const GURL& requesting_origin, | 90 ContentSetting GetPermissionStatus(const GURL& requesting_origin, |
85 const GURL& embedding_origin) const; | 91 const GURL& embedding_origin) const; |
86 | 92 |
87 // Resets the permission to its default value. | 93 // Resets the permission to its default value. |
88 virtual void ResetPermission(const GURL& requesting_origin, | 94 virtual void ResetPermission(const GURL& requesting_origin, |
89 const GURL& embedding_origin); | 95 const GURL& embedding_origin); |
90 | 96 |
91 // Withdraw an existing permission request, no op if the permission request | 97 // Withdraw an existing permission request, no op if the permission request |
92 // was already cancelled by some other means. | 98 // was already cancelled by some other means. |
93 virtual void CancelPermissionRequest(content::WebContents* web_contents, | 99 virtual void CancelPermissionRequest(content::WebContents* web_contents, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 ContentSettingsType content_settings_type() const { | 163 ContentSettingsType content_settings_type() const { |
158 return content_settings_type_; | 164 return content_settings_type_; |
159 } | 165 } |
160 | 166 |
161 private: | 167 private: |
162 friend class PermissionContextBaseTests; | 168 friend class PermissionContextBaseTests; |
163 | 169 |
164 // Called when a request is no longer used so it can be cleaned up. | 170 // Called when a request is no longer used so it can be cleaned up. |
165 void CleanUpRequest(const PermissionRequestID& id); | 171 void CleanUpRequest(const PermissionRequestID& id); |
166 | 172 |
173 // Called when the requesting origin and permission have been checked by Safe | |
174 // Browsing. |permission_blocked| determines whether to auto-block the | |
175 // permission request without prompting the user for a decision. | |
176 void ContinueRequestPermission(content::WebContents* web_contents, | |
177 const PermissionRequestID& id, | |
178 const GURL& requesting_origin, | |
179 const GURL& embedding_origin, | |
180 bool user_gesture, | |
181 const BrowserPermissionCallback& callback, | |
182 bool permission_blocked); | |
183 | |
184 void SetSafeBrowsingDatabaseManagerForTests( | |
raymes
2016/12/20 23:58:57
nit: ForTest (without this s) is a bit more common
meredithl
2016/12/29 06:23:35
Done.
| |
185 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager); | |
186 | |
187 void SetTimeoutForSafeBrowsingClient(int timeout); | |
raymes
2016/12/20 23:58:57
nit: it should be made clear that this is just for
meredithl
2016/12/29 06:23:35
Done.
| |
188 | |
167 Profile* profile_; | 189 Profile* profile_; |
168 const content::PermissionType permission_type_; | 190 const content::PermissionType permission_type_; |
169 const ContentSettingsType content_settings_type_; | 191 const ContentSettingsType content_settings_type_; |
192 int safe_browsing_timeout_; | |
193 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager_; | |
170 #if defined(OS_ANDROID) | 194 #if defined(OS_ANDROID) |
171 std::unique_ptr<PermissionQueueController> permission_queue_controller_; | 195 std::unique_ptr<PermissionQueueController> permission_queue_controller_; |
172 #endif | 196 #endif |
173 base::ScopedPtrHashMap<std::string, std::unique_ptr<PermissionRequest>> | 197 base::ScopedPtrHashMap<std::string, std::unique_ptr<PermissionRequest>> |
174 pending_requests_; | 198 pending_requests_; |
175 | 199 |
176 // Must be the last member, to ensure that it will be | 200 // Must be the last member, to ensure that it will be |
177 // destroyed first, which will invalidate weak pointers | 201 // destroyed first, which will invalidate weak pointers |
178 base::WeakPtrFactory<PermissionContextBase> weak_factory_; | 202 base::WeakPtrFactory<PermissionContextBase> weak_factory_; |
179 }; | 203 }; |
180 | 204 |
181 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ | 205 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ |
OLD | NEW |