| 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_EQ(CONTENT_SETTING_ASK, |
| 273 GetEmbargoResult(permission, request_origin).content_setting); |
| 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; | |
| 304 base::Time current_time = clock_->Now(); | 303 base::Time current_time = clock_->Now(); |
| 305 if (base::FeatureList::IsEnabled(features::kPermissionsBlacklist) && | 304 if (base::FeatureList::IsEnabled(features::kPermissionsBlacklist) && |
| 306 permission_dict->GetDouble(kPermissionBlacklistEmbargoKey, | 305 permission_dict->GetDouble(kPermissionBlacklistEmbargoKey, |
| 307 &embargo_date)) { | 306 &embargo_date)) { |
| 308 if (current_time < | 307 if (current_time < |
| 309 base::Time::FromInternalValue(embargo_date) + | 308 base::Time::FromInternalValue(embargo_date) + |
| 310 base::TimeDelta::FromDays(g_blacklist_embargo_days)) { | 309 base::TimeDelta::FromDays(g_blacklist_embargo_days)) { |
| 311 is_under_blacklist_embargo = true; | 310 return PermissionResult(CONTENT_SETTING_BLOCK, |
| 311 PermissionStatusSource::SAFE_BROWSING_BLACKLIST); |
| 312 } | 312 } |
| 313 } | 313 } |
| 314 | 314 |
| 315 if (base::FeatureList::IsEnabled(features::kBlockPromptsIfDismissedOften) && | 315 if (base::FeatureList::IsEnabled(features::kBlockPromptsIfDismissedOften) && |
| 316 permission_dict->GetDouble(kPermissionDismissalEmbargoKey, | 316 permission_dict->GetDouble(kPermissionDismissalEmbargoKey, |
| 317 &embargo_date)) { | 317 &embargo_date)) { |
| 318 if (current_time < | 318 if (current_time < |
| 319 base::Time::FromInternalValue(embargo_date) + | 319 base::Time::FromInternalValue(embargo_date) + |
| 320 base::TimeDelta::FromDays(g_dismissal_embargo_days)) { | 320 base::TimeDelta::FromDays(g_dismissal_embargo_days)) { |
| 321 is_under_dismiss_embargo = true; | 321 return PermissionResult(CONTENT_SETTING_BLOCK, |
| 322 PermissionStatusSource::MULTIPLE_DISMISSALS); |
| 322 } | 323 } |
| 323 } | 324 } |
| 324 | 325 |
| 325 // If either embargo is still in effect, return true. | 326 return PermissionResult(CONTENT_SETTING_ASK, |
| 326 return is_under_dismiss_embargo || is_under_blacklist_embargo; | 327 PermissionStatusSource::UNSPECIFIED); |
| 327 } | 328 } |
| 328 | 329 |
| 329 void PermissionDecisionAutoBlocker::CheckSafeBrowsingResult( | 330 void PermissionDecisionAutoBlocker::CheckSafeBrowsingResult( |
| 330 ContentSettingsType permission, | 331 ContentSettingsType permission, |
| 331 const GURL& request_origin, | 332 const GURL& request_origin, |
| 332 base::Callback<void(bool)> callback, | 333 base::Callback<void(bool)> callback, |
| 333 bool should_be_embargoed) { | 334 bool should_be_embargoed) { |
| 334 if (should_be_embargoed) { | 335 if (should_be_embargoed) { |
| 335 // Requesting site is blacklisted for this permission, update the content | 336 // Requesting site is blacklisted for this permission, update the content |
| 336 // setting to place it under embargo. | 337 // setting to place it under embargo. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 361 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | 362 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, |
| 362 int timeout) { | 363 int timeout) { |
| 363 db_manager_ = db_manager; | 364 db_manager_ = db_manager; |
| 364 safe_browsing_timeout_ = timeout; | 365 safe_browsing_timeout_ = timeout; |
| 365 } | 366 } |
| 366 | 367 |
| 367 void PermissionDecisionAutoBlocker::SetClockForTesting( | 368 void PermissionDecisionAutoBlocker::SetClockForTesting( |
| 368 std::unique_ptr<base::Clock> clock) { | 369 std::unique_ptr<base::Clock> clock) { |
| 369 clock_ = std::move(clock); | 370 clock_ = std::move(clock); |
| 370 } | 371 } |
| OLD | NEW |