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/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 14 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
15 #include "chrome/browser/permissions/permission_blacklist_client.h" | 15 #include "chrome/browser/permissions/permission_blacklist_client.h" |
16 #include "chrome/browser/permissions/permission_util.h" | |
17 #include "chrome/browser/profiles/incognito_helpers.h" | 16 #include "chrome/browser/profiles/incognito_helpers.h" |
18 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 18 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
20 #include "chrome/common/chrome_features.h" | 19 #include "chrome/common/chrome_features.h" |
21 #include "components/content_settings/core/browser/host_content_settings_map.h" | 20 #include "components/content_settings/core/browser/host_content_settings_map.h" |
22 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 21 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
23 #include "components/safe_browsing_db/database_manager.h" | 22 #include "components/safe_browsing_db/database_manager.h" |
24 #include "components/variations/variations_associated_data.h" | 23 #include "components/variations/variations_associated_data.h" |
25 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
26 #include "url/gurl.h" | 25 #include "url/gurl.h" |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 dismissal_embargo_days > 0) { | 262 dismissal_embargo_days > 0) { |
264 g_dismissal_embargo_days = dismissal_embargo_days; | 263 g_dismissal_embargo_days = dismissal_embargo_days; |
265 } | 264 } |
266 } | 265 } |
267 | 266 |
268 void PermissionDecisionAutoBlocker::UpdateEmbargoedStatus( | 267 void PermissionDecisionAutoBlocker::UpdateEmbargoedStatus( |
269 ContentSettingsType permission, | 268 ContentSettingsType permission, |
270 const GURL& request_origin, | 269 const GURL& request_origin, |
271 content::WebContents* web_contents, | 270 content::WebContents* web_contents, |
272 base::Callback<void(bool)> callback) { | 271 base::Callback<void(bool)> callback) { |
273 DCHECK(!IsUnderEmbargo(permission, request_origin)); | 272 DCHECK(GetEmbargoResult(permission, request_origin).content_setting == |
273 CONTENT_SETTING_ASK); | |
raymes
2017/02/22 23:13:50
nit: DCHECK_EQ(CONTENT_SETTING_ASK, ...)
dominickn
2017/02/22 23:38:54
Done.
| |
274 | 274 |
275 if (base::FeatureList::IsEnabled(features::kPermissionsBlacklist) && | 275 if (base::FeatureList::IsEnabled(features::kPermissionsBlacklist) && |
276 db_manager_) { | 276 db_manager_) { |
277 // The CheckSafeBrowsingResult callback won't be called if the profile is | 277 // The CheckSafeBrowsingResult callback won't be called if the profile is |
278 // destroyed before a result is received. In that case this object will have | 278 // destroyed before a result is received. In that case this object will have |
279 // been destroyed by that point. | 279 // been destroyed by that point. |
280 PermissionBlacklistClient::CheckSafeBrowsingBlacklist( | 280 PermissionBlacklistClient::CheckSafeBrowsingBlacklist( |
281 db_manager_, permission, request_origin, web_contents, | 281 db_manager_, permission, request_origin, web_contents, |
282 safe_browsing_timeout_, | 282 safe_browsing_timeout_, |
283 base::Bind(&PermissionDecisionAutoBlocker::CheckSafeBrowsingResult, | 283 base::Bind(&PermissionDecisionAutoBlocker::CheckSafeBrowsingResult, |
284 base::Unretained(this), permission, request_origin, | 284 base::Unretained(this), permission, request_origin, |
285 callback)); | 285 callback)); |
286 return; | 286 return; |
287 } | 287 } |
288 | 288 |
289 callback.Run(false /* permission blocked */); | 289 callback.Run(false /* permission blocked */); |
290 } | 290 } |
291 | 291 |
292 bool PermissionDecisionAutoBlocker::IsUnderEmbargo( | 292 PermissionResult PermissionDecisionAutoBlocker::GetEmbargoResult( |
293 ContentSettingsType permission, | 293 ContentSettingsType permission, |
294 const GURL& request_origin) { | 294 const GURL& request_origin) { |
295 HostContentSettingsMap* map = | 295 HostContentSettingsMap* map = |
296 HostContentSettingsMapFactory::GetForProfile(profile_); | 296 HostContentSettingsMapFactory::GetForProfile(profile_); |
297 std::unique_ptr<base::DictionaryValue> dict = | 297 std::unique_ptr<base::DictionaryValue> dict = |
298 GetOriginDict(map, request_origin); | 298 GetOriginDict(map, request_origin); |
299 base::DictionaryValue* permission_dict = GetOrCreatePermissionDict( | 299 base::DictionaryValue* permission_dict = GetOrCreatePermissionDict( |
300 dict.get(), PermissionUtil::GetPermissionString(permission)); | 300 dict.get(), PermissionUtil::GetPermissionString(permission)); |
301 double embargo_date = -1; | 301 double embargo_date = -1; |
302 bool is_under_dismiss_embargo = false; | 302 |
303 bool is_under_blacklist_embargo = false; | 303 PermissionStatusSource reason = PermissionStatusSource::UNSPECIFIED; |
304 ContentSetting setting = CONTENT_SETTING_ASK; | |
304 base::Time current_time = clock_->Now(); | 305 base::Time current_time = clock_->Now(); |
305 if (base::FeatureList::IsEnabled(features::kPermissionsBlacklist) && | 306 if (base::FeatureList::IsEnabled(features::kPermissionsBlacklist) && |
306 permission_dict->GetDouble(kPermissionBlacklistEmbargoKey, | 307 permission_dict->GetDouble(kPermissionBlacklistEmbargoKey, |
307 &embargo_date)) { | 308 &embargo_date)) { |
308 if (current_time < | 309 if (current_time < |
309 base::Time::FromInternalValue(embargo_date) + | 310 base::Time::FromInternalValue(embargo_date) + |
310 base::TimeDelta::FromDays(g_blacklist_embargo_days)) { | 311 base::TimeDelta::FromDays(g_blacklist_embargo_days)) { |
311 is_under_blacklist_embargo = true; | 312 reason = PermissionStatusSource::SAFE_BROWSING_BLACKLIST; |
313 setting = CONTENT_SETTING_BLOCK; | |
raymes
2017/02/22 23:13:50
Can we just
return PermissionResult(CONTENT_SETTI
dominickn
2017/02/22 23:38:54
Done.
| |
312 } | 314 } |
313 } | 315 } |
314 | 316 |
315 if (base::FeatureList::IsEnabled(features::kBlockPromptsIfDismissedOften) && | 317 if (base::FeatureList::IsEnabled(features::kBlockPromptsIfDismissedOften) && |
316 permission_dict->GetDouble(kPermissionDismissalEmbargoKey, | 318 permission_dict->GetDouble(kPermissionDismissalEmbargoKey, |
317 &embargo_date)) { | 319 &embargo_date)) { |
318 if (current_time < | 320 if (current_time < |
319 base::Time::FromInternalValue(embargo_date) + | 321 base::Time::FromInternalValue(embargo_date) + |
320 base::TimeDelta::FromDays(g_dismissal_embargo_days)) { | 322 base::TimeDelta::FromDays(g_dismissal_embargo_days)) { |
321 is_under_dismiss_embargo = true; | 323 reason = PermissionStatusSource::MULTIPLE_DISMISSALS; |
324 setting = CONTENT_SETTING_BLOCK; | |
322 } | 325 } |
323 } | 326 } |
324 | 327 |
325 // If either embargo is still in effect, return true. | 328 return PermissionResult(setting, reason); |
326 return is_under_dismiss_embargo || is_under_blacklist_embargo; | |
327 } | 329 } |
328 | 330 |
329 void PermissionDecisionAutoBlocker::CheckSafeBrowsingResult( | 331 void PermissionDecisionAutoBlocker::CheckSafeBrowsingResult( |
330 ContentSettingsType permission, | 332 ContentSettingsType permission, |
331 const GURL& request_origin, | 333 const GURL& request_origin, |
332 base::Callback<void(bool)> callback, | 334 base::Callback<void(bool)> callback, |
333 bool should_be_embargoed) { | 335 bool should_be_embargoed) { |
334 if (should_be_embargoed) { | 336 if (should_be_embargoed) { |
335 // Requesting site is blacklisted for this permission, update the content | 337 // Requesting site is blacklisted for this permission, update the content |
336 // setting to place it under embargo. | 338 // setting to place it under embargo. |
(...skipping 24 matching lines...) Expand all Loading... | |
361 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | 363 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, |
362 int timeout) { | 364 int timeout) { |
363 db_manager_ = db_manager; | 365 db_manager_ = db_manager; |
364 safe_browsing_timeout_ = timeout; | 366 safe_browsing_timeout_ = timeout; |
365 } | 367 } |
366 | 368 |
367 void PermissionDecisionAutoBlocker::SetClockForTesting( | 369 void PermissionDecisionAutoBlocker::SetClockForTesting( |
368 std::unique_ptr<base::Clock> clock) { | 370 std::unique_ptr<base::Clock> clock) { |
369 clock_ = std::move(clock); | 371 clock_ = std::move(clock); |
370 } | 372 } |
OLD | NEW |