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 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" | 5 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/feature_list.h" | 9 #include "base/feature_list.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 HostContentSettingsMapFactory::GetForProfile(profile); | 106 HostContentSettingsMapFactory::GetForProfile(profile); |
107 std::unique_ptr<base::DictionaryValue> dict = GetOriginDict(map, url); | 107 std::unique_ptr<base::DictionaryValue> dict = GetOriginDict(map, url); |
108 base::DictionaryValue* permission_dict = GetOrCreatePermissionDict( | 108 base::DictionaryValue* permission_dict = GetOrCreatePermissionDict( |
109 dict.get(), PermissionUtil::GetPermissionString(permission)); | 109 dict.get(), PermissionUtil::GetPermissionString(permission)); |
110 | 110 |
111 int current_count = 0; | 111 int current_count = 0; |
112 permission_dict->GetInteger(key, ¤t_count); | 112 permission_dict->GetInteger(key, ¤t_count); |
113 return current_count; | 113 return current_count; |
114 } | 114 } |
115 | 115 |
116 bool PreviouslyEmbargoed(Profile* profile, | |
dominickn
2017/01/27 06:05:47
Call this WasPreviouslyEmbargoed. Add a comment sa
meredithl
2017/01/29 23:48:29
Done.
| |
117 const GURL& url, | |
118 content::PermissionType permission, | |
119 const char* key) { | |
120 HostContentSettingsMap* map = | |
121 HostContentSettingsMapFactory::GetForProfile(profile); | |
122 std::unique_ptr<base::DictionaryValue> dict = GetOriginDict(map, url); | |
123 base::DictionaryValue* permission_dict = GetOrCreatePermissionDict( | |
124 dict.get(), PermissionUtil::GetPermissionString(permission)); | |
125 return permission_dict->HasKey(key); | |
126 } | |
127 | |
116 } // namespace | 128 } // namespace |
117 | 129 |
118 // PermissionDecisionAutoBlocker::Factory -------------------------------------- | 130 // PermissionDecisionAutoBlocker::Factory -------------------------------------- |
119 | 131 |
120 // static | 132 // static |
121 PermissionDecisionAutoBlocker* | 133 PermissionDecisionAutoBlocker* |
122 PermissionDecisionAutoBlocker::Factory::GetForProfile(Profile* profile) { | 134 PermissionDecisionAutoBlocker::Factory::GetForProfile(Profile* profile) { |
123 return static_cast<PermissionDecisionAutoBlocker*>( | 135 return static_cast<PermissionDecisionAutoBlocker*>( |
124 GetInstance()->GetServiceForBrowserContext(profile, true)); | 136 GetInstance()->GetServiceForBrowserContext(profile, true)); |
125 } | 137 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 } | 232 } |
221 | 233 |
222 bool PermissionDecisionAutoBlocker::RecordDismissAndEmbargo( | 234 bool PermissionDecisionAutoBlocker::RecordDismissAndEmbargo( |
223 const GURL& url, | 235 const GURL& url, |
224 content::PermissionType permission) { | 236 content::PermissionType permission) { |
225 int current_dismissal_count = RecordActionInWebsiteSettings( | 237 int current_dismissal_count = RecordActionInWebsiteSettings( |
226 url, permission, kPromptDismissCountKey, profile_); | 238 url, permission, kPromptDismissCountKey, profile_); |
227 | 239 |
228 if (base::FeatureList::IsEnabled(features::kBlockPromptsIfDismissedOften) && | 240 if (base::FeatureList::IsEnabled(features::kBlockPromptsIfDismissedOften) && |
229 current_dismissal_count >= g_prompt_dismissals_before_block) { | 241 current_dismissal_count >= g_prompt_dismissals_before_block) { |
242 if (PreviouslyEmbargoed(profile_, url, permission, | |
243 kPermissionDismissalEmbargoKey)) { | |
244 PermissionUmaUtil::RecordRepeatedEmbargo( | |
245 PermissionEmbargoReason::REPEATED_DISMISSALS); | |
246 } | |
247 | |
230 PlaceUnderEmbargo(permission, url, kPermissionDismissalEmbargoKey); | 248 PlaceUnderEmbargo(permission, url, kPermissionDismissalEmbargoKey); |
249 PermissionUmaUtil::RecordPermissionEmbargoReason( | |
250 PermissionEmbargoReason::REPEATED_DISMISSALS); | |
231 return true; | 251 return true; |
232 } | 252 } |
253 | |
dominickn
2017/01/27 06:05:47
Nit: probably don't need this extra newline
meredithl
2017/01/29 23:48:29
Done.
| |
233 return false; | 254 return false; |
234 } | 255 } |
235 | 256 |
236 int PermissionDecisionAutoBlocker::RecordIgnore( | 257 int PermissionDecisionAutoBlocker::RecordIgnore( |
237 const GURL& url, | 258 const GURL& url, |
238 content::PermissionType permission) { | 259 content::PermissionType permission) { |
239 return RecordActionInWebsiteSettings(url, permission, kPromptIgnoreCountKey, | 260 return RecordActionInWebsiteSettings(url, permission, kPromptIgnoreCountKey, |
240 profile_); | 261 profile_); |
241 } | 262 } |
242 | 263 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 return is_under_dismiss_embargo || is_under_blacklist_embargo; | 355 return is_under_dismiss_embargo || is_under_blacklist_embargo; |
335 } | 356 } |
336 | 357 |
337 // static | 358 // static |
338 void PermissionDecisionAutoBlocker::CheckSafeBrowsingResult( | 359 void PermissionDecisionAutoBlocker::CheckSafeBrowsingResult( |
339 content::PermissionType permission, | 360 content::PermissionType permission, |
340 const GURL& request_origin, | 361 const GURL& request_origin, |
341 base::Callback<void(bool)> callback, | 362 base::Callback<void(bool)> callback, |
342 bool should_be_embargoed) { | 363 bool should_be_embargoed) { |
343 if (should_be_embargoed) { | 364 if (should_be_embargoed) { |
344 // Requesting site is blacklisted for this permission, update the content | 365 if (PreviouslyEmbargoed(profile_, request_origin, permission, |
345 // setting to place it under embargo. | 366 kPermissionBlacklistEmbargoKey)) { |
367 PermissionUmaUtil::RecordRepeatedEmbargo( | |
368 PermissionEmbargoReason::PERMISSIONS_BLACKLISTING); | |
369 } | |
370 | |
346 PlaceUnderEmbargo(permission, request_origin, | 371 PlaceUnderEmbargo(permission, request_origin, |
347 kPermissionBlacklistEmbargoKey); | 372 kPermissionBlacklistEmbargoKey); |
373 PermissionUmaUtil::RecordPermissionEmbargoReason( | |
374 PermissionEmbargoReason::PERMISSIONS_BLACKLISTING); | |
375 } else { | |
376 PermissionUmaUtil::RecordPermissionEmbargoReason( | |
dominickn
2017/01/27 06:05:47
Will this double count since you're calling Record
meredithl
2017/01/29 23:48:29
Hmm, I believe so. Imo that should have been picke
dominickn
2017/01/30 00:06:20
You don't actually have any test which checks the
meredithl
2017/01/30 00:34:33
I do a check of the histograms in Permission Conte
dominickn
2017/01/30 00:42:36
Right, but those tests don't have a safe browsing
meredithl
2017/01/30 02:04:47
Okay, I've added an extra test in PDAB to check th
| |
377 PermissionEmbargoReason::NOT_EMBARGOED); | |
348 } | 378 } |
349 callback.Run(should_be_embargoed /* permission blocked */); | 379 |
380 callback.Run(should_be_embargoed); | |
350 } | 381 } |
351 | 382 |
352 // static | 383 // static |
353 void PermissionDecisionAutoBlocker::PlaceUnderEmbargo( | 384 void PermissionDecisionAutoBlocker::PlaceUnderEmbargo( |
354 content::PermissionType permission, | 385 content::PermissionType permission, |
355 const GURL& request_origin, | 386 const GURL& request_origin, |
356 const char* key) { | 387 const char* key) { |
357 HostContentSettingsMap* map = | 388 HostContentSettingsMap* map = |
358 HostContentSettingsMapFactory::GetForProfile(profile_); | 389 HostContentSettingsMapFactory::GetForProfile(profile_); |
359 std::unique_ptr<base::DictionaryValue> dict = | 390 std::unique_ptr<base::DictionaryValue> dict = |
(...skipping 11 matching lines...) Expand all Loading... | |
371 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | 402 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, |
372 int timeout) { | 403 int timeout) { |
373 db_manager_ = db_manager; | 404 db_manager_ = db_manager; |
374 safe_browsing_timeout_ = timeout; | 405 safe_browsing_timeout_ = timeout; |
375 } | 406 } |
376 | 407 |
377 void PermissionDecisionAutoBlocker::SetClockForTesting( | 408 void PermissionDecisionAutoBlocker::SetClockForTesting( |
378 std::unique_ptr<base::Clock> clock) { | 409 std::unique_ptr<base::Clock> clock) { |
379 clock_ = std::move(clock); | 410 clock_ = std::move(clock); |
380 } | 411 } |
OLD | NEW |