| 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/protocol_manager.h" | 5 #include "chrome/browser/safe_browsing/protocol_manager.h" |
| 6 | 6 |
| 7 #ifndef NDEBUG | 7 #ifndef NDEBUG |
| 8 #include "base/base64.h" | 8 #include "base/base64.h" |
| 9 #endif | 9 #endif |
| 10 #include "base/environment.h" | 10 #include "base/environment.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 17 #include "base/timer.h" | 17 #include "base/timer.h" |
| 18 #include "chrome/browser/safe_browsing/protocol_parser.h" | 18 #include "chrome/browser/safe_browsing/protocol_parser.h" |
| 19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 20 #include "chrome/common/chrome_version_info.h" | 20 #include "chrome/common/chrome_version_info.h" |
| 21 #include "chrome/common/env_vars.h" | 21 #include "chrome/common/env_vars.h" |
| 22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 23 #include "google_apis/google_api_keys.h" |
| 23 #include "net/base/escape.h" | 24 #include "net/base/escape.h" |
| 24 #include "net/base/load_flags.h" | 25 #include "net/base/load_flags.h" |
| 25 #include "net/url_request/url_fetcher.h" | 26 #include "net/url_request/url_fetcher.h" |
| 26 #include "net/url_request/url_request_context_getter.h" | 27 #include "net/url_request/url_request_context_getter.h" |
| 27 #include "net/url_request/url_request_status.h" | 28 #include "net/url_request/url_request_status.h" |
| 28 | 29 |
| 29 using base::Time; | 30 using base::Time; |
| 30 using base::TimeDelta; | 31 using base::TimeDelta; |
| 31 using content::BrowserThread; | 32 using content::BrowserThread; |
| 32 | 33 |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 | 643 |
| 643 std::string SafeBrowsingProtocolManager::ComposeUrl( | 644 std::string SafeBrowsingProtocolManager::ComposeUrl( |
| 644 const std::string& prefix, const std::string& method, | 645 const std::string& prefix, const std::string& method, |
| 645 const std::string& client_name, const std::string& version, | 646 const std::string& client_name, const std::string& version, |
| 646 const std::string& additional_query) { | 647 const std::string& additional_query) { |
| 647 DCHECK(!prefix.empty() && !method.empty() && | 648 DCHECK(!prefix.empty() && !method.empty() && |
| 648 !client_name.empty() && !version.empty()); | 649 !client_name.empty() && !version.empty()); |
| 649 std::string url = base::StringPrintf("%s/%s?client=%s&appver=%s&pver=2.2", | 650 std::string url = base::StringPrintf("%s/%s?client=%s&appver=%s&pver=2.2", |
| 650 prefix.c_str(), method.c_str(), | 651 prefix.c_str(), method.c_str(), |
| 651 client_name.c_str(), version.c_str()); | 652 client_name.c_str(), version.c_str()); |
| 653 std::string api_key = google_apis::GetAPIKey(); |
| 654 if (!api_key.empty()) { |
| 655 base::StringAppendF(&url, "&key=%s", |
| 656 net::EscapeQueryParamValue(api_key, true).c_str()); |
| 657 } |
| 652 if (!additional_query.empty()) { | 658 if (!additional_query.empty()) { |
| 653 DCHECK(url.find("?") != std::string::npos); | 659 DCHECK(url.find("?") != std::string::npos); |
| 654 url.append("&"); | 660 url.append("&"); |
| 655 url.append(additional_query); | 661 url.append(additional_query); |
| 656 } | 662 } |
| 657 return url; | 663 return url; |
| 658 } | 664 } |
| 659 | 665 |
| 660 GURL SafeBrowsingProtocolManager::UpdateUrl() const { | 666 GURL SafeBrowsingProtocolManager::UpdateUrl() const { |
| 661 return GURL(ComposeUrl(url_prefix_, "downloads", client_name_, version_, | 667 return GURL(ComposeUrl(url_prefix_, "downloads", client_name_, version_, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 net::EscapeQueryParamValue(referrer_url.spec(), true).c_str(), | 711 net::EscapeQueryParamValue(referrer_url.spec(), true).c_str(), |
| 706 is_subresource)); | 712 is_subresource)); |
| 707 } | 713 } |
| 708 | 714 |
| 709 GURL SafeBrowsingProtocolManager::MalwareDetailsUrl() const { | 715 GURL SafeBrowsingProtocolManager::MalwareDetailsUrl() const { |
| 710 std::string url = base::StringPrintf( | 716 std::string url = base::StringPrintf( |
| 711 "%s/clientreport/malware?client=%s&appver=%s&pver=1.0", | 717 "%s/clientreport/malware?client=%s&appver=%s&pver=1.0", |
| 712 url_prefix_.c_str(), | 718 url_prefix_.c_str(), |
| 713 client_name_.c_str(), | 719 client_name_.c_str(), |
| 714 version_.c_str()); | 720 version_.c_str()); |
| 721 std::string api_key = google_apis::GetAPIKey(); |
| 722 if (!api_key.empty()) { |
| 723 base::StringAppendF(&url, "&key=%s", |
| 724 net::EscapeQueryParamValue(api_key, true).c_str()); |
| 725 } |
| 715 return GURL(url); | 726 return GURL(url); |
| 716 } | 727 } |
| 717 | 728 |
| 718 GURL SafeBrowsingProtocolManager::NextChunkUrl(const std::string& url) const { | 729 GURL SafeBrowsingProtocolManager::NextChunkUrl(const std::string& url) const { |
| 719 std::string next_url; | 730 std::string next_url; |
| 720 if (!StartsWithASCII(url, "http://", false) && | 731 if (!StartsWithASCII(url, "http://", false) && |
| 721 !StartsWithASCII(url, "https://", false)) { | 732 !StartsWithASCII(url, "https://", false)) { |
| 722 // Use https if we updated via https, otherwise http (useful for testing). | 733 // Use https if we updated via https, otherwise http (useful for testing). |
| 723 if (StartsWithASCII(url_prefix_, "https://", false)) | 734 if (StartsWithASCII(url_prefix_, "https://", false)) |
| 724 next_url.append("https://"); | 735 next_url.append("https://"); |
| 725 else | 736 else |
| 726 next_url.append("http://"); | 737 next_url.append("http://"); |
| 727 next_url.append(url); | 738 next_url.append(url); |
| 728 } else { | 739 } else { |
| 729 next_url = url; | 740 next_url = url; |
| 730 } | 741 } |
| 731 if (!additional_query_.empty()) { | 742 if (!additional_query_.empty()) { |
| 732 if (next_url.find("?") != std::string::npos) { | 743 if (next_url.find("?") != std::string::npos) { |
| 733 next_url.append("&"); | 744 next_url.append("&"); |
| 734 } else { | 745 } else { |
| 735 next_url.append("?"); | 746 next_url.append("?"); |
| 736 } | 747 } |
| 737 next_url.append(additional_query_); | 748 next_url.append(additional_query_); |
| 738 } | 749 } |
| 739 return GURL(next_url); | 750 return GURL(next_url); |
| 740 } | 751 } |
| OLD | NEW |