| 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/ping_manager.h" | 5 #include "chrome/browser/safe_browsing/ping_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "chrome/browser/safe_browsing/permission_reporter.h" | |
| 14 #include "components/certificate_reporting/error_reporter.h" | 13 #include "components/certificate_reporting/error_reporter.h" |
| 15 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 16 #include "google_apis/google_api_keys.h" | 15 #include "google_apis/google_api_keys.h" |
| 17 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
| 18 #include "net/base/load_flags.h" | 17 #include "net/base/load_flags.h" |
| 19 #include "net/ssl/ssl_info.h" | 18 #include "net/ssl/ssl_info.h" |
| 20 #include "net/url_request/report_sender.h" | 19 #include "net/url_request/report_sender.h" |
| 21 #include "net/url_request/url_fetcher.h" | 20 #include "net/url_request/url_fetcher.h" |
| 22 #include "net/url_request/url_request_context_getter.h" | 21 #include "net/url_request/url_request_context_getter.h" |
| 23 #include "net/url_request/url_request_status.h" | 22 #include "net/url_request/url_request_status.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 55 |
| 57 if (request_context_getter) { | 56 if (request_context_getter) { |
| 58 net::ReportSender::CookiesPreference cookies_preference; | 57 net::ReportSender::CookiesPreference cookies_preference; |
| 59 GURL certificate_upload_url; | 58 GURL certificate_upload_url; |
| 60 cookies_preference = net::ReportSender::DO_NOT_SEND_COOKIES; | 59 cookies_preference = net::ReportSender::DO_NOT_SEND_COOKIES; |
| 61 certificate_upload_url = GURL(kExtendedReportingUploadUrlInsecure); | 60 certificate_upload_url = GURL(kExtendedReportingUploadUrlInsecure); |
| 62 | 61 |
| 63 certificate_error_reporter_.reset(new certificate_reporting::ErrorReporter( | 62 certificate_error_reporter_.reset(new certificate_reporting::ErrorReporter( |
| 64 request_context_getter->GetURLRequestContext(), certificate_upload_url, | 63 request_context_getter->GetURLRequestContext(), certificate_upload_url, |
| 65 cookies_preference)); | 64 cookies_preference)); |
| 66 | |
| 67 permission_reporter_.reset( | |
| 68 new PermissionReporter(request_context_getter->GetURLRequestContext())); | |
| 69 } | 65 } |
| 70 | 66 |
| 71 version_ = SafeBrowsingProtocolManagerHelper::Version(); | 67 version_ = SafeBrowsingProtocolManagerHelper::Version(); |
| 72 } | 68 } |
| 73 | 69 |
| 74 SafeBrowsingPingManager::~SafeBrowsingPingManager() { | 70 SafeBrowsingPingManager::~SafeBrowsingPingManager() { |
| 75 // Delete in-progress safebrowsing reports (hits and details). | 71 // Delete in-progress safebrowsing reports (hits and details). |
| 76 STLDeleteContainerPointers(safebrowsing_reports_.begin(), | 72 STLDeleteContainerPointers(safebrowsing_reports_.begin(), |
| 77 safebrowsing_reports_.end()); | 73 safebrowsing_reports_.end()); |
| 78 } | 74 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 DCHECK(certificate_error_reporter_); | 122 DCHECK(certificate_error_reporter_); |
| 127 certificate_error_reporter_->SendExtendedReportingReport(serialized_report); | 123 certificate_error_reporter_->SendExtendedReportingReport(serialized_report); |
| 128 } | 124 } |
| 129 | 125 |
| 130 void SafeBrowsingPingManager::SetCertificateErrorReporterForTesting( | 126 void SafeBrowsingPingManager::SetCertificateErrorReporterForTesting( |
| 131 std::unique_ptr<certificate_reporting::ErrorReporter> | 127 std::unique_ptr<certificate_reporting::ErrorReporter> |
| 132 certificate_error_reporter) { | 128 certificate_error_reporter) { |
| 133 certificate_error_reporter_ = std::move(certificate_error_reporter); | 129 certificate_error_reporter_ = std::move(certificate_error_reporter); |
| 134 } | 130 } |
| 135 | 131 |
| 136 void SafeBrowsingPingManager::ReportPermissionAction( | |
| 137 const GURL& origin, | |
| 138 content::PermissionType permission, | |
| 139 PermissionAction action) { | |
| 140 permission_reporter_->SendReport(origin, permission, action); | |
| 141 } | |
| 142 | |
| 143 GURL SafeBrowsingPingManager::SafeBrowsingHitUrl( | 132 GURL SafeBrowsingPingManager::SafeBrowsingHitUrl( |
| 144 const safe_browsing::HitReport& hit_report) const { | 133 const safe_browsing::HitReport& hit_report) const { |
| 145 DCHECK(hit_report.threat_type == SB_THREAT_TYPE_URL_MALWARE || | 134 DCHECK(hit_report.threat_type == SB_THREAT_TYPE_URL_MALWARE || |
| 146 hit_report.threat_type == SB_THREAT_TYPE_URL_PHISHING || | 135 hit_report.threat_type == SB_THREAT_TYPE_URL_PHISHING || |
| 147 hit_report.threat_type == SB_THREAT_TYPE_URL_UNWANTED || | 136 hit_report.threat_type == SB_THREAT_TYPE_URL_UNWANTED || |
| 148 hit_report.threat_type == SB_THREAT_TYPE_BINARY_MALWARE_URL || | 137 hit_report.threat_type == SB_THREAT_TYPE_BINARY_MALWARE_URL || |
| 149 hit_report.threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL || | 138 hit_report.threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL || |
| 150 hit_report.threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL); | 139 hit_report.threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL); |
| 151 std::string url = SafeBrowsingProtocolManagerHelper::ComposeUrl( | 140 std::string url = SafeBrowsingProtocolManagerHelper::ComposeUrl( |
| 152 url_prefix_, "report", client_name_, version_, std::string(), | 141 url_prefix_, "report", client_name_, version_, std::string(), |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 version_.c_str()); | 219 version_.c_str()); |
| 231 std::string api_key = google_apis::GetAPIKey(); | 220 std::string api_key = google_apis::GetAPIKey(); |
| 232 if (!api_key.empty()) { | 221 if (!api_key.empty()) { |
| 233 base::StringAppendF(&url, "&key=%s", | 222 base::StringAppendF(&url, "&key=%s", |
| 234 net::EscapeQueryParamValue(api_key, true).c_str()); | 223 net::EscapeQueryParamValue(api_key, true).c_str()); |
| 235 } | 224 } |
| 236 return GURL(url); | 225 return GURL(url); |
| 237 } | 226 } |
| 238 | 227 |
| 239 } // namespace safe_browsing | 228 } // namespace safe_browsing |
| OLD | NEW |