Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(395)

Side by Side Diff: chrome/browser/permissions/permission_decision_auto_blocker.h

Issue 2622983003: Implement embargo in PermissionDecisionAutoBlocker (Closed)
Patch Set: Nits + review Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.
raymes 2017/01/12 00:53:15 Hmm, this comment only talks about the embargo par
meredithl 2017/01/12 05:59:19 I have that as a TODO just below, which is to impl
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
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,
raymes 2017/01/12 00:53:15 If we make this a keyed service we can avoid passi
meredithl 2017/01/12 05:59:19 Everyone agrees this sounds like an excellent idea
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::Callback<void(bool)> callback,
108 bool should_be_embargoed);
109
110 // Sets the embargo status of the |request_origin| inside the |permission|
111 // dictionary.
112 static void PlaceUnderEmbargo(content::PermissionType permission,
113 const GURL& request_origin,
114 HostContentSettingsMap* map,
115 base::Time current_time);
55 116
56 // Keys used for storing count data in a website setting. 117 // Keys used for storing count data in a website setting.
57 static const char kPromptDismissCountKey[]; 118 static const char kPromptDismissCountKey[];
58 static const char kPromptIgnoreCountKey[]; 119 static const char kPromptIgnoreCountKey[];
120 static const char kPermissionOriginEmbargoKey[];
59 121
60 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionDecisionAutoBlocker); 122 DISALLOW_IMPLICIT_CONSTRUCTORS(PermissionDecisionAutoBlocker);
61 }; 123 };
62 124
63 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_ 125 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DECISION_AUTO_BLOCKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698