Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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 "components/safe_browsing/base_ping_manager.h" | 5 #include "components/safe_browsing/base_ping_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_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 "base/values.h" | 14 #include "base/values.h" |
| 15 #include "components/data_use_measurement/core/data_use_user_data.h" | 15 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "google_apis/google_api_keys.h" | 17 #include "google_apis/google_api_keys.h" |
| 18 #include "net/base/escape.h" | 18 #include "net/base/escape.h" |
| 19 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
| 20 #include "net/log/net_log_source_type.h" | 20 #include "net/log/net_log_source_type.h" |
| 21 #include "net/traffic_annotation/network_traffic_annotation.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.h" | 23 #include "net/url_request/url_request_context.h" |
| 23 #include "net/url_request/url_request_context_getter.h" | 24 #include "net/url_request/url_request_context_getter.h" |
| 24 #include "net/url_request/url_request_status.h" | 25 #include "net/url_request/url_request_status.h" |
| 25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 26 | 27 |
| 27 using content::BrowserThread; | 28 using content::BrowserThread; |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 // Returns a dictionary with "url"=|url-spec| and "data"=|payload| for | 31 // Returns a dictionary with "url"=|url-spec| and "data"=|payload| for |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 return ptr.get() == source; | 103 return ptr.get() == source; |
| 103 }); | 104 }); |
| 104 DCHECK(it != safebrowsing_reports_.end()); | 105 DCHECK(it != safebrowsing_reports_.end()); |
| 105 safebrowsing_reports_.erase(it); | 106 safebrowsing_reports_.erase(it); |
| 106 } | 107 } |
| 107 | 108 |
| 108 // Sends a SafeBrowsing "hit" report. | 109 // Sends a SafeBrowsing "hit" report. |
| 109 void BasePingManager::ReportSafeBrowsingHit( | 110 void BasePingManager::ReportSafeBrowsingHit( |
| 110 const safe_browsing::HitReport& hit_report) { | 111 const safe_browsing::HitReport& hit_report) { |
| 111 GURL report_url = SafeBrowsingHitUrl(hit_report); | 112 GURL report_url = SafeBrowsingHitUrl(hit_report); |
| 113 net::NetworkTrafficAnnotationTag traffic_annotation = | |
| 114 net::DefineNetworkTrafficAnnotation("...", R"( | |
| 115 semantics { | |
| 116 sender: "..." | |
|
Nathan Parker
2017/04/14 21:32:23
Sender: Safe browsing extended reporting
desc: Whe
Ramin Halavati
2017/04/18 08:46:40
Done.
| |
| 117 description: "..." | |
| 118 trigger: "..." | |
| 119 data: "..." | |
| 120 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER | |
| 121 } | |
| 122 policy { | |
| 123 cookies_allowed: false/true | |
| 124 cookies_store: "..." | |
| 125 setting: "..." | |
| 126 chrome_policy { | |
| 127 [POLICY_NAME] { | |
| 128 policy_options {mode: MANDATORY/RECOMMENDED/UNSET} | |
| 129 [POLICY_NAME]: ... //(value to disable it) | |
| 130 } | |
| 131 } | |
| 132 policy_exception_justification: "..." | |
| 133 })"); | |
| 112 std::unique_ptr<net::URLFetcher> report_ptr = net::URLFetcher::Create( | 134 std::unique_ptr<net::URLFetcher> report_ptr = net::URLFetcher::Create( |
| 113 report_url, | 135 report_url, |
| 114 hit_report.post_data.empty() ? net::URLFetcher::GET | 136 hit_report.post_data.empty() ? net::URLFetcher::GET |
| 115 : net::URLFetcher::POST, | 137 : net::URLFetcher::POST, |
| 116 this); | 138 this, traffic_annotation); |
| 117 net::URLFetcher* report = report_ptr.get(); | 139 net::URLFetcher* report = report_ptr.get(); |
| 118 data_use_measurement::DataUseUserData::AttachToFetcher( | 140 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 119 report, data_use_measurement::DataUseUserData::SAFE_BROWSING); | 141 report, data_use_measurement::DataUseUserData::SAFE_BROWSING); |
| 120 report_ptr->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 142 report_ptr->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
| 121 report_ptr->SetRequestContext(request_context_getter_.get()); | 143 report_ptr->SetRequestContext(request_context_getter_.get()); |
| 122 std::string post_data_base64; | 144 std::string post_data_base64; |
| 123 if (!hit_report.post_data.empty()) { | 145 if (!hit_report.post_data.empty()) { |
| 124 report_ptr->SetUploadData("text/plain", hit_report.post_data); | 146 report_ptr->SetUploadData("text/plain", hit_report.post_data); |
| 125 base::Base64Encode(hit_report.post_data, &post_data_base64); | 147 base::Base64Encode(hit_report.post_data, &post_data_base64); |
| 126 } | 148 } |
| 127 | 149 |
| 128 net_log_.BeginEvent( | 150 net_log_.BeginEvent( |
| 129 net::NetLogEventType::SAFE_BROWSING_PING, | 151 net::NetLogEventType::SAFE_BROWSING_PING, |
| 130 base::Bind(&NetLogPingStartCallback, net_log_, | 152 base::Bind(&NetLogPingStartCallback, net_log_, |
| 131 report_ptr->GetOriginalURL(), post_data_base64)); | 153 report_ptr->GetOriginalURL(), post_data_base64)); |
| 132 | 154 |
| 133 report->Start(); | 155 report->Start(); |
| 134 safebrowsing_reports_.insert(std::move(report_ptr)); | 156 safebrowsing_reports_.insert(std::move(report_ptr)); |
| 135 } | 157 } |
| 136 | 158 |
| 137 // Sends threat details for users who opt-in. | 159 // Sends threat details for users who opt-in. |
| 138 void BasePingManager::ReportThreatDetails(const std::string& report) { | 160 void BasePingManager::ReportThreatDetails(const std::string& report) { |
| 139 GURL report_url = ThreatDetailsUrl(); | 161 GURL report_url = ThreatDetailsUrl(); |
| 140 std::unique_ptr<net::URLFetcher> fetcher = | 162 net::NetworkTrafficAnnotationTag traffic_annotation = |
| 141 net::URLFetcher::Create(report_url, net::URLFetcher::POST, this); | 163 net::DefineNetworkTrafficAnnotation("...", R"( |
|
Nathan Parker
2017/04/14 21:32:23
Same as above. We'll eventually consolidate these
Ramin Halavati
2017/04/18 08:46:40
As they were the same, merged them into one consta
| |
| 164 semantics { | |
| 165 sender: "..." | |
| 166 description: "..." | |
| 167 trigger: "..." | |
| 168 data: "..." | |
| 169 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER | |
| 170 } | |
| 171 policy { | |
| 172 cookies_allowed: false/true | |
| 173 cookies_store: "..." | |
| 174 setting: "..." | |
| 175 chrome_policy { | |
| 176 [POLICY_NAME] { | |
| 177 policy_options {mode: MANDATORY/RECOMMENDED/UNSET} | |
| 178 [POLICY_NAME]: ... //(value to disable it) | |
| 179 } | |
| 180 } | |
| 181 policy_exception_justification: "..." | |
| 182 })"); | |
| 183 std::unique_ptr<net::URLFetcher> fetcher = net::URLFetcher::Create( | |
| 184 report_url, net::URLFetcher::POST, this, traffic_annotation); | |
| 142 data_use_measurement::DataUseUserData::AttachToFetcher( | 185 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 143 fetcher.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING); | 186 fetcher.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING); |
| 144 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 187 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
| 145 fetcher->SetRequestContext(request_context_getter_.get()); | 188 fetcher->SetRequestContext(request_context_getter_.get()); |
| 146 fetcher->SetUploadData("application/octet-stream", report); | 189 fetcher->SetUploadData("application/octet-stream", report); |
| 147 // Don't try too hard to send reports on failures. | 190 // Don't try too hard to send reports on failures. |
| 148 fetcher->SetAutomaticallyRetryOn5xx(false); | 191 fetcher->SetAutomaticallyRetryOn5xx(false); |
| 149 | 192 |
| 150 std::string report_base64; | 193 std::string report_base64; |
| 151 base::Base64Encode(report, &report_base64); | 194 base::Base64Encode(report, &report_base64); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 url_prefix_.c_str(), client_name_.c_str(), version_.c_str()); | 288 url_prefix_.c_str(), client_name_.c_str(), version_.c_str()); |
| 246 std::string api_key = google_apis::GetAPIKey(); | 289 std::string api_key = google_apis::GetAPIKey(); |
| 247 if (!api_key.empty()) { | 290 if (!api_key.empty()) { |
| 248 base::StringAppendF(&url, "&key=%s", | 291 base::StringAppendF(&url, "&key=%s", |
| 249 net::EscapeQueryParamValue(api_key, true).c_str()); | 292 net::EscapeQueryParamValue(api_key, true).c_str()); |
| 250 } | 293 } |
| 251 return GURL(url); | 294 return GURL(url); |
| 252 } | 295 } |
| 253 | 296 |
| 254 } // namespace safe_browsing | 297 } // namespace safe_browsing |
| OLD | NEW |