| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/safe_browsing_service.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 // Also, at this point, page_url points to the _previous_ page that we | 1019 // Also, at this point, page_url points to the _previous_ page that we |
| 1020 // were on. We replace page_url with resource.original_url and referrer | 1020 // were on. We replace page_url with resource.original_url and referrer |
| 1021 // with page_url. | 1021 // with page_url. |
| 1022 if (!is_subresource && | 1022 if (!is_subresource && |
| 1023 !resource.original_url.is_empty() && | 1023 !resource.original_url.is_empty() && |
| 1024 resource.original_url != resource.url) { | 1024 resource.original_url != resource.url) { |
| 1025 referrer_url = page_url; | 1025 referrer_url = page_url; |
| 1026 page_url = resource.original_url; | 1026 page_url = resource.original_url; |
| 1027 } | 1027 } |
| 1028 ReportSafeBrowsingHit(resource.url, page_url, referrer_url, is_subresource, | 1028 ReportSafeBrowsingHit(resource.url, page_url, referrer_url, is_subresource, |
| 1029 resource.threat_type); | 1029 resource.threat_type, std::string() /* post_data */); |
| 1030 } | 1030 } |
| 1031 | 1031 |
| 1032 SafeBrowsingBlockingPage::ShowBlockingPage(this, resource); | 1032 SafeBrowsingBlockingPage::ShowBlockingPage(this, resource); |
| 1033 } | 1033 } |
| 1034 | 1034 |
| 1035 // A safebrowsing hit is sent after a blocking page for malware/phishing | 1035 // A safebrowsing hit is sent after a blocking page for malware/phishing |
| 1036 // or after the warning dialog for download urls, only for UMA users. | 1036 // or after the warning dialog for download urls, only for UMA users. |
| 1037 void SafeBrowsingService::ReportSafeBrowsingHit( | 1037 void SafeBrowsingService::ReportSafeBrowsingHit( |
| 1038 const GURL& malicious_url, | 1038 const GURL& malicious_url, |
| 1039 const GURL& page_url, | 1039 const GURL& page_url, |
| 1040 const GURL& referrer_url, | 1040 const GURL& referrer_url, |
| 1041 bool is_subresource, | 1041 bool is_subresource, |
| 1042 SafeBrowsingService::UrlCheckResult threat_type) { | 1042 SafeBrowsingService::UrlCheckResult threat_type, |
| 1043 const std::string& post_data) { |
| 1043 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1044 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1044 if (!CanReportStats()) | 1045 if (!CanReportStats()) |
| 1045 return; | 1046 return; |
| 1046 | 1047 |
| 1047 BrowserThread::PostTask( | 1048 BrowserThread::PostTask( |
| 1048 BrowserThread::IO, FROM_HERE, | 1049 BrowserThread::IO, FROM_HERE, |
| 1049 NewRunnableMethod( | 1050 NewRunnableMethod( |
| 1050 this, | 1051 this, |
| 1051 &SafeBrowsingService::ReportSafeBrowsingHitOnIOThread, | 1052 &SafeBrowsingService::ReportSafeBrowsingHitOnIOThread, |
| 1052 malicious_url, | 1053 malicious_url, |
| 1053 page_url, | 1054 page_url, |
| 1054 referrer_url, | 1055 referrer_url, |
| 1055 is_subresource, | 1056 is_subresource, |
| 1056 threat_type)); | 1057 threat_type, |
| 1058 post_data)); |
| 1057 } | 1059 } |
| 1058 | 1060 |
| 1059 void SafeBrowsingService::ReportSafeBrowsingHitOnIOThread( | 1061 void SafeBrowsingService::ReportSafeBrowsingHitOnIOThread( |
| 1060 const GURL& malicious_url, | 1062 const GURL& malicious_url, |
| 1061 const GURL& page_url, | 1063 const GURL& page_url, |
| 1062 const GURL& referrer_url, | 1064 const GURL& referrer_url, |
| 1063 bool is_subresource, | 1065 bool is_subresource, |
| 1064 SafeBrowsingService::UrlCheckResult threat_type) { | 1066 SafeBrowsingService::UrlCheckResult threat_type, |
| 1067 const std::string& post_data) { |
| 1065 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1068 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1066 if (!enabled_) | 1069 if (!enabled_) |
| 1067 return; | 1070 return; |
| 1068 | 1071 |
| 1069 DVLOG(1) << "ReportSafeBrowsingHit: " << malicious_url << " " << page_url | 1072 DVLOG(1) << "ReportSafeBrowsingHit: " << malicious_url << " " << page_url |
| 1070 << " " << referrer_url << " " << is_subresource << " " | 1073 << " " << referrer_url << " " << is_subresource << " " |
| 1071 << threat_type; | 1074 << threat_type; |
| 1072 protocol_manager_->ReportSafeBrowsingHit(malicious_url, page_url, | 1075 protocol_manager_->ReportSafeBrowsingHit(malicious_url, page_url, |
| 1073 referrer_url, is_subresource, | 1076 referrer_url, is_subresource, |
| 1074 threat_type); | 1077 threat_type, post_data); |
| 1075 } | 1078 } |
| 1076 | 1079 |
| 1077 // If the user had opted-in to send MalwareDetails, this gets called | 1080 // If the user had opted-in to send MalwareDetails, this gets called |
| 1078 // when the report is ready. | 1081 // when the report is ready. |
| 1079 void SafeBrowsingService::SendSerializedMalwareDetails( | 1082 void SafeBrowsingService::SendSerializedMalwareDetails( |
| 1080 const std::string& serialized) { | 1083 const std::string& serialized) { |
| 1081 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1084 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1082 if (!serialized.empty()) { | 1085 if (!serialized.empty()) { |
| 1083 DVLOG(1) << "Sending serialized malware details."; | 1086 DVLOG(1) << "Sending serialized malware details."; |
| 1084 protocol_manager_->ReportMalwareDetails(serialized); | 1087 protocol_manager_->ReportMalwareDetails(serialized); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1186 check->is_download = true; | 1189 check->is_download = true; |
| 1187 check->timeout_task = | 1190 check->timeout_task = |
| 1188 NewRunnableMethod(this, &SafeBrowsingService::TimeoutCallback, check); | 1191 NewRunnableMethod(this, &SafeBrowsingService::TimeoutCallback, check); |
| 1189 checks_.insert(check); | 1192 checks_.insert(check); |
| 1190 | 1193 |
| 1191 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, task); | 1194 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, task); |
| 1192 | 1195 |
| 1193 MessageLoop::current()->PostDelayedTask( | 1196 MessageLoop::current()->PostDelayedTask( |
| 1194 FROM_HERE, check->timeout_task, timeout_ms); | 1197 FROM_HERE, check->timeout_task, timeout_ms); |
| 1195 } | 1198 } |
| OLD | NEW |