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 is only |
| 37 // embargoed if it appears on Safe Browsing's API blacklist. |
| 38 // TODO(meredithl): Incorporate embargoing into blocking on repeated dismissals. |
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, |
(...skipping 17 matching lines...) Expand all Loading... |
43 | 66 |
44 // Records that a dismissal of a prompt for |permission| was made, and returns | 67 // 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. | 68 // true if this dismissal should be considered a block. False otherwise. |
46 static bool ShouldChangeDismissalToBlock(const GURL& url, | 69 static bool ShouldChangeDismissalToBlock(const GURL& url, |
47 content::PermissionType permission, | 70 content::PermissionType permission, |
48 Profile* profile); | 71 Profile* profile); |
49 | 72 |
50 // Updates the threshold to start blocking prompts from the field trial. | 73 // Updates the threshold to start blocking prompts from the field trial. |
51 static void UpdateFromVariations(); | 74 static void UpdateFromVariations(); |
52 | 75 |
| 76 // Checks if the |request_origin| is under embargo for the requested |
| 77 // |permission|. Internally, this will make a call to IsUnderEmbargo to check |
| 78 // the content setting first, but may also make a call to Safe Browsing to |
| 79 // check if the |request_origin| is blacklisted for |permission|, which is |
| 80 // performed asynchronously. |
| 81 static void ShouldAutomaticallyBlock( |
| 82 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, |
| 83 content::PermissionType permission, |
| 84 const GURL& request_origin, |
| 85 content::WebContents* web_contents, |
| 86 int timeout, |
| 87 Profile* profile, |
| 88 base::Time current_time, |
| 89 base::Callback<void(bool)> callback); |
| 90 |
| 91 // Checks the status of the content setting to determine if |request_origin| |
| 92 // is under embargo for the |permission|. This check is done synchronously. |
| 93 static bool IsUnderEmbargo(content::PermissionType permission, |
| 94 Profile* profile, |
| 95 const GURL& request_origin, |
| 96 base::Time current_time); |
| 97 |
53 private: | 98 private: |
54 friend class PermissionContextBaseTests; | 99 friend class PermissionContextBaseTests; |
| 100 friend class PermissionDecisionAutoBlockerUnitTest; |
| 101 |
| 102 // Get the result of the Safe Browsing check, if |should_be_embargoed| is true |
| 103 // then |request_origin| will be placed under embargo for that |permission|. |
| 104 static void CheckSafeBrowsingResult(content::PermissionType permission, |
| 105 Profile* profile, |
| 106 const GURL& request_origin, |
| 107 base::Time current_time, |
| 108 base::Callback<void(bool)> callback, |
| 109 bool should_be_embargoed); |
| 110 |
| 111 // Sets the embargo status of the |request_origin| inside the |permission| |
| 112 // dictionary. |
| 113 static void PlaceUnderEmbargo(content::PermissionType permission, |
| 114 const GURL& request_origin, |
| 115 HostContentSettingsMap* map, |
| 116 base::Time current_time); |
55 | 117 |
56 // Keys used for storing count data in a website setting. | 118 // Keys used for storing count data in a website setting. |
57 static const char kPromptDismissCountKey[]; | 119 static const char kPromptDismissCountKey[]; |
58 static const char kPromptIgnoreCountKey[]; | 120 static const char kPromptIgnoreCountKey[]; |
| 121 static const char kPermissionOriginEmbargoKey[]; |
59 | 122 |
60 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionDecisionAutoBlocker); | 123 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionDecisionAutoBlocker); |
61 }; | 124 }; |
62 | 125 |
63 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ | 126 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ |
OLD | NEW |