Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3142)

Side by Side Diff: chrome/browser/safe_browsing/threat_details.cc

Issue 1509073002: Fixes for Safe Browsing with unrelated pending navigations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review changes for comment #10 Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Implementation of the ThreatDetails class. 5 // Implementation of the ThreatDetails class.
6 6
7 #include "chrome/browser/safe_browsing/threat_details.h" 7 #include "chrome/browser/safe_browsing/threat_details.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 175
176 void ThreatDetails::StartCollection() { 176 void ThreatDetails::StartCollection() {
177 DVLOG(1) << "Starting to compute threat details."; 177 DVLOG(1) << "Starting to compute threat details.";
178 report_.reset(new ClientSafeBrowsingReportRequest()); 178 report_.reset(new ClientSafeBrowsingReportRequest());
179 179
180 if (IsReportableUrl(resource_.url)) { 180 if (IsReportableUrl(resource_.url)) {
181 report_->set_url(resource_.url.spec()); 181 report_->set_url(resource_.url.spec());
182 report_->set_type(GetReportTypeFromSBThreatType(resource_.threat_type)); 182 report_->set_type(GetReportTypeFromSBThreatType(resource_.threat_type));
183 } 183 }
184 184
185 GURL page_url = web_contents()->GetURL(); 185 NavigationEntry* nav_entry = resource_.GetNavigationEntryForResource();
186
187 GURL page_url = nav_entry->GetURL();
Charlie Reis 2015/12/17 19:24:18 nav_entry might be null.
mattm 2015/12/18 21:41:04 Done, thanks for catching! I must have gotten inte
186 if (IsReportableUrl(page_url)) 188 if (IsReportableUrl(page_url))
187 report_->set_page_url(page_url.spec()); 189 report_->set_page_url(page_url.spec());
188 190
189 GURL referrer_url; 191 GURL referrer_url = nav_entry->GetReferrer().url;
190 NavigationEntry* nav_entry = web_contents()->GetController().GetActiveEntry(); 192 if (IsReportableUrl(referrer_url)) {
191 if (nav_entry) { 193 report_->set_referrer_url(referrer_url.spec());
192 referrer_url = nav_entry->GetReferrer().url;
193 if (IsReportableUrl(referrer_url)) {
194 report_->set_referrer_url(referrer_url.spec());
195 }
196 } 194 }
197 195
198 // Add the nodes, starting from the page url. 196 // Add the nodes, starting from the page url.
199 AddUrl(page_url, GURL(), std::string(), NULL); 197 AddUrl(page_url, GURL(), std::string(), NULL);
200 198
201 // Add the resource_url and its original url, if non-empty and different. 199 // Add the resource_url and its original url, if non-empty and different.
202 if (!resource_.original_url.is_empty() && 200 if (!resource_.original_url.is_empty() &&
203 resource_.url != resource_.original_url) { 201 resource_.url != resource_.original_url) {
204 // Add original_url, as the parent of resource_url. 202 // Add original_url, as the parent of resource_url.
205 AddUrl(resource_.original_url, GURL(), std::string(), NULL); 203 AddUrl(resource_.original_url, GURL(), std::string(), NULL);
(...skipping 11 matching lines...) Expand all
217 if (!resource_.original_url.is_empty()) 215 if (!resource_.original_url.is_empty())
218 parent_url = resource_.original_url; 216 parent_url = resource_.original_url;
219 217
220 // Set the previous redirect url as the parent of the next one 218 // Set the previous redirect url as the parent of the next one
221 for (size_t i = 0; i < resource_.redirect_urls.size(); ++i) { 219 for (size_t i = 0; i < resource_.redirect_urls.size(); ++i) {
222 AddUrl(resource_.redirect_urls[i], parent_url, std::string(), NULL); 220 AddUrl(resource_.redirect_urls[i], parent_url, std::string(), NULL);
223 parent_url = resource_.redirect_urls[i]; 221 parent_url = resource_.redirect_urls[i];
224 } 222 }
225 223
226 // Add the referrer url. 224 // Add the referrer url.
227 if (nav_entry && !referrer_url.is_empty()) 225 if (!referrer_url.is_empty())
228 AddUrl(referrer_url, GURL(), std::string(), NULL); 226 AddUrl(referrer_url, GURL(), std::string(), NULL);
229 227
230 if (!resource_.IsMainPageLoadBlocked()) { 228 if (!resource_.IsMainPageLoadBlocked()) {
231 // Get URLs of frames, scripts etc from the DOM. 229 // Get URLs of frames, scripts etc from the DOM.
232 // OnReceivedThreatDOMDetails will be called when the renderer replies. 230 // OnReceivedThreatDOMDetails will be called when the renderer replies.
233 // TODO(mattm): In theory, if the user proceeds through the warning DOM 231 // TODO(mattm): In theory, if the user proceeds through the warning DOM
234 // detail collection could be started once the page loads. 232 // detail collection could be started once the page loads.
235 content::RenderViewHost* view = web_contents()->GetRenderViewHost(); 233 content::RenderViewHost* view = web_contents()->GetRenderViewHost();
236 view->Send(new SafeBrowsingMsg_GetThreatDOMDetails(view->GetRoutingID())); 234 view->Send(new SafeBrowsingMsg_GetThreatDOMDetails(view->GetRoutingID()));
237 } 235 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 // Send the report, using the SafeBrowsingService. 337 // Send the report, using the SafeBrowsingService.
340 std::string serialized; 338 std::string serialized;
341 if (!report_->SerializeToString(&serialized)) { 339 if (!report_->SerializeToString(&serialized)) {
342 DLOG(ERROR) << "Unable to serialize the threat report."; 340 DLOG(ERROR) << "Unable to serialize the threat report.";
343 return; 341 return;
344 } 342 }
345 ui_manager_->SendSerializedThreatDetails(serialized); 343 ui_manager_->SendSerializedThreatDetails(serialized);
346 } 344 }
347 345
348 } // namespace safe_browsing 346 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698