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_forward.h" | 8 #include "base/callback.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" |
10 #include "content/public/browser/permission_type.h" | 11 #include "content/public/browser/permission_type.h" |
11 #include "url/gurl.h" | 12 #include "url/gurl.h" |
12 | 13 |
13 class GURL; | 14 class GURL; |
14 class Profile; | 15 class Profile; |
15 | 16 |
| 17 namespace content { |
| 18 class WebContents; |
| 19 } |
| 20 |
| 21 namespace safe_browsing { |
| 22 class SafeBrowsingDatabaseManager; |
| 23 } |
| 24 |
| 25 namespace base { |
| 26 class Time; |
| 27 } |
| 28 |
| 29 class HostContentSettingsMap; |
| 30 |
| 31 // The PermissionDecisionAutoBlocker decides whether or not a given origin |
| 32 // should be automatically blocked from requesting a permission. When an origin |
| 33 // is blocked, it is placed under an "embargo". Until the embargo expires, any |
| 34 // requests made by the origin are automatically blocked. Once the embargo is |
| 35 // lifted, the origin will be permitted to request a permission again, which may |
| 36 // result in it being placed under embargo again. Currently, an origin can be |
| 37 // placed under embargo if it appears on Safe Browsing's API blacklist, or if it |
| 38 // has a number of prior dismissals greater than a threshold. |
16 class PermissionDecisionAutoBlocker { | 39 class PermissionDecisionAutoBlocker { |
17 public: | 40 public: |
18 // Removes any recorded counts for urls which match |filter| under |profile|. | 41 // Removes any recorded counts for urls which match |filter| under |profile|. |
19 static void RemoveCountsByUrl(Profile* profile, | 42 static void RemoveCountsByUrl(Profile* profile, |
20 base::Callback<bool(const GURL& url)> filter); | 43 base::Callback<bool(const GURL& url)> filter); |
21 | 44 |
22 // Returns the current number of dismisses recorded for |permission| type at | 45 // Returns the current number of dismisses recorded for |permission| type at |
23 // |url|. | 46 // |url|. |
24 static int GetDismissCount(const GURL& url, | 47 static int GetDismissCount(const GURL& url, |
25 content::PermissionType permission, | 48 content::PermissionType permission, |
26 Profile* profile); | 49 Profile* profile); |
27 | 50 |
28 // Returns the current number of ignores recorded for |permission| | 51 // Returns the current number of ignores recorded for |permission| |
29 // type at |url|. | 52 // type at |url|. |
30 static int GetIgnoreCount(const GURL& url, | 53 static int GetIgnoreCount(const GURL& url, |
31 content::PermissionType permission, | 54 content::PermissionType permission, |
32 Profile* profile); | 55 Profile* profile); |
33 | 56 |
34 // Records that a dismissal of a prompt for |permission| was made. | 57 // Records that a dismissal of a prompt for |permission| was made. If the |
35 static int RecordDismiss(const GURL& url, | 58 // total number of dismissals exceeds a threshhold and |
36 content::PermissionType permission, | 59 // features::kBlockPromptsIfDismissedOften is enabled it will place |url| |
37 Profile* profile); | 60 // under embargo for |permission|. |
| 61 static bool RecordDismissAndEmbargo(const GURL& url, |
| 62 content::PermissionType permission, |
| 63 Profile* profile, |
| 64 base::Time current_time); |
38 | 65 |
39 // Records that an ignore of a prompt for |permission| was made. | 66 // Records that an ignore of a prompt for |permission| was made. |
40 static int RecordIgnore(const GURL& url, | 67 static int RecordIgnore(const GURL& url, |
41 content::PermissionType permission, | 68 content::PermissionType permission, |
42 Profile* profile); | 69 Profile* profile); |
43 | 70 |
44 // Records that a dismissal of a prompt for |permission| was made, and returns | 71 // 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. | 72 // true if this dismissal should be considered a block. False otherwise. |
| 73 // TODO(meredithl): Remove in favour of embargoing on repeated dismissals. |
46 static bool ShouldChangeDismissalToBlock(const GURL& url, | 74 static bool ShouldChangeDismissalToBlock(const GURL& url, |
47 content::PermissionType permission, | 75 content::PermissionType permission, |
48 Profile* profile); | 76 Profile* profile); |
49 | 77 |
50 // Updates the threshold to start blocking prompts from the field trial. | 78 // Updates the threshold to start blocking prompts from the field trial. |
51 static void UpdateFromVariations(); | 79 static void UpdateFromVariations(); |
52 | 80 |
| 81 // Checks if |request_origin| is under embargo for |permission|. Internally, |
| 82 // this will make a call to IsUnderEmbargo to check the content setting first, |
| 83 // but may also make a call to Safe Browsing to check if |request_origin| is |
| 84 // blacklisted for |permission|, which is performed asynchronously. |
| 85 static void UpdateEmbargoedStatus( |
| 86 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, |
| 87 content::PermissionType permission, |
| 88 const GURL& request_origin, |
| 89 content::WebContents* web_contents, |
| 90 int timeout, |
| 91 Profile* profile, |
| 92 base::Time current_time, |
| 93 base::Callback<void(bool)> callback); |
| 94 |
| 95 // Checks the status of the content setting to determine if |request_origin| |
| 96 // is under embargo for |permission|. This checks both embargo for Permissions |
| 97 // Blacklisting and repeated dismissals. |
| 98 static bool IsUnderEmbargo(content::PermissionType permission, |
| 99 Profile* profile, |
| 100 const GURL& request_origin, |
| 101 base::Time current_time); |
| 102 |
53 private: | 103 private: |
54 friend class PermissionContextBaseTests; | 104 friend class PermissionContextBaseTests; |
| 105 friend class PermissionDecisionAutoBlockerUnitTest; |
| 106 |
| 107 static void CheckSafeBrowsingResult(content::PermissionType permission, |
| 108 Profile* profile, |
| 109 const GURL& request_origin, |
| 110 base::Time current_time, |
| 111 base::Callback<void(bool)> callback, |
| 112 bool should_be_embargoed); |
| 113 |
| 114 static void PlaceUnderEmbargo(content::PermissionType permission, |
| 115 const GURL& request_origin, |
| 116 HostContentSettingsMap* map, |
| 117 base::Time current_time, |
| 118 const char* key); |
55 | 119 |
56 // Keys used for storing count data in a website setting. | 120 // Keys used for storing count data in a website setting. |
57 static const char kPromptDismissCountKey[]; | 121 static const char kPromptDismissCountKey[]; |
58 static const char kPromptIgnoreCountKey[]; | 122 static const char kPromptIgnoreCountKey[]; |
| 123 static const char kPermissionDismissalEmbargoKey[]; |
| 124 static const char kPermissionBlacklistEmbargoKey[]; |
59 | 125 |
60 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionDecisionAutoBlocker); | 126 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionDecisionAutoBlocker); |
61 }; | 127 }; |
62 | 128 |
63 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ | 129 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ |
OLD | NEW |