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.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/singleton.h" | |
| 12 #include "components/keyed_service/content/browser_context_keyed_service_factory .h" | |
| 13 #include "components/keyed_service/core/keyed_service.h" | |
| 11 #include "content/public/browser/permission_type.h" | 14 #include "content/public/browser/permission_type.h" |
| 12 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 13 | 16 |
| 14 class GURL; | 17 class GURL; |
| 15 class Profile; | 18 class Profile; |
| 16 | 19 |
| 17 namespace content { | 20 namespace content { |
| 18 class WebContents; | 21 class WebContents; |
| 19 } | 22 } |
| 20 | 23 |
| 21 namespace safe_browsing { | 24 namespace safe_browsing { |
| 22 class SafeBrowsingDatabaseManager; | 25 class SafeBrowsingDatabaseManager; |
| 23 } | 26 } |
| 24 | 27 |
| 25 namespace base { | 28 namespace base { |
| 26 class Time; | 29 class Time; |
| 27 } | 30 } |
| 28 | 31 |
| 29 class HostContentSettingsMap; | 32 class HostContentSettingsMap; |
| 30 | 33 |
| 31 // The PermissionDecisionAutoBlocker decides whether or not a given origin | 34 // The PermissionDecisionAutoBlocker decides whether or not a given origin |
| 32 // should be automatically blocked from requesting a permission. When an origin | 35 // 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 | 36 // 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 | 37 // 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 | 38 // 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 | 39 // 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 | 40 // 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. | 41 // has a number of prior dismissals greater than a threshold. |
| 39 class PermissionDecisionAutoBlocker { | 42 class PermissionDecisionAutoBlocker : public KeyedService { |
| 40 public: | 43 public: |
| 41 // Removes any recorded counts for urls which match |filter| under |profile|. | 44 explicit PermissionDecisionAutoBlocker(Profile* profile); |
| 42 static void RemoveCountsByUrl(Profile* profile, | 45 ~PermissionDecisionAutoBlocker() override; |
|
raymes
2017/01/23 06:14:23
You should be able to make the constructor/destrut
meredithl
2017/01/24 01:20:46
Done.
| |
| 43 base::Callback<bool(const GURL& url)> filter); | 46 |
| 47 static PermissionDecisionAutoBlocker* GetForProfile(Profile* profile); | |
| 48 | |
| 49 // Removes any recorded counts for urls which match |filter|. | |
| 50 void RemoveCountsByUrl(base::Callback<bool(const GURL& url)> filter); | |
| 44 | 51 |
| 45 // Returns the current number of dismisses recorded for |permission| type at | 52 // Returns the current number of dismisses recorded for |permission| type at |
| 46 // |url|. | 53 // |url|. |
| 47 static int GetDismissCount(const GURL& url, | 54 int GetDismissCount(const GURL& url, content::PermissionType permission); |
| 48 content::PermissionType permission, | |
| 49 Profile* profile); | |
| 50 | 55 |
| 51 // Returns the current number of ignores recorded for |permission| | 56 // Returns the current number of ignores recorded for |permission| |
| 52 // type at |url|. | 57 // type at |url|. |
| 53 static int GetIgnoreCount(const GURL& url, | 58 int GetIgnoreCount(const GURL& url, content::PermissionType permission); |
| 54 content::PermissionType permission, | |
| 55 Profile* profile); | |
| 56 | 59 |
| 57 // Records that a dismissal of a prompt for |permission| was made. If the | 60 // Records that a dismissal of a prompt for |permission| was made. If the |
| 58 // total number of dismissals exceeds a threshhold and | 61 // total number of dismissals exceeds a threshhold and |
| 59 // features::kBlockPromptsIfDismissedOften is enabled it will place |url| | 62 // features::kBlockPromptsIfDismissedOften is enabled it will place |url| |
| 60 // under embargo for |permission|. | 63 // under embargo for |permission|. |
| 61 static bool RecordDismissAndEmbargo(const GURL& url, | 64 bool RecordDismissAndEmbargo(const GURL& url, |
| 62 content::PermissionType permission, | 65 content::PermissionType permission, |
| 63 Profile* profile, | 66 base::Time current_time); |
| 64 base::Time current_time); | |
| 65 | 67 |
| 66 // Records that an ignore of a prompt for |permission| was made. | 68 // Records that an ignore of a prompt for |permission| was made. |
| 67 static int RecordIgnore(const GURL& url, | 69 int RecordIgnore(const GURL& url, content::PermissionType permission); |
| 68 content::PermissionType permission, | |
| 69 Profile* profile); | |
| 70 | |
| 71 // Records that a dismissal of a prompt for |permission| was made, and returns | |
| 72 // true if this dismissal should be considered a block. False otherwise. | |
| 73 // TODO(meredithl): Remove in favour of embargoing on repeated dismissals. | |
| 74 static bool ShouldChangeDismissalToBlock(const GURL& url, | |
| 75 content::PermissionType permission, | |
| 76 Profile* profile); | |
| 77 | 70 |
| 78 // Updates the threshold to start blocking prompts from the field trial. | 71 // Updates the threshold to start blocking prompts from the field trial. |
| 79 static void UpdateFromVariations(); | 72 static void UpdateFromVariations(); |
| 80 | 73 |
| 81 // Checks if |request_origin| is under embargo for |permission|. Internally, | 74 // Checks if |request_origin| is under embargo for |permission|. Internally, |
| 82 // this will make a call to IsUnderEmbargo to check the content setting first, | 75 // 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 | 76 // but may also make a call to Safe Browsing to check their API blacklist, |
|
raymes
2017/01/23 06:14:23
their->the
meredithl
2017/01/24 01:20:46
Done.
| |
| 84 // blacklisted for |permission|, which is performed asynchronously. | 77 // which is performed asynchronously. |
| 85 static void UpdateEmbargoedStatus( | 78 void UpdateEmbargoedStatus(content::PermissionType permission, |
| 86 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | 79 const GURL& request_origin, |
| 87 content::PermissionType permission, | 80 content::WebContents* web_contents, |
| 88 const GURL& request_origin, | 81 base::Time current_time, |
| 89 content::WebContents* web_contents, | 82 base::Callback<void(bool)> callback); |
| 90 int timeout, | |
| 91 Profile* profile, | |
| 92 base::Time current_time, | |
| 93 base::Callback<void(bool)> callback); | |
| 94 | 83 |
| 95 // Checks the status of the content setting to determine if |request_origin| | 84 // Checks the status of the content setting to determine if |request_origin| |
| 96 // is under embargo for |permission|. This checks both embargo for Permissions | 85 // is under embargo for |permission|. This checks both embargo for Permissions |
| 97 // Blacklisting and repeated dismissals. | 86 // Blacklisting and repeated dismissals. |
| 98 static bool IsUnderEmbargo(content::PermissionType permission, | 87 bool IsUnderEmbargo(content::PermissionType permission, |
| 99 Profile* profile, | 88 const GURL& request_origin, |
| 100 const GURL& request_origin, | 89 base::Time current_time); |
| 101 base::Time current_time); | 90 |
| 91 void SetSafeBrowsingDatabaseManagerAndTimeoutForTesting( | |
| 92 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | |
| 93 int timeout); | |
|
raymes
2017/01/23 06:14:23
nit: this should be private
meredithl
2017/01/24 01:20:46
Done.
| |
| 102 | 94 |
| 103 private: | 95 private: |
| 104 friend class PermissionContextBaseTests; | 96 friend class PermissionContextBaseTests; |
| 105 friend class PermissionDecisionAutoBlockerUnitTest; | 97 friend class PermissionDecisionAutoBlockerUnitTest; |
| 106 | 98 |
| 107 static void CheckSafeBrowsingResult(content::PermissionType permission, | 99 static void CheckSafeBrowsingResult(content::PermissionType permission, |
| 108 Profile* profile, | 100 Profile* profile, |
| 109 const GURL& request_origin, | 101 const GURL& request_origin, |
| 110 base::Time current_time, | 102 base::Time current_time, |
| 111 base::Callback<void(bool)> callback, | 103 base::Callback<void(bool)> callback, |
| 112 bool should_be_embargoed); | 104 bool should_be_embargoed); |
| 113 | 105 |
| 114 static void PlaceUnderEmbargo(content::PermissionType permission, | 106 static void PlaceUnderEmbargo(content::PermissionType permission, |
| 115 const GURL& request_origin, | 107 const GURL& request_origin, |
| 116 HostContentSettingsMap* map, | 108 HostContentSettingsMap* map, |
| 117 base::Time current_time, | 109 base::Time current_time, |
| 118 const char* key); | 110 const char* key); |
|
raymes
2017/01/23 06:14:23
nit: convert these to member functions or just sta
meredithl
2017/01/24 01:20:46
CheckSafeBrowsingResult is static to avoid having
raymes
2017/01/24 03:31:08
I don't think it is actually safer from a lifetime
meredithl
2017/01/24 04:52:25
Done.
| |
| 119 | 111 |
| 120 // Keys used for storing count data in a website setting. | 112 // Keys used for storing count data in a website setting. |
| 121 static const char kPromptDismissCountKey[]; | 113 static const char kPromptDismissCountKey[]; |
| 122 static const char kPromptIgnoreCountKey[]; | 114 static const char kPromptIgnoreCountKey[]; |
| 123 static const char kPermissionDismissalEmbargoKey[]; | 115 static const char kPermissionDismissalEmbargoKey[]; |
| 124 static const char kPermissionBlacklistEmbargoKey[]; | 116 static const char kPermissionBlacklistEmbargoKey[]; |
| 125 | 117 |
| 118 Profile* profile_; | |
| 119 int safe_browsing_timeout_; | |
|
raymes
2017/01/23 06:14:23
nit: please document the units that the timeout is
meredithl
2017/01/24 01:20:46
Done.
| |
| 120 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager_; | |
| 121 | |
| 126 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionDecisionAutoBlocker); | 122 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionDecisionAutoBlocker); |
| 127 }; | 123 }; |
| 128 | 124 |
| 125 class PermissionDecisionAutoBlockerFactory | |
| 126 : public BrowserContextKeyedServiceFactory { | |
| 127 public: | |
| 128 static PermissionDecisionAutoBlocker* GetForProfile(Profile* profile); | |
| 129 static PermissionDecisionAutoBlockerFactory* GetInstance(); | |
| 130 | |
| 131 private: | |
| 132 friend struct base::DefaultSingletonTraits< | |
| 133 PermissionDecisionAutoBlockerFactory>; | |
| 134 | |
| 135 PermissionDecisionAutoBlockerFactory(); | |
| 136 ~PermissionDecisionAutoBlockerFactory() override; | |
| 137 | |
| 138 // BrowserContextKeyedServiceFactory | |
| 139 KeyedService* BuildServiceInstanceFor( | |
| 140 content::BrowserContext* context) const override; | |
| 141 | |
| 142 content::BrowserContext* GetBrowserContextToUse( | |
| 143 content::BrowserContext* context) const override; | |
| 144 }; | |
| 129 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ | 145 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ |
| OLD | NEW |