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" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 // BrowserContextKeyedServiceFactory | 51 // BrowserContextKeyedServiceFactory |
| 52 KeyedService* BuildServiceInstanceFor( | 52 KeyedService* BuildServiceInstanceFor( |
| 53 content::BrowserContext* context) const override; | 53 content::BrowserContext* context) const override; |
| 54 | 54 |
| 55 content::BrowserContext* GetBrowserContextToUse( | 55 content::BrowserContext* GetBrowserContextToUse( |
| 56 content::BrowserContext* context) const override; | 56 content::BrowserContext* context) const override; |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 static PermissionDecisionAutoBlocker* GetForProfile(Profile* profile); | 59 static PermissionDecisionAutoBlocker* GetForProfile(Profile* profile); |
| 60 | 60 |
| 61 // Removes any recorded counts for urls which match |filter|. | 61 // Updates the threshold to start blocking prompts from the field trial. |
| 62 void RemoveCountsByUrl(base::Callback<bool(const GURL& url)> filter); | 62 static void UpdateFromVariations(); |
| 63 | |
| 64 // Makes an asynchronous call to Safe Browsing to check the API blacklist. | |
|
raymes
2017/02/23 06:09:30
nit: you may also want to note that the result wil
dominickn
2017/02/23 06:14:19
Done.
| |
| 65 void CheckSafeBrowsingBlacklist(content::WebContents* web_contents, | |
| 66 const GURL& request_origin, | |
| 67 ContentSettingsType permission, | |
| 68 base::Callback<void(bool)> callback); | |
| 69 | |
| 70 // Checks the status of the content setting to determine if |request_origin| | |
| 71 // is under embargo for |permission|. This checks both embargo for Permissions | |
| 72 // Blacklisting and repeated dismissals. | |
| 73 PermissionResult GetEmbargoResult(const GURL& request_origin, | |
| 74 ContentSettingsType permission); | |
| 63 | 75 |
| 64 // Returns the current number of dismisses recorded for |permission| type at | 76 // Returns the current number of dismisses recorded for |permission| type at |
| 65 // |url|. | 77 // |url|. |
| 66 int GetDismissCount(const GURL& url, ContentSettingsType permission); | 78 int GetDismissCount(const GURL& url, ContentSettingsType permission); |
| 67 | 79 |
| 68 // Returns the current number of ignores recorded for |permission| | 80 // Returns the current number of ignores recorded for |permission| |
| 69 // type at |url|. | 81 // type at |url|. |
| 70 int GetIgnoreCount(const GURL& url, ContentSettingsType permission); | 82 int GetIgnoreCount(const GURL& url, ContentSettingsType permission); |
| 71 | 83 |
| 72 // Records that a dismissal of a prompt for |permission| was made. If the | 84 // Records that a dismissal of a prompt for |permission| was made. If the |
| 73 // total number of dismissals exceeds a threshhold and | 85 // total number of dismissals exceeds a threshhold and |
| 74 // features::kBlockPromptsIfDismissedOften is enabled it will place |url| | 86 // features::kBlockPromptsIfDismissedOften is enabled it will place |url| |
| 75 // under embargo for |permission|. | 87 // under embargo for |permission|. |
| 76 bool RecordDismissAndEmbargo(const GURL& url, ContentSettingsType permission); | 88 bool RecordDismissAndEmbargo(const GURL& url, ContentSettingsType permission); |
| 77 | 89 |
| 78 // Records that an ignore of a prompt for |permission| was made. | 90 // Records that an ignore of a prompt for |permission| was made. |
| 79 int RecordIgnore(const GURL& url, ContentSettingsType permission); | 91 int RecordIgnore(const GURL& url, ContentSettingsType permission); |
| 80 | 92 |
| 81 // Updates the threshold to start blocking prompts from the field trial. | 93 // Removes any recorded counts for urls which match |filter|. |
| 82 static void UpdateFromVariations(); | 94 void RemoveCountsByUrl(base::Callback<bool(const GURL& url)> filter); |
| 83 | |
| 84 // Updates whether |request_origin| should be under embargo for |permission|. | |
| 85 // Makes an asynchronous call to Safe Browsing to check the API blacklist. | |
| 86 void UpdateEmbargoedStatus(ContentSettingsType permission, | |
| 87 const GURL& request_origin, | |
| 88 content::WebContents* web_contents, | |
| 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 |permission|. This checks both embargo for Permissions | |
| 93 // Blacklisting and repeated dismissals. | |
| 94 PermissionResult GetEmbargoResult(ContentSettingsType permission, | |
| 95 const GURL& request_origin); | |
| 96 | 95 |
| 97 private: | 96 private: |
| 98 friend class PermissionContextBaseTests; | 97 friend class PermissionContextBaseTests; |
| 99 friend class PermissionDecisionAutoBlockerUnitTest; | 98 friend class PermissionDecisionAutoBlockerUnitTest; |
| 100 | 99 |
| 101 explicit PermissionDecisionAutoBlocker(Profile* profile); | 100 explicit PermissionDecisionAutoBlocker(Profile* profile); |
| 102 ~PermissionDecisionAutoBlocker() override; | 101 ~PermissionDecisionAutoBlocker() override; |
| 103 | 102 |
| 104 // Get the result of the Safe Browsing check, if |should_be_embargoed| is true | 103 // Get the result of the Safe Browsing check, if |should_be_embargoed| is true |
| 105 // then |request_origin| will be placed under embargo for that |permission|. | 104 // then |request_origin| will be placed under embargo for that |permission|. |
| 106 void CheckSafeBrowsingResult(ContentSettingsType permission, | 105 void CheckSafeBrowsingResult(const GURL& request_origin, |
| 107 const GURL& request_origin, | 106 ContentSettingsType permission, |
| 108 base::Callback<void(bool)> callback, | 107 base::Callback<void(bool)> callback, |
| 109 bool should_be_embargoed); | 108 bool should_be_embargoed); |
| 110 | 109 |
| 111 void PlaceUnderEmbargo(ContentSettingsType permission, | 110 void PlaceUnderEmbargo(const GURL& request_origin, |
| 112 const GURL& request_origin, | 111 ContentSettingsType permission, |
| 113 const char* key); | 112 const char* key); |
| 114 | 113 |
| 115 void SetSafeBrowsingDatabaseManagerAndTimeoutForTesting( | 114 void SetSafeBrowsingDatabaseManagerAndTimeoutForTesting( |
| 116 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | 115 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, |
| 117 int timeout); | 116 int timeout); |
| 118 | 117 |
| 119 void SetClockForTesting(std::unique_ptr<base::Clock> clock); | 118 void SetClockForTesting(std::unique_ptr<base::Clock> clock); |
| 120 | 119 |
| 121 // Keys used for storing count data in a website setting. | 120 // Keys used for storing count data in a website setting. |
| 122 static const char kPromptDismissCountKey[]; | 121 static const char kPromptDismissCountKey[]; |
| 123 static const char kPromptIgnoreCountKey[]; | 122 static const char kPromptIgnoreCountKey[]; |
| 124 static const char kPermissionDismissalEmbargoKey[]; | 123 static const char kPermissionDismissalEmbargoKey[]; |
| 125 static const char kPermissionBlacklistEmbargoKey[]; | 124 static const char kPermissionBlacklistEmbargoKey[]; |
| 126 | 125 |
| 127 Profile* profile_; | 126 Profile* profile_; |
| 128 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager_; | 127 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager_; |
| 129 | 128 |
| 130 // Timeout in ms. | 129 // Timeout in ms. |
| 131 int safe_browsing_timeout_; | 130 int safe_browsing_timeout_; |
| 132 | 131 |
| 133 std::unique_ptr<base::Clock> clock_; | 132 std::unique_ptr<base::Clock> clock_; |
| 134 | 133 |
| 135 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionDecisionAutoBlocker); | 134 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionDecisionAutoBlocker); |
| 136 }; | 135 }; |
| 137 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ | 136 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ |
| OLD | NEW |