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_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. | |
|
raymes
2017/01/18 03:15:20
I think the TODO is less of a TODO now? Could we j
meredithl
2017/01/18 08:28:16
Done.
| |
| 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 UpdateEmbargoedStatus( | |
| 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. | |
|
raymes
2017/01/18 03:15:20
nit: the last sentence is probably unnecessary as
meredithl
2017/01/18 08:28:16
Done.
| |
| 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 // Sets the embargo status of the |request_origin| inside the |permission| | |
| 103 // dictionary for testing. | |
| 104 static void PlaceUnderEmbargoForTest(content::PermissionType permission, | |
| 105 const GURL& request_origin, | |
| 106 HostContentSettingsMap* map, | |
| 107 base::Time current_time); | |
| 108 | |
| 109 // Gets the embargo status of the |request_origin| inside the |permission| | |
| 110 // dictionary for testing. | |
| 111 static bool GetEmbargoStatusForTest(content::PermissionType permission, | |
| 112 const GURL& request_origin, | |
| 113 HostContentSettingsMap* map); | |
| 55 | 114 |
| 56 // Keys used for storing count data in a website setting. | 115 // Keys used for storing count data in a website setting. |
| 57 static const char kPromptDismissCountKey[]; | 116 static const char kPromptDismissCountKey[]; |
| 58 static const char kPromptIgnoreCountKey[]; | 117 static const char kPromptIgnoreCountKey[]; |
| 118 static const char kPermissionDismissalEmbargoKey[]; | |
| 119 static const char kPermissionBlacklistEmbargoKey[]; | |
| 59 | 120 |
| 60 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionDecisionAutoBlocker); | 121 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionDecisionAutoBlocker); |
| 61 }; | 122 }; |
| 62 | 123 |
| 63 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ | 124 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ |
| OLD | NEW |