| 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/download_protection_service.h" | 5 #include "chrome/browser/safe_browsing/download_protection_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 DownloadProtectionService::DownloadInfo | 151 DownloadProtectionService::DownloadInfo |
| 152 DownloadProtectionService::DownloadInfo::FromDownloadItem( | 152 DownloadProtectionService::DownloadInfo::FromDownloadItem( |
| 153 const DownloadItem& item) { | 153 const DownloadItem& item) { |
| 154 DownloadInfo download_info; | 154 DownloadInfo download_info; |
| 155 download_info.target_file = item.GetTargetFilePath(); | 155 download_info.target_file = item.GetTargetFilePath(); |
| 156 download_info.sha256_hash = item.GetHash(); | 156 download_info.sha256_hash = item.GetHash(); |
| 157 download_info.local_file = item.GetFullPath(); | 157 download_info.local_file = item.GetFullPath(); |
| 158 download_info.download_url_chain = item.GetUrlChain(); | 158 download_info.download_url_chain = item.GetUrlChain(); |
| 159 download_info.referrer_url = item.GetReferrerUrl(); | 159 download_info.referrer_url = item.GetReferrerUrl(); |
| 160 download_info.total_bytes = item.GetTotalBytes(); | 160 download_info.total_bytes = item.GetTotalBytes(); |
| 161 // TODO(bryner): Populate user_initiated | 161 download_info.remote_address = item.GetRemoteAddress(); |
| 162 download_info.user_initiated = item.GetStateInfo().has_user_gesture; |
| 162 return download_info; | 163 return download_info; |
| 163 } | 164 } |
| 164 | 165 |
| 165 // Parent SafeBrowsing::Client class used to lookup the bad binary | 166 // Parent SafeBrowsing::Client class used to lookup the bad binary |
| 166 // URL and digest list. There are two sub-classes (one for each list). | 167 // URL and digest list. There are two sub-classes (one for each list). |
| 167 class DownloadSBClient | 168 class DownloadSBClient |
| 168 : public SafeBrowsingService::Client, | 169 : public SafeBrowsingService::Client, |
| 169 public base::RefCountedThreadSafe<DownloadSBClient> { | 170 public base::RefCountedThreadSafe<DownloadSBClient> { |
| 170 public: | 171 public: |
| 171 DownloadSBClient( | 172 DownloadSBClient( |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 request.set_url(info_.download_url_chain.back().spec()); | 569 request.set_url(info_.download_url_chain.back().spec()); |
| 569 request.mutable_digests()->set_sha256(info_.sha256_hash); | 570 request.mutable_digests()->set_sha256(info_.sha256_hash); |
| 570 request.set_length(info_.total_bytes); | 571 request.set_length(info_.total_bytes); |
| 571 for (size_t i = 0; i < info_.download_url_chain.size(); ++i) { | 572 for (size_t i = 0; i < info_.download_url_chain.size(); ++i) { |
| 572 ClientDownloadRequest::Resource* resource = request.add_resources(); | 573 ClientDownloadRequest::Resource* resource = request.add_resources(); |
| 573 resource->set_url(info_.download_url_chain[i].spec()); | 574 resource->set_url(info_.download_url_chain[i].spec()); |
| 574 if (i == info_.download_url_chain.size() - 1) { | 575 if (i == info_.download_url_chain.size() - 1) { |
| 575 // The last URL in the chain is the download URL. | 576 // The last URL in the chain is the download URL. |
| 576 resource->set_type(ClientDownloadRequest::DOWNLOAD_URL); | 577 resource->set_type(ClientDownloadRequest::DOWNLOAD_URL); |
| 577 resource->set_referrer(info_.referrer_url.spec()); | 578 resource->set_referrer(info_.referrer_url.spec()); |
| 579 if (!info_.remote_address.empty()) { |
| 580 resource->set_remote_ip(info_.remote_address); |
| 581 } |
| 578 } else { | 582 } else { |
| 579 resource->set_type(ClientDownloadRequest::DOWNLOAD_REDIRECT); | 583 resource->set_type(ClientDownloadRequest::DOWNLOAD_REDIRECT); |
| 580 } | 584 } |
| 581 // TODO(noelutz): fill out the remote IP addresses. | 585 // TODO(noelutz): fill out the remote IP addresses. |
| 582 } | 586 } |
| 583 request.set_user_initiated(info_.user_initiated); | 587 request.set_user_initiated(info_.user_initiated); |
| 584 request.mutable_signature()->CopyFrom(signature_info_); | 588 request.mutable_signature()->CopyFrom(signature_info_); |
| 585 std::string request_data; | 589 std::string request_data; |
| 586 if (!request.SerializeToString(&request_data)) { | 590 if (!request.SerializeToString(&request_data)) { |
| 587 RecordImprovedProtectionStats(REASON_INVALID_REQUEST_PROTO); | 591 RecordImprovedProtectionStats(REASON_INVALID_REQUEST_PROTO); |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 | 835 |
| 832 std::string issuer_fp = base::HexEncode(issuer.fingerprint().data, | 836 std::string issuer_fp = base::HexEncode(issuer.fingerprint().data, |
| 833 sizeof(issuer.fingerprint().data)); | 837 sizeof(issuer.fingerprint().data)); |
| 834 for (std::set<std::string>::iterator it = paths_to_check.begin(); | 838 for (std::set<std::string>::iterator it = paths_to_check.begin(); |
| 835 it != paths_to_check.end(); ++it) { | 839 it != paths_to_check.end(); ++it) { |
| 836 whitelist_strings->push_back("cert/" + issuer_fp + *it); | 840 whitelist_strings->push_back("cert/" + issuer_fp + *it); |
| 837 } | 841 } |
| 838 } | 842 } |
| 839 | 843 |
| 840 } // namespace safe_browsing | 844 } // namespace safe_browsing |
| OLD | NEW |