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

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 #13-15 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 GURL referrer_url;
186 if (IsReportableUrl(page_url)) 186 NavigationEntry* nav_entry = resource_.GetNavigationEntryForResource();
187 report_->set_page_url(page_url.spec()); 187 if (nav_entry) {
188 GURL page_url = nav_entry->GetURL();
189 if (IsReportableUrl(page_url))
190 report_->set_page_url(page_url.spec());
188 191
189 GURL referrer_url;
190 NavigationEntry* nav_entry = web_contents()->GetController().GetActiveEntry();
191 if (nav_entry) {
192 referrer_url = nav_entry->GetReferrer().url; 192 referrer_url = nav_entry->GetReferrer().url;
193 if (IsReportableUrl(referrer_url)) { 193 if (IsReportableUrl(referrer_url))
194 report_->set_referrer_url(referrer_url.spec()); 194 report_->set_referrer_url(referrer_url.spec());
195 } 195
196 // Add the nodes, starting from the page url.
197 AddUrl(page_url, GURL(), std::string(), NULL);
196 } 198 }
197 199
198 // Add the nodes, starting from the page url.
199 AddUrl(page_url, GURL(), std::string(), NULL);
200
201 // Add the resource_url and its original url, if non-empty and different. 200 // Add the resource_url and its original url, if non-empty and different.
202 if (!resource_.original_url.is_empty() && 201 if (!resource_.original_url.is_empty() &&
203 resource_.url != resource_.original_url) { 202 resource_.url != resource_.original_url) {
204 // Add original_url, as the parent of resource_url. 203 // Add original_url, as the parent of resource_url.
205 AddUrl(resource_.original_url, GURL(), std::string(), NULL); 204 AddUrl(resource_.original_url, GURL(), std::string(), NULL);
206 AddUrl(resource_.url, resource_.original_url, std::string(), NULL); 205 AddUrl(resource_.url, resource_.original_url, std::string(), NULL);
207 } else { 206 } else {
208 AddUrl(resource_.url, GURL(), std::string(), NULL); 207 AddUrl(resource_.url, GURL(), std::string(), NULL);
209 } 208 }
210 209
211 // Add the redirect urls, if non-empty. The redirect urls do not include the 210 // Add the redirect urls, if non-empty. The redirect urls do not include the
212 // original url, but include the unsafe url which is the last one of the 211 // original url, but include the unsafe url which is the last one of the
213 // redirect urls chain 212 // redirect urls chain
214 GURL parent_url; 213 GURL parent_url;
215 // Set the original url as the parent of the first redirect url if it's not 214 // Set the original url as the parent of the first redirect url if it's not
216 // empty. 215 // empty.
217 if (!resource_.original_url.is_empty()) 216 if (!resource_.original_url.is_empty())
218 parent_url = resource_.original_url; 217 parent_url = resource_.original_url;
219 218
220 // Set the previous redirect url as the parent of the next one 219 // Set the previous redirect url as the parent of the next one
221 for (size_t i = 0; i < resource_.redirect_urls.size(); ++i) { 220 for (size_t i = 0; i < resource_.redirect_urls.size(); ++i) {
222 AddUrl(resource_.redirect_urls[i], parent_url, std::string(), NULL); 221 AddUrl(resource_.redirect_urls[i], parent_url, std::string(), NULL);
223 parent_url = resource_.redirect_urls[i]; 222 parent_url = resource_.redirect_urls[i];
224 } 223 }
225 224
226 // Add the referrer url. 225 // Add the referrer url.
227 if (nav_entry && !referrer_url.is_empty()) 226 if (!referrer_url.is_empty())
228 AddUrl(referrer_url, GURL(), std::string(), NULL); 227 AddUrl(referrer_url, GURL(), std::string(), NULL);
229 228
230 if (!resource_.IsMainPageLoadBlocked()) { 229 if (!resource_.IsMainPageLoadBlocked()) {
231 // Get URLs of frames, scripts etc from the DOM. 230 // Get URLs of frames, scripts etc from the DOM.
232 // OnReceivedThreatDOMDetails will be called when the renderer replies. 231 // OnReceivedThreatDOMDetails will be called when the renderer replies.
233 // TODO(mattm): In theory, if the user proceeds through the warning DOM 232 // TODO(mattm): In theory, if the user proceeds through the warning DOM
234 // detail collection could be started once the page loads. 233 // detail collection could be started once the page loads.
235 content::RenderViewHost* view = web_contents()->GetRenderViewHost(); 234 content::RenderViewHost* view = web_contents()->GetRenderViewHost();
236 view->Send(new SafeBrowsingMsg_GetThreatDOMDetails(view->GetRoutingID())); 235 view->Send(new SafeBrowsingMsg_GetThreatDOMDetails(view->GetRoutingID()));
237 } 236 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 // Send the report, using the SafeBrowsingService. 338 // Send the report, using the SafeBrowsingService.
340 std::string serialized; 339 std::string serialized;
341 if (!report_->SerializeToString(&serialized)) { 340 if (!report_->SerializeToString(&serialized)) {
342 DLOG(ERROR) << "Unable to serialize the threat report."; 341 DLOG(ERROR) << "Unable to serialize the threat report.";
343 return; 342 return;
344 } 343 }
345 ui_manager_->SendSerializedThreatDetails(serialized); 344 ui_manager_->SendSerializedThreatDetails(serialized);
346 } 345 }
347 346
348 } // namespace safe_browsing 347 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698