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

Side by Side Diff: chrome/browser/safe_browsing/ui_manager.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 #include "chrome/browser/safe_browsing/ui_manager.h" 5 #include "chrome/browser/safe_browsing/ui_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/debug/leak_tracker.h" 10 #include "base/debug/leak_tracker.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // Client-side phishing detection interstitials never block the main frame 81 // Client-side phishing detection interstitials never block the main frame
82 // load, since they happen after the page is finished loading. 82 // load, since they happen after the page is finished loading.
83 if (threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL || 83 if (threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL ||
84 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) { 84 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) {
85 return false; 85 return false;
86 } 86 }
87 87
88 return true; 88 return true;
89 } 89 }
90 90
91 content::NavigationEntry*
92 SafeBrowsingUIManager::UnsafeResource::GetNavigationEntryForResource() const {
93 WebContents* contents =
94 tab_util::GetWebContentsByID(render_process_host_id, render_view_id);
95 if (!contents)
96 return nullptr;
97 // If a safebrowsing hit occurs during main frame navigation, the navigation
98 // will not be committed, and the pending navigation entry refers to the hit.
99 if (IsMainPageLoadBlocked())
100 return contents->GetController().GetPendingEntry();
101 // If a safebrowsing hit occurs on a subresource load, or on a main frame
102 // after the navigation is committed, the last committed navigation entry
103 // refers to the page with the hit. Note that there may concurrently be an
104 // unrelated pending navigation to another site, so GetActiveEntry() would be
105 // wrong.
106 return contents->GetController().GetLastCommittedEntry();
107 }
108
91 // SafeBrowsingUIManager ------------------------------------------------------- 109 // SafeBrowsingUIManager -------------------------------------------------------
92 110
93 SafeBrowsingUIManager::SafeBrowsingUIManager( 111 SafeBrowsingUIManager::SafeBrowsingUIManager(
94 const scoped_refptr<SafeBrowsingService>& service) 112 const scoped_refptr<SafeBrowsingService>& service)
95 : sb_service_(service) {} 113 : sb_service_(service) {}
96 114
97 SafeBrowsingUIManager::~SafeBrowsingUIManager() {} 115 SafeBrowsingUIManager::~SafeBrowsingUIManager() {}
98 116
99 void SafeBrowsingUIManager::StopOnIOThread(bool shutdown) { 117 void SafeBrowsingUIManager::StopOnIOThread(bool shutdown) {
100 DCHECK_CURRENTLY_ON(BrowserThread::IO); 118 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 DCHECK(resource.callback_thread); 185 DCHECK(resource.callback_thread);
168 resource.callback_thread->PostTask(FROM_HERE, 186 resource.callback_thread->PostTask(FROM_HERE,
169 base::Bind(resource.callback, true)); 187 base::Bind(resource.callback, true));
170 } 188 }
171 return; 189 return;
172 } 190 }
173 191
174 if (resource.threat_type != SB_THREAT_TYPE_SAFE) { 192 if (resource.threat_type != SB_THREAT_TYPE_SAFE) {
175 HitReport hit_report; 193 HitReport hit_report;
176 hit_report.malicious_url = resource.url; 194 hit_report.malicious_url = resource.url;
177 hit_report.page_url = web_contents->GetURL();
178 hit_report.is_subresource = resource.is_subresource; 195 hit_report.is_subresource = resource.is_subresource;
179 hit_report.threat_type = resource.threat_type; 196 hit_report.threat_type = resource.threat_type;
180 hit_report.threat_source = resource.threat_source; 197 hit_report.threat_source = resource.threat_source;
181 198
182 NavigationEntry* entry = web_contents->GetController().GetActiveEntry(); 199 NavigationEntry* entry = resource.GetNavigationEntryForResource();
183 if (entry) 200 if (entry) {
201 hit_report.page_url = entry->GetURL();
184 hit_report.referrer_url = entry->GetReferrer().url; 202 hit_report.referrer_url = entry->GetReferrer().url;
203 }
185 204
186 // When the malicious url is on the main frame, and resource.original_url 205 // When the malicious url is on the main frame, and resource.original_url
187 // is not the same as the resource.url, that means we have a redirect from 206 // is not the same as the resource.url, that means we have a redirect from
188 // resource.original_url to resource.url. 207 // resource.original_url to resource.url.
189 // Also, at this point, page_url points to the _previous_ page that we 208 // Also, at this point, page_url points to the _previous_ page that we
190 // were on. We replace page_url with resource.original_url and referrer 209 // were on. We replace page_url with resource.original_url and referrer
191 // with page_url. 210 // with page_url.
192 if (!resource.is_subresource && 211 if (!resource.is_subresource &&
193 !resource.original_url.is_empty() && 212 !resource.original_url.is_empty() &&
194 resource.original_url != resource.url) { 213 resource.original_url != resource.url) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 WebContents* web_contents = tab_util::GetWebContentsByID( 323 WebContents* web_contents = tab_util::GetWebContentsByID(
305 resource.render_process_host_id, resource.render_view_id); 324 resource.render_process_host_id, resource.render_view_id);
306 325
307 WhitelistUrlSet* site_list = 326 WhitelistUrlSet* site_list =
308 static_cast<WhitelistUrlSet*>(web_contents->GetUserData(kWhitelistKey)); 327 static_cast<WhitelistUrlSet*>(web_contents->GetUserData(kWhitelistKey));
309 if (!site_list) { 328 if (!site_list) {
310 site_list = new WhitelistUrlSet; 329 site_list = new WhitelistUrlSet;
311 web_contents->SetUserData(kWhitelistKey, site_list); 330 web_contents->SetUserData(kWhitelistKey, site_list);
312 } 331 }
313 332
314 GURL whitelisted_url(resource.is_subresource ? web_contents->GetVisibleURL() 333 GURL whitelisted_url;
315 : resource.url); 334 if (resource.is_subresource) {
335 NavigationEntry* entry = resource.GetNavigationEntryForResource();
336 if (!entry)
337 return;
338 whitelisted_url = entry->GetURL();
339 } else {
340 whitelisted_url = resource.url;
341 }
342
316 site_list->Insert(whitelisted_url); 343 site_list->Insert(whitelisted_url);
317 } 344 }
318 345
319 // Check if the user has already ignored a SB warning for this WebContents and 346 // Check if the user has already ignored a SB warning for this WebContents and
320 // top-level domain. 347 // top-level domain.
321 bool SafeBrowsingUIManager::IsWhitelisted(const UnsafeResource& resource) { 348 bool SafeBrowsingUIManager::IsWhitelisted(const UnsafeResource& resource) {
322 DCHECK_CURRENTLY_ON(BrowserThread::UI); 349 DCHECK_CURRENTLY_ON(BrowserThread::UI);
323 WebContents* web_contents = tab_util::GetWebContentsByID( 350 WebContents* web_contents = tab_util::GetWebContentsByID(
324 resource.render_process_host_id, resource.render_view_id); 351 resource.render_process_host_id, resource.render_view_id);
325 352
326 GURL maybe_whitelisted_url( 353 GURL maybe_whitelisted_url;
327 resource.is_subresource ? web_contents->GetVisibleURL() : resource.url); 354 if (resource.is_subresource) {
355 NavigationEntry* entry = resource.GetNavigationEntryForResource();
356 if (!entry)
357 return false;
358 maybe_whitelisted_url = entry->GetURL();
359 } else {
360 maybe_whitelisted_url = resource.url;
361 }
362
328 WhitelistUrlSet* site_list = 363 WhitelistUrlSet* site_list =
329 static_cast<WhitelistUrlSet*>(web_contents->GetUserData(kWhitelistKey)); 364 static_cast<WhitelistUrlSet*>(web_contents->GetUserData(kWhitelistKey));
330 if (!site_list) 365 if (!site_list)
331 return false; 366 return false;
332 return site_list->Contains(maybe_whitelisted_url); 367 return site_list->Contains(maybe_whitelisted_url);
333 } 368 }
334 369
335 } // namespace safe_browsing 370 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/ui_manager.h ('k') | chrome/browser/safe_browsing/ui_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698