| 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/download_protection_service.h" | 5 #include "chrome/browser/safe_browsing/download_protection_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 DOWNLOAD_URL_CHECKS_MALWARE, | 108 DOWNLOAD_URL_CHECKS_MALWARE, |
| 109 | 109 |
| 110 DOWNLOAD_HASH_CHECKS_TOTAL, | 110 DOWNLOAD_HASH_CHECKS_TOTAL, |
| 111 DOWNLOAD_HASH_CHECKS_MALWARE, | 111 DOWNLOAD_HASH_CHECKS_MALWARE, |
| 112 | 112 |
| 113 // Memory space for histograms is determined by the max. | 113 // Memory space for histograms is determined by the max. |
| 114 // ALWAYS ADD NEW VALUES BEFORE THIS ONE. | 114 // ALWAYS ADD NEW VALUES BEFORE THIS ONE. |
| 115 DOWNLOAD_CHECKS_MAX | 115 DOWNLOAD_CHECKS_MAX |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 // Prepares URLs to be put into a ping message. Currently this just shortens | |
| 119 // data: URIs, other URLs are included verbatim. | |
| 120 std::string SanitizeUrl(const GURL& url) { | |
| 121 std::string spec = url.spec(); | |
| 122 if (url.SchemeIs(url::kDataScheme)) { | |
| 123 size_t comma_pos = spec.find(','); | |
| 124 if (comma_pos != std::string::npos && comma_pos != spec.size() - 1) { | |
| 125 std::string hash_value = crypto::SHA256HashString(spec); | |
| 126 spec.erase(comma_pos + 1); | |
| 127 spec += base::HexEncode(hash_value.data(), hash_value.size()); | |
| 128 } | |
| 129 } | |
| 130 return spec; | |
| 131 } | |
| 132 | |
| 133 } // namespace | 118 } // namespace |
| 134 | 119 |
| 135 // Parent SafeBrowsing::Client class used to lookup the bad binary | 120 // Parent SafeBrowsing::Client class used to lookup the bad binary |
| 136 // URL and digest list. There are two sub-classes (one for each list). | 121 // URL and digest list. There are two sub-classes (one for each list). |
| 137 class DownloadSBClient | 122 class DownloadSBClient |
| 138 : public SafeBrowsingDatabaseManager::Client, | 123 : public SafeBrowsingDatabaseManager::Client, |
| 139 public base::RefCountedThreadSafe<DownloadSBClient> { | 124 public base::RefCountedThreadSafe<DownloadSBClient> { |
| 140 public: | 125 public: |
| 141 DownloadSBClient( | 126 DownloadSBClient( |
| 142 const content::DownloadItem& item, | 127 const content::DownloadItem& item, |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 start_time_(base::TimeTicks::Now()), | 289 start_time_(base::TimeTicks::Now()), |
| 305 skipped_url_whitelist_(false), | 290 skipped_url_whitelist_(false), |
| 306 skipped_certificate_whitelist_(false), | 291 skipped_certificate_whitelist_(false), |
| 307 is_extended_reporting_(false), | 292 is_extended_reporting_(false), |
| 308 is_incognito_(false), | 293 is_incognito_(false), |
| 309 weakptr_factory_(this) { | 294 weakptr_factory_(this) { |
| 310 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 295 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 311 item_->AddObserver(this); | 296 item_->AddObserver(this); |
| 312 } | 297 } |
| 313 | 298 |
| 299 bool ShouldSampleUnsupportedFile(const base::FilePath& filename) { |
| 300 // If this extension is specifically marked as SAMPLED_PING (as are |
| 301 // all "unknown" extensions), we may want to sample it. Sampling it means |
| 302 // we'll send a "light ping" with private info removed, and we won't |
| 303 // use the verdict. |
| 304 const FileTypePolicies* policies = FileTypePolicies::GetInstance(); |
| 305 return service_ && is_extended_reporting_ && !is_incognito_ && |
| 306 base::RandDouble() < policies->SampledPingProbability() && |
| 307 policies->PingSettingForFile(filename) == |
| 308 DownloadFileType::SAMPLED_PING; |
| 309 } |
| 310 |
| 314 void Start() { | 311 void Start() { |
| 315 DVLOG(2) << "Starting SafeBrowsing download check for: " | 312 DVLOG(2) << "Starting SafeBrowsing download check for: " |
| 316 << item_->DebugString(true); | 313 << item_->DebugString(true); |
| 317 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 314 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 318 if (item_->GetBrowserContext()) { | 315 if (item_->GetBrowserContext()) { |
| 319 Profile* profile = | 316 Profile* profile = |
| 320 Profile::FromBrowserContext(item_->GetBrowserContext()); | 317 Profile::FromBrowserContext(item_->GetBrowserContext()); |
| 321 is_extended_reporting_ = profile && | 318 is_extended_reporting_ = profile && |
| 322 profile->GetPrefs()->GetBoolean( | 319 profile->GetPrefs()->GetBoolean( |
| 323 prefs::kSafeBrowsingExtendedReportingEnabled); | 320 prefs::kSafeBrowsingExtendedReportingEnabled); |
| 324 is_incognito_ = item_->GetBrowserContext()->IsOffTheRecord(); | 321 is_incognito_ = item_->GetBrowserContext()->IsOffTheRecord(); |
| 325 } | 322 } |
| 326 // TODO(noelutz): implement some cache to make sure we don't issue the same | 323 |
| 327 // request over and over again if a user downloads the same binary multiple | |
| 328 // times. | |
| 329 DownloadCheckResultReason reason = REASON_MAX; | 324 DownloadCheckResultReason reason = REASON_MAX; |
| 330 if (!IsSupportedDownload( | 325 if (!IsSupportedDownload( |
| 331 *item_, item_->GetTargetFilePath(), &reason, &type_)) { | 326 *item_, item_->GetTargetFilePath(), &reason, &type_)) { |
| 332 switch (reason) { | 327 switch (reason) { |
| 333 case REASON_EMPTY_URL_CHAIN: | 328 case REASON_EMPTY_URL_CHAIN: |
| 334 case REASON_INVALID_URL: | 329 case REASON_INVALID_URL: |
| 335 case REASON_UNSUPPORTED_URL_SCHEME: | 330 case REASON_UNSUPPORTED_URL_SCHEME: |
| 336 case REASON_LOCAL_FILE: | 331 case REASON_LOCAL_FILE: |
| 337 case REASON_REMOTE_FILE: | 332 case REASON_REMOTE_FILE: |
| 338 PostFinishTask(UNKNOWN, reason); | 333 PostFinishTask(UNKNOWN, reason); |
| 339 return; | 334 return; |
| 340 | 335 |
| 341 case REASON_NOT_BINARY_FILE: | 336 case REASON_NOT_BINARY_FILE: |
| 337 if (ShouldSampleUnsupportedFile(item_->GetTargetFilePath())) { |
| 338 // Send a "light ping" and don't use the verdict. |
| 339 type_ = ClientDownloadRequest::SAMPLED_UNSUPPORTED_FILE; |
| 340 break; |
| 341 } |
| 342 RecordFileExtensionType(item_->GetTargetFilePath()); | 342 RecordFileExtensionType(item_->GetTargetFilePath()); |
| 343 PostFinishTask(UNKNOWN, reason); | 343 PostFinishTask(UNKNOWN, reason); |
| 344 return; | 344 return; |
| 345 | 345 |
| 346 default: | 346 default: |
| 347 // We only expect the reasons explicitly handled above. | 347 // We only expect the reasons explicitly handled above. |
| 348 NOTREACHED(); | 348 NOTREACHED(); |
| 349 } | 349 } |
| 350 } | 350 } |
| 351 RecordFileExtensionType(item_->GetTargetFilePath()); | 351 RecordFileExtensionType(item_->GetTargetFilePath()); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 std::string token; | 460 std::string token; |
| 461 if (source->GetStatus().is_success() && | 461 if (source->GetStatus().is_success() && |
| 462 net::HTTP_OK == source->GetResponseCode()) { | 462 net::HTTP_OK == source->GetResponseCode()) { |
| 463 ClientDownloadResponse response; | 463 ClientDownloadResponse response; |
| 464 std::string data; | 464 std::string data; |
| 465 bool got_data = source->GetResponseAsString(&data); | 465 bool got_data = source->GetResponseAsString(&data); |
| 466 DCHECK(got_data); | 466 DCHECK(got_data); |
| 467 if (!response.ParseFromString(data)) { | 467 if (!response.ParseFromString(data)) { |
| 468 reason = REASON_INVALID_RESPONSE_PROTO; | 468 reason = REASON_INVALID_RESPONSE_PROTO; |
| 469 result = UNKNOWN; | 469 result = UNKNOWN; |
| 470 } else if (type_ == ClientDownloadRequest::SAMPLED_UNSUPPORTED_FILE) { |
| 471 // Ignore the verdict because we were just reporting a sampled file. |
| 472 reason = REASON_SAMPLED_UNSUPPORTED_FILE; |
| 473 result = UNKNOWN; |
| 470 } else if (response.verdict() == ClientDownloadResponse::SAFE) { | 474 } else if (response.verdict() == ClientDownloadResponse::SAFE) { |
| 471 reason = REASON_DOWNLOAD_SAFE; | 475 reason = REASON_DOWNLOAD_SAFE; |
| 472 result = SAFE; | 476 result = SAFE; |
| 473 } else if (service_ && !service_->IsSupportedDownload( | 477 } else if (service_ && !service_->IsSupportedDownload( |
| 474 *item_, item_->GetTargetFilePath())) { | 478 *item_, item_->GetTargetFilePath())) { |
| 475 // The client of the download protection service assumes that we don't | 479 // TODO(nparker): Remove this check since it should be impossible. |
| 476 // support this download so we cannot return any other verdict than | |
| 477 // UNKNOWN even if the server says it's dangerous to download this file. | |
| 478 // Note: if service_ is NULL we already cancelled the request and | |
| 479 // returned UNKNOWN. | |
| 480 reason = REASON_DOWNLOAD_NOT_SUPPORTED; | 480 reason = REASON_DOWNLOAD_NOT_SUPPORTED; |
| 481 result = UNKNOWN; | 481 result = UNKNOWN; |
| 482 } else if (response.verdict() == ClientDownloadResponse::DANGEROUS) { | 482 } else if (response.verdict() == ClientDownloadResponse::DANGEROUS) { |
| 483 reason = REASON_DOWNLOAD_DANGEROUS; | 483 reason = REASON_DOWNLOAD_DANGEROUS; |
| 484 result = DANGEROUS; | 484 result = DANGEROUS; |
| 485 token = response.token(); | 485 token = response.token(); |
| 486 } else if (response.verdict() == ClientDownloadResponse::UNCOMMON) { | 486 } else if (response.verdict() == ClientDownloadResponse::UNCOMMON) { |
| 487 reason = REASON_DOWNLOAD_UNCOMMON; | 487 reason = REASON_DOWNLOAD_UNCOMMON; |
| 488 result = UNCOMMON; | 488 result = UNCOMMON; |
| 489 token = response.token(); | 489 token = response.token(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 ClientDownloadRequest::DownloadType* type) { | 524 ClientDownloadRequest::DownloadType* type) { |
| 525 if (item.GetUrlChain().empty()) { | 525 if (item.GetUrlChain().empty()) { |
| 526 *reason = REASON_EMPTY_URL_CHAIN; | 526 *reason = REASON_EMPTY_URL_CHAIN; |
| 527 return false; | 527 return false; |
| 528 } | 528 } |
| 529 const GURL& final_url = item.GetUrlChain().back(); | 529 const GURL& final_url = item.GetUrlChain().back(); |
| 530 if (!final_url.is_valid() || final_url.is_empty()) { | 530 if (!final_url.is_valid() || final_url.is_empty()) { |
| 531 *reason = REASON_INVALID_URL; | 531 *reason = REASON_INVALID_URL; |
| 532 return false; | 532 return false; |
| 533 } | 533 } |
| 534 if (!FileTypePolicies::GetInstance()->IsCheckedBinaryFile(target_path)) { | |
| 535 *reason = REASON_NOT_BINARY_FILE; | |
| 536 return false; | |
| 537 } | |
| 538 if (!final_url.IsStandard() && !final_url.SchemeIsBlob() && | 534 if (!final_url.IsStandard() && !final_url.SchemeIsBlob() && |
| 539 !final_url.SchemeIs(url::kDataScheme)) { | 535 !final_url.SchemeIs(url::kDataScheme)) { |
| 540 *reason = REASON_UNSUPPORTED_URL_SCHEME; | 536 *reason = REASON_UNSUPPORTED_URL_SCHEME; |
| 541 return false; | 537 return false; |
| 542 } | 538 } |
| 543 if (final_url.SchemeIsFile()) { | 539 if (final_url.SchemeIsFile()) { |
| 544 *reason = final_url.has_host() ? REASON_REMOTE_FILE : REASON_LOCAL_FILE; | 540 *reason = final_url.has_host() ? REASON_REMOTE_FILE : REASON_LOCAL_FILE; |
| 545 return false; | 541 return false; |
| 546 } | 542 } |
| 543 // This check should be last, so we know the earlier checks passed. |
| 544 if (!FileTypePolicies::GetInstance()->IsCheckedBinaryFile(target_path)) { |
| 545 *reason = REASON_NOT_BINARY_FILE; |
| 546 return false; |
| 547 } |
| 547 *type = download_protection_util::GetDownloadType(target_path); | 548 *type = download_protection_util::GetDownloadType(target_path); |
| 548 return true; | 549 return true; |
| 549 } | 550 } |
| 550 | 551 |
| 551 private: | 552 private: |
| 552 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 553 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
| 553 friend class base::DeleteHelper<CheckClientDownloadRequest>; | 554 friend class base::DeleteHelper<CheckClientDownloadRequest>; |
| 554 | 555 |
| 555 ~CheckClientDownloadRequest() override { | 556 ~CheckClientDownloadRequest() override { |
| 556 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 557 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 if (service_->IsHashManuallyBlacklisted(request.digests().sha256())) | 879 if (service_->IsHashManuallyBlacklisted(request.digests().sha256())) |
| 879 return true; | 880 return true; |
| 880 | 881 |
| 881 for (auto bin_itr : request.archived_binary()) { | 882 for (auto bin_itr : request.archived_binary()) { |
| 882 if (service_->IsHashManuallyBlacklisted(bin_itr.digests().sha256())) | 883 if (service_->IsHashManuallyBlacklisted(bin_itr.digests().sha256())) |
| 883 return true; | 884 return true; |
| 884 } | 885 } |
| 885 return false; | 886 return false; |
| 886 } | 887 } |
| 887 | 888 |
| 889 // Prepares URLs to be put into a ping message. Currently this just shortens |
| 890 // data: URIs, other URLs are included verbatim. If this is a sampled binary, |
| 891 // we'll send a lite-ping which strips all PII. |
| 892 std::string SanitizeUrl(const GURL& url) const { |
| 893 if (type_ == ClientDownloadRequest::SAMPLED_UNSUPPORTED_FILE) |
| 894 return url.GetOrigin().spec(); |
| 895 |
| 896 std::string spec = url.spec(); |
| 897 if (url.SchemeIs(url::kDataScheme)) { |
| 898 size_t comma_pos = spec.find(','); |
| 899 if (comma_pos != std::string::npos && comma_pos != spec.size() - 1) { |
| 900 std::string hash_value = crypto::SHA256HashString(spec); |
| 901 spec.erase(comma_pos + 1); |
| 902 spec += base::HexEncode(hash_value.data(), hash_value.size()); |
| 903 } |
| 904 } |
| 905 return spec; |
| 906 } |
| 907 |
| 888 void SendRequest() { | 908 void SendRequest() { |
| 889 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 909 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 890 | 910 |
| 891 // This is our last chance to check whether the request has been canceled | 911 // This is our last chance to check whether the request has been canceled |
| 892 // before sending it. | 912 // before sending it. |
| 893 if (!service_) | 913 if (!service_) |
| 894 return; | 914 return; |
| 895 | 915 |
| 896 ClientDownloadRequest request; | 916 ClientDownloadRequest request; |
| 897 if (is_extended_reporting_) { | 917 if (is_extended_reporting_) { |
| 898 request.mutable_population()->set_user_population( | 918 request.mutable_population()->set_user_population( |
| 899 ChromeUserPopulation::EXTENDED_REPORTING); | 919 ChromeUserPopulation::EXTENDED_REPORTING); |
| 900 } else { | 920 } else { |
| 901 request.mutable_population()->set_user_population( | 921 request.mutable_population()->set_user_population( |
| 902 ChromeUserPopulation::SAFE_BROWSING); | 922 ChromeUserPopulation::SAFE_BROWSING); |
| 903 } | 923 } |
| 924 |
| 904 request.set_url(SanitizeUrl(item_->GetUrlChain().back())); | 925 request.set_url(SanitizeUrl(item_->GetUrlChain().back())); |
| 905 request.mutable_digests()->set_sha256(item_->GetHash()); | 926 request.mutable_digests()->set_sha256(item_->GetHash()); |
| 906 request.set_length(item_->GetReceivedBytes()); | 927 request.set_length(item_->GetReceivedBytes()); |
| 907 request.set_skipped_url_whitelist(skipped_url_whitelist_); | 928 request.set_skipped_url_whitelist(skipped_url_whitelist_); |
| 908 request.set_skipped_certificate_whitelist(skipped_certificate_whitelist_); | 929 request.set_skipped_certificate_whitelist(skipped_certificate_whitelist_); |
| 909 for (size_t i = 0; i < item_->GetUrlChain().size(); ++i) { | 930 for (size_t i = 0; i < item_->GetUrlChain().size(); ++i) { |
| 910 ClientDownloadRequest::Resource* resource = request.add_resources(); | 931 ClientDownloadRequest::Resource* resource = request.add_resources(); |
| 911 resource->set_url(SanitizeUrl(item_->GetUrlChain()[i])); | 932 resource->set_url(SanitizeUrl(item_->GetUrlChain()[i])); |
| 912 if (i == item_->GetUrlChain().size() - 1) { | 933 if (i == item_->GetUrlChain().size() - 1) { |
| 913 // The last URL in the chain is the download URL. | 934 // The last URL in the chain is the download URL. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 937 resource->set_url(SanitizeUrl(tab_url_)); | 958 resource->set_url(SanitizeUrl(tab_url_)); |
| 938 DVLOG(2) << "tab url " << resource->url(); | 959 DVLOG(2) << "tab url " << resource->url(); |
| 939 resource->set_type(ClientDownloadRequest::TAB_URL); | 960 resource->set_type(ClientDownloadRequest::TAB_URL); |
| 940 if (tab_referrer_url_.is_valid()) { | 961 if (tab_referrer_url_.is_valid()) { |
| 941 resource->set_referrer(SanitizeUrl(tab_referrer_url_)); | 962 resource->set_referrer(SanitizeUrl(tab_referrer_url_)); |
| 942 DVLOG(2) << "tab referrer " << resource->referrer(); | 963 DVLOG(2) << "tab referrer " << resource->referrer(); |
| 943 } | 964 } |
| 944 } | 965 } |
| 945 | 966 |
| 946 request.set_user_initiated(item_->HasUserGesture()); | 967 request.set_user_initiated(item_->HasUserGesture()); |
| 947 request.set_file_basename( | 968 if (type_ == ClientDownloadRequest::SAMPLED_UNSUPPORTED_FILE) { |
| 969 request.set_file_basename( |
| 970 base::FilePath(item_->GetTargetFilePath().Extension()) |
| 971 .AsUTF8Unsafe()); |
| 972 } else { |
| 973 request.set_file_basename( |
| 948 item_->GetTargetFilePath().BaseName().AsUTF8Unsafe()); | 974 item_->GetTargetFilePath().BaseName().AsUTF8Unsafe()); |
| 975 } |
| 949 request.set_download_type(type_); | 976 request.set_download_type(type_); |
| 950 if (archive_is_valid_ != ArchiveValid::UNSET) | 977 if (archive_is_valid_ != ArchiveValid::UNSET) |
| 951 request.set_archive_valid(archive_is_valid_ == ArchiveValid::VALID); | 978 request.set_archive_valid(archive_is_valid_ == ArchiveValid::VALID); |
| 952 request.mutable_signature()->CopyFrom(signature_info_); | 979 request.mutable_signature()->CopyFrom(signature_info_); |
| 953 if (image_headers_) | 980 if (image_headers_) |
| 954 request.set_allocated_image_headers(image_headers_.release()); | 981 request.set_allocated_image_headers(image_headers_.release()); |
| 955 if (archived_executable_) | 982 if (archived_executable_) |
| 956 request.mutable_archived_binary()->Swap(&archived_binary_); | 983 request.mutable_archived_binary()->Swap(&archived_binary_); |
| 957 if (!request.SerializeToString(&client_download_request_data_)) { | 984 if (!request.SerializeToString(&client_download_request_data_)) { |
| 958 FinishRequest(UNKNOWN, REASON_INVALID_REQUEST_PROTO); | 985 FinishRequest(UNKNOWN, REASON_INVALID_REQUEST_PROTO); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 REASON_MAX); | 1046 REASON_MAX); |
| 1020 if (reason != REASON_REQUEST_CANCELED) { | 1047 if (reason != REASON_REQUEST_CANCELED) { |
| 1021 UMA_HISTOGRAM_TIMES("SBClientDownload.DownloadRequestTimeoutDuration", | 1048 UMA_HISTOGRAM_TIMES("SBClientDownload.DownloadRequestTimeoutDuration", |
| 1022 base::TimeTicks::Now() - timeout_start_time_); | 1049 base::TimeTicks::Now() - timeout_start_time_); |
| 1023 } | 1050 } |
| 1024 } | 1051 } |
| 1025 if (service_) { | 1052 if (service_) { |
| 1026 DVLOG(2) << "SafeBrowsing download verdict for: " | 1053 DVLOG(2) << "SafeBrowsing download verdict for: " |
| 1027 << item_->DebugString(true) << " verdict:" << reason | 1054 << item_->DebugString(true) << " verdict:" << reason |
| 1028 << " result:" << result; | 1055 << " result:" << result; |
| 1029 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", | 1056 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", reason, |
| 1030 reason, | |
| 1031 REASON_MAX); | 1057 REASON_MAX); |
| 1032 callback_.Run(result); | 1058 callback_.Run(result); |
| 1033 item_->RemoveObserver(this); | 1059 item_->RemoveObserver(this); |
| 1034 item_ = NULL; | 1060 item_ = NULL; |
| 1035 DownloadProtectionService* service = service_; | 1061 DownloadProtectionService* service = service_; |
| 1036 service_ = NULL; | 1062 service_ = NULL; |
| 1037 service->RequestFinished(this); | 1063 service->RequestFinished(this); |
| 1038 // DownloadProtectionService::RequestFinished will decrement our refcount, | 1064 // DownloadProtectionService::RequestFinished will decrement our refcount, |
| 1039 // so we may be deleted now. | 1065 // so we may be deleted now. |
| 1040 } else { | 1066 } else { |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1367 case ClientDownloadResponse::DANGEROUS: | 1393 case ClientDownloadResponse::DANGEROUS: |
| 1368 return DANGEROUS; | 1394 return DANGEROUS; |
| 1369 case ClientDownloadResponse::DANGEROUS_HOST: | 1395 case ClientDownloadResponse::DANGEROUS_HOST: |
| 1370 return DANGEROUS_HOST; | 1396 return DANGEROUS_HOST; |
| 1371 } | 1397 } |
| 1372 return UNKNOWN; | 1398 return UNKNOWN; |
| 1373 } | 1399 } |
| 1374 | 1400 |
| 1375 // Given a |default_file_path| and a list of |alternate_extensions|, | 1401 // Given a |default_file_path| and a list of |alternate_extensions|, |
| 1376 // constructs a FilePath with each possible extension and returns one that | 1402 // constructs a FilePath with each possible extension and returns one that |
| 1377 // satisfies download_protection_util::IsSupportedBinaryFile(). If none are | 1403 // satisfies IsCheckedBinaryFile(). If none are supported, returns an |
| 1378 // supported, returns an empty FilePath. | 1404 // empty FilePath. |
| 1379 static base::FilePath GetSupportedFilePath( | 1405 static base::FilePath GetSupportedFilePath( |
| 1380 const base::FilePath& default_file_path, | 1406 const base::FilePath& default_file_path, |
| 1381 const std::vector<base::FilePath::StringType>& alternate_extensions) { | 1407 const std::vector<base::FilePath::StringType>& alternate_extensions) { |
| 1382 const FileTypePolicies* file_type_policies = | 1408 const FileTypePolicies* file_type_policies = |
| 1383 FileTypePolicies::GetInstance(); | 1409 FileTypePolicies::GetInstance(); |
| 1384 if (file_type_policies->IsCheckedBinaryFile(default_file_path)) | 1410 if (file_type_policies->IsCheckedBinaryFile(default_file_path)) |
| 1385 return default_file_path; | 1411 return default_file_path; |
| 1386 | 1412 |
| 1387 for (const auto& extension : alternate_extensions) { | 1413 for (const auto& extension : alternate_extensions) { |
| 1388 base::FilePath alternative_file_path = | 1414 base::FilePath alternative_file_path = |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1411 CheckDownloadCallback callback_; | 1437 CheckDownloadCallback callback_; |
| 1412 | 1438 |
| 1413 DownloadProtectionService* service_; | 1439 DownloadProtectionService* service_; |
| 1414 const scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; | 1440 const scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; |
| 1415 | 1441 |
| 1416 // Time request was started. | 1442 // Time request was started. |
| 1417 const base::TimeTicks start_time_; | 1443 const base::TimeTicks start_time_; |
| 1418 | 1444 |
| 1419 // A download path that is supported by SafeBrowsing. This is determined by | 1445 // A download path that is supported by SafeBrowsing. This is determined by |
| 1420 // invoking GetSupportedFilePath(). If non-empty, | 1446 // invoking GetSupportedFilePath(). If non-empty, |
| 1421 // safe_browsing::IsSupportedBinaryFile(supported_path_) is always true. This | 1447 // IsCheckedBinaryFile(supported_path_) is always true. This |
| 1422 // path is therefore used as the download target when sending the SafeBrowsing | 1448 // path is therefore used as the download target when sending the SafeBrowsing |
| 1423 // ping. | 1449 // ping. |
| 1424 const base::FilePath supported_path_; | 1450 const base::FilePath supported_path_; |
| 1425 | 1451 |
| 1426 base::WeakPtrFactory<PPAPIDownloadRequest> weakptr_factory_; | 1452 base::WeakPtrFactory<PPAPIDownloadRequest> weakptr_factory_; |
| 1427 | 1453 |
| 1428 DISALLOW_COPY_AND_ASSIGN(PPAPIDownloadRequest); | 1454 DISALLOW_COPY_AND_ASSIGN(PPAPIDownloadRequest); |
| 1429 }; | 1455 }; |
| 1430 | 1456 |
| 1431 DownloadProtectionService::DownloadProtectionService( | 1457 DownloadProtectionService::DownloadProtectionService( |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1510 FROM_HERE, | 1536 FROM_HERE, |
| 1511 base::Bind(&DownloadUrlSBClient::StartCheck, client)); | 1537 base::Bind(&DownloadUrlSBClient::StartCheck, client)); |
| 1512 } | 1538 } |
| 1513 | 1539 |
| 1514 bool DownloadProtectionService::IsSupportedDownload( | 1540 bool DownloadProtectionService::IsSupportedDownload( |
| 1515 const content::DownloadItem& item, | 1541 const content::DownloadItem& item, |
| 1516 const base::FilePath& target_path) const { | 1542 const base::FilePath& target_path) const { |
| 1517 DownloadCheckResultReason reason = REASON_MAX; | 1543 DownloadCheckResultReason reason = REASON_MAX; |
| 1518 ClientDownloadRequest::DownloadType type = | 1544 ClientDownloadRequest::DownloadType type = |
| 1519 ClientDownloadRequest::WIN_EXECUTABLE; | 1545 ClientDownloadRequest::WIN_EXECUTABLE; |
| 1546 // TODO(nparker): Remove the CRX check here once can support |
| 1547 // UNKNOWN types properly. http://crbug.com/581044 |
| 1520 return (CheckClientDownloadRequest::IsSupportedDownload( | 1548 return (CheckClientDownloadRequest::IsSupportedDownload( |
| 1521 item, target_path, &reason, &type) && | 1549 item, target_path, &reason, &type) && |
| 1522 (ClientDownloadRequest::CHROME_EXTENSION != type)); | 1550 (ClientDownloadRequest::CHROME_EXTENSION != type)); |
| 1523 } | 1551 } |
| 1524 | 1552 |
| 1525 void DownloadProtectionService::CheckPPAPIDownloadRequest( | 1553 void DownloadProtectionService::CheckPPAPIDownloadRequest( |
| 1526 const GURL& requestor_url, | 1554 const GURL& requestor_url, |
| 1527 const base::FilePath& default_file_path, | 1555 const base::FilePath& default_file_path, |
| 1528 const std::vector<base::FilePath::StringType>& alternate_extensions, | 1556 const std::vector<base::FilePath::StringType>& alternate_extensions, |
| 1529 const CheckDownloadCallback& callback) { | 1557 const CheckDownloadCallback& callback) { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1690 GURL DownloadProtectionService::GetDownloadRequestUrl() { | 1718 GURL DownloadProtectionService::GetDownloadRequestUrl() { |
| 1691 GURL url(kDownloadRequestUrl); | 1719 GURL url(kDownloadRequestUrl); |
| 1692 std::string api_key = google_apis::GetAPIKey(); | 1720 std::string api_key = google_apis::GetAPIKey(); |
| 1693 if (!api_key.empty()) | 1721 if (!api_key.empty()) |
| 1694 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); | 1722 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); |
| 1695 | 1723 |
| 1696 return url; | 1724 return url; |
| 1697 } | 1725 } |
| 1698 | 1726 |
| 1699 } // namespace safe_browsing | 1727 } // namespace safe_browsing |
| OLD | NEW |