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