Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_DECISION_AUTO_BLOCKER_H_ | 5 #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ |
| 6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ | 6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | |
| 8 #include "base/callback_forward.h" | 9 #include "base/callback_forward.h" |
|
dominickn
2017/01/11 07:52:13
Remove callback_forward.h
meredithl
2017/01/11 23:22:28
Done.
| |
| 9 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | |
| 10 #include "content/public/browser/permission_type.h" | 12 #include "content/public/browser/permission_type.h" |
| 11 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 12 | 14 |
| 13 class GURL; | 15 class GURL; |
| 14 class Profile; | 16 class Profile; |
| 15 | 17 |
| 18 namespace content { | |
| 19 class WebContents; | |
| 20 } | |
| 21 | |
| 22 namespace safe_browsing { | |
| 23 class SafeBrowsingDatabaseManager; | |
| 24 } | |
| 25 | |
| 26 namespace base { | |
| 27 class Time; | |
| 28 } | |
| 29 | |
| 30 class HostContentSettingsMap; | |
| 31 | |
|
dominickn
2017/01/11 07:52:13
Add a class comment here explaining what embargo i
meredithl
2017/01/11 23:22:28
Yep! I've also left a TODO explaining that this wi
| |
| 16 class PermissionDecisionAutoBlocker { | 32 class PermissionDecisionAutoBlocker { |
| 17 public: | 33 public: |
| 18 // Removes any recorded counts for urls which match |filter| under |profile|. | 34 // Removes any recorded counts for urls which match |filter| under |profile|. |
| 19 static void RemoveCountsByUrl(Profile* profile, | 35 static void RemoveCountsByUrl(Profile* profile, |
| 20 base::Callback<bool(const GURL& url)> filter); | 36 base::Callback<bool(const GURL& url)> filter); |
| 21 | 37 |
| 22 // Returns the current number of dismisses recorded for |permission| type at | 38 // Returns the current number of dismisses recorded for |permission| type at |
| 23 // |url|. | 39 // |url|. |
| 24 static int GetDismissCount(const GURL& url, | 40 static int GetDismissCount(const GURL& url, |
| 25 content::PermissionType permission, | 41 content::PermissionType permission, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 43 | 59 |
| 44 // Records that a dismissal of a prompt for |permission| was made, and returns | 60 // Records that a dismissal of a prompt for |permission| was made, and returns |
| 45 // true if this dismissal should be considered a block. False otherwise. | 61 // true if this dismissal should be considered a block. False otherwise. |
| 46 static bool ShouldChangeDismissalToBlock(const GURL& url, | 62 static bool ShouldChangeDismissalToBlock(const GURL& url, |
| 47 content::PermissionType permission, | 63 content::PermissionType permission, |
| 48 Profile* profile); | 64 Profile* profile); |
| 49 | 65 |
| 50 // Updates the threshold to start blocking prompts from the field trial. | 66 // Updates the threshold to start blocking prompts from the field trial. |
| 51 static void UpdateFromVariations(); | 67 static void UpdateFromVariations(); |
| 52 | 68 |
| 69 // Checks if the |request_origin| is under embargo for the requested | |
| 70 // |permission|. Internally, this will make a call to IsUnderEmbargo to check | |
| 71 // the content setting first, but may also make a call to Safe Browsing to | |
| 72 // check if the |request_origin| is blacklisted for |permission|, which is | |
| 73 // performed asynchronously. | |
| 74 static void ShouldAutomaticallyBlock( | |
| 75 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | |
| 76 content::PermissionType permission, | |
| 77 const GURL& request_origin, | |
| 78 content::WebContents* web_contents, | |
| 79 int timeout, | |
| 80 Profile* profile, | |
| 81 base::Time current_time, | |
| 82 base::Callback<void(bool)> callback); | |
| 83 | |
| 84 // Checks the status of the content setting to determine if |request_origin| | |
| 85 // is under embargo for the |permission|. This check is done synchronously. | |
| 86 static bool IsUnderEmbargo(content::PermissionType permission, | |
| 87 Profile* profile, | |
| 88 const GURL& request_origin, | |
| 89 base::Time current_time); | |
| 90 | |
| 53 private: | 91 private: |
| 54 friend class PermissionContextBaseTests; | 92 friend class PermissionContextBaseTests; |
| 93 friend class PermissionDecisionAutoBlockerUnitTest; | |
| 94 | |
| 95 // Get the result of the Safe Browsing check, if |should_be_embargoed| then | |
|
dominickn
2017/01/11 07:52:13
"if |should_be_embargoed| is true then".
meredithl
2017/01/11 23:22:28
Done.
| |
| 96 // |request_origin| will be placed under embargo. | |
| 97 static void CheckSafeBrowsingResult(content::PermissionType permission, | |
| 98 Profile* profile, | |
| 99 const GURL& request_origin, | |
| 100 base::Callback<void(bool)> callback, | |
| 101 bool should_be_embargoed); | |
| 102 | |
| 103 // Sets the embargo status of the |request_origin| inside the |permission| | |
| 104 // dictionary. | |
| 105 static void PlaceUnderEmbargo(content::PermissionType permission, | |
| 106 const GURL& request_origin, | |
| 107 HostContentSettingsMap* map, | |
| 108 base::Time current_time); | |
| 55 | 109 |
| 56 // Keys used for storing count data in a website setting. | 110 // Keys used for storing count data in a website setting. |
| 57 static const char kPromptDismissCountKey[]; | 111 static const char kPromptDismissCountKey[]; |
| 58 static const char kPromptIgnoreCountKey[]; | 112 static const char kPromptIgnoreCountKey[]; |
| 113 static const char kPermissionOriginEmbargoKey[]; | |
| 59 | 114 |
| 60 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionDecisionAutoBlocker); | 115 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionDecisionAutoBlocker); |
| 61 }; | 116 }; |
| 62 | 117 |
| 63 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ | 118 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ |
| OLD | NEW |