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 the threshold specified either | |
39 // through variations or |g_prompt_dismissals_before_block|. | |
raymes
2017/01/18 23:35:00
nit: I would leave out the |g_prompt_dismissals_be
meredithl
2017/01/19 02:11:43
Done.
| |
16 class PermissionDecisionAutoBlocker { | 40 class PermissionDecisionAutoBlocker { |
17 public: | 41 public: |
18 // Removes any recorded counts for urls which match |filter| under |profile|. | 42 // Removes any recorded counts for urls which match |filter| under |profile|. |
19 static void RemoveCountsByUrl(Profile* profile, | 43 static void RemoveCountsByUrl(Profile* profile, |
20 base::Callback<bool(const GURL& url)> filter); | 44 base::Callback<bool(const GURL& url)> filter); |
21 | 45 |
22 // Returns the current number of dismisses recorded for |permission| type at | 46 // Returns the current number of dismisses recorded for |permission| type at |
23 // |url|. | 47 // |url|. |
24 static int GetDismissCount(const GURL& url, | 48 static int GetDismissCount(const GURL& url, |
25 content::PermissionType permission, | 49 content::PermissionType permission, |
26 Profile* profile); | 50 Profile* profile); |
27 | 51 |
28 // Returns the current number of ignores recorded for |permission| | 52 // Returns the current number of ignores recorded for |permission| |
29 // type at |url|. | 53 // type at |url|. |
30 static int GetIgnoreCount(const GURL& url, | 54 static int GetIgnoreCount(const GURL& url, |
31 content::PermissionType permission, | 55 content::PermissionType permission, |
32 Profile* profile); | 56 Profile* profile); |
33 | 57 |
34 // Records that a dismissal of a prompt for |permission| was made. | 58 // Records that a dismissal of a prompt for |permission| was made. If the |
35 static int RecordDismiss(const GURL& url, | 59 // total number of dismissals exceeds |g_prompt_dismissals_before_block| and |
raymes
2017/01/18 23:35:00
nit: same here
meredithl
2017/01/19 02:11:43
Done.
| |
36 content::PermissionType permission, | 60 // features::kBlockPromptsIfDismissedOften is enabled it will place |url| |
37 Profile* profile); | 61 // under embargo for |permission|. |
62 static bool RecordDismissAndEmbargo(const GURL& url, | |
63 content::PermissionType permission, | |
64 Profile* profile, | |
65 base::Time current_time); | |
38 | 66 |
39 // Records that an ignore of a prompt for |permission| was made. | 67 // Records that an ignore of a prompt for |permission| was made. |
40 static int RecordIgnore(const GURL& url, | 68 static int RecordIgnore(const GURL& url, |
41 content::PermissionType permission, | 69 content::PermissionType permission, |
42 Profile* profile); | 70 Profile* profile); |
43 | 71 |
44 // Records that a dismissal of a prompt for |permission| was made, and returns | 72 // 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. | 73 // true if this dismissal should be considered a block. False otherwise. |
74 // TODO(meredithl): Remove in favour of embargoing on repeated dismissals. | |
46 static bool ShouldChangeDismissalToBlock(const GURL& url, | 75 static bool ShouldChangeDismissalToBlock(const GURL& url, |
47 content::PermissionType permission, | 76 content::PermissionType permission, |
48 Profile* profile); | 77 Profile* profile); |
49 | 78 |
50 // Updates the threshold to start blocking prompts from the field trial. | 79 // Updates the threshold to start blocking prompts from the field trial. |
51 static void UpdateFromVariations(); | 80 static void UpdateFromVariations(); |
52 | 81 |
82 // Checks if |request_origin| is under embargo for |permission|. Internally, | |
83 // this will make a call to IsUnderEmbargo to check the content setting first, | |
84 // but may also make a call to Safe Browsing to check if |request_origin| is | |
85 // blacklisted for |permission|, which is performed asynchronously. | |
86 static void UpdateEmbargoedStatus( | |
87 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | |
88 content::PermissionType permission, | |
89 const GURL& request_origin, | |
90 content::WebContents* web_contents, | |
91 int timeout, | |
92 Profile* profile, | |
93 base::Time current_time, | |
94 base::Callback<void(bool)> callback); | |
95 | |
96 // Checks the status of the content setting to determine if |request_origin| | |
97 // is under embargo for |permission|. This checks both embargo for Permissions | |
98 // Blacklisting and repeated dismissals. | |
99 static bool IsUnderEmbargo(content::PermissionType permission, | |
100 Profile* profile, | |
101 const GURL& request_origin, | |
102 base::Time current_time); | |
103 | |
53 private: | 104 private: |
54 friend class PermissionContextBaseTests; | 105 friend class PermissionContextBaseTests; |
106 friend class PermissionDecisionAutoBlockerUnitTest; | |
107 | |
108 static void CheckSafeBrowsingResult(content::PermissionType permission, | |
109 Profile* profile, | |
110 const GURL& request_origin, | |
111 base::Time current_time, | |
112 base::Callback<void(bool)> callback, | |
113 bool should_be_embargoed); | |
114 | |
115 // Sets the embargo status of |request_origin| inside |permission| dictionary | |
116 // for testing. | |
117 static void PlaceUnderEmbargoForTest(content::PermissionType permission, | |
118 const GURL& request_origin, | |
119 HostContentSettingsMap* map, | |
120 base::Time current_time); | |
121 | |
122 // Gets the embargo status of the |request_origin| inside the |permission| | |
123 // dictionary for testing. | |
124 static bool GetEmbargoStatusForTest(content::PermissionType permission, | |
125 const GURL& request_origin, | |
126 HostContentSettingsMap* map); | |
55 | 127 |
56 // Keys used for storing count data in a website setting. | 128 // Keys used for storing count data in a website setting. |
57 static const char kPromptDismissCountKey[]; | 129 static const char kPromptDismissCountKey[]; |
58 static const char kPromptIgnoreCountKey[]; | 130 static const char kPromptIgnoreCountKey[]; |
131 static const char kPermissionDismissalEmbargoKey[]; | |
132 static const char kPermissionBlacklistEmbargoKey[]; | |
59 | 133 |
60 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionDecisionAutoBlocker); | 134 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionDecisionAutoBlocker); |
61 }; | 135 }; |
62 | 136 |
63 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ | 137 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ |
OLD | NEW |