Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/safe_browsing/ui_manager.h" | 5 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 } | 85 } |
| 86 | 86 |
| 87 Profile* profile = | 87 Profile* profile = |
| 88 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 88 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 89 hit_report.extended_reporting_level = | 89 hit_report.extended_reporting_level = |
| 90 profile ? GetExtendedReportingLevel(*profile->GetPrefs()) | 90 profile ? GetExtendedReportingLevel(*profile->GetPrefs()) |
| 91 : SBER_LEVEL_OFF; | 91 : SBER_LEVEL_OFF; |
| 92 hit_report.is_metrics_reporting_active = | 92 hit_report.is_metrics_reporting_active = |
| 93 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); | 93 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); |
| 94 | 94 |
| 95 MaybeReportSafeBrowsingHit(hit_report); | 95 MaybeReportSafeBrowsingHit(hit_report, web_contents); |
| 96 | 96 |
| 97 for (Observer& observer : observer_list_) | 97 for (Observer& observer : observer_list_) |
| 98 observer.OnSafeBrowsingHit(resource); | 98 observer.OnSafeBrowsingHit(resource); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void SafeBrowsingUIManager::ShowBlockingPageForResource( | 101 void SafeBrowsingUIManager::ShowBlockingPageForResource( |
| 102 const UnsafeResource& resource) { | 102 const UnsafeResource& resource) { |
| 103 SafeBrowsingBlockingPage::ShowBlockingPage(this, resource); | 103 SafeBrowsingBlockingPage::ShowBlockingPage(this, resource); |
| 104 } | 104 } |
| 105 | 105 |
| 106 // A safebrowsing hit is sent after a blocking page for malware/phishing | 106 // A safebrowsing hit is sent after a blocking page for malware/phishing |
| 107 // or after the warning dialog for download urls, only for | 107 // or after the warning dialog for download urls, only for |
| 108 // extended-reporting users. | 108 // extended-reporting users. |
| 109 void SafeBrowsingUIManager::MaybeReportSafeBrowsingHit( | 109 void SafeBrowsingUIManager::MaybeReportSafeBrowsingHit( |
| 110 const HitReport& hit_report) { | 110 const HitReport& hit_report, |
| 111 WebContents* web_contents) { | |
| 111 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 112 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 112 | 113 |
| 113 // Send report if user opted-in extended reporting. | 114 // Send report if user opted-in to extended reporting and is not in |
| 114 if (hit_report.extended_reporting_level != SBER_LEVEL_OFF) { | 115 // incognito mode. |
| 116 if (ShouldSendHitReport(hit_report, web_contents)) { | |
| 115 BrowserThread::PostTask( | 117 BrowserThread::PostTask( |
| 116 BrowserThread::IO, FROM_HERE, | 118 BrowserThread::IO, FROM_HERE, |
| 117 base::BindOnce(&SafeBrowsingUIManager::ReportSafeBrowsingHitOnIOThread, | 119 base::BindOnce(&SafeBrowsingUIManager::ReportSafeBrowsingHitOnIOThread, |
| 118 this, hit_report)); | 120 this, hit_report)); |
| 119 } | 121 } |
| 120 } | 122 } |
| 121 | 123 |
| 124 // Static | |
| 125 bool SafeBrowsingUIManager::ShouldSendHitReport(const HitReport& hit_report, | |
| 126 WebContents* web_contents) { | |
| 127 if (hit_report.extended_reporting_level != SBER_LEVEL_OFF && | |
| 128 web_contents->GetBrowserContext()->IsOffTheRecord() == false) { | |
|
Jialiu Lin
2017/05/18 22:32:12
nit: replace "web_contents->GetBrowserContext()->I
mortonm
2017/05/19 20:21:03
Done.
| |
| 129 return true; | |
| 130 } | |
| 131 return false; | |
| 132 } | |
| 133 | |
| 122 void SafeBrowsingUIManager::ReportSafeBrowsingHitOnIOThread( | 134 void SafeBrowsingUIManager::ReportSafeBrowsingHitOnIOThread( |
| 123 const HitReport& hit_report) { | 135 const HitReport& hit_report) { |
| 124 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 136 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 125 | 137 |
| 126 // The service may delete the ping manager (i.e. when user disabling service, | 138 // The service may delete the ping manager (i.e. when user disabling service, |
| 127 // etc). This happens on the IO thread. | 139 // etc). This happens on the IO thread. |
| 128 if (!sb_service_ || !sb_service_->ping_manager()) | 140 if (!sb_service_ || !sb_service_->ping_manager()) |
| 129 return; | 141 return; |
| 130 | 142 |
| 131 DVLOG(1) << "ReportSafeBrowsingHit: " << hit_report.malicious_url << " " | 143 DVLOG(1) << "ReportSafeBrowsingHit: " << hit_report.malicious_url << " " |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 } | 218 } |
| 207 } | 219 } |
| 208 | 220 |
| 209 // Static. | 221 // Static. |
| 210 GURL SafeBrowsingUIManager::GetMainFrameWhitelistUrlForResourceForTesting( | 222 GURL SafeBrowsingUIManager::GetMainFrameWhitelistUrlForResourceForTesting( |
| 211 const security_interstitials::UnsafeResource& resource) { | 223 const security_interstitials::UnsafeResource& resource) { |
| 212 return GetMainFrameWhitelistUrlForResource(resource); | 224 return GetMainFrameWhitelistUrlForResource(resource); |
| 213 } | 225 } |
| 214 | 226 |
| 215 } // namespace safe_browsing | 227 } // namespace safe_browsing |
| OLD | NEW |