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

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

Issue 1509073002: Fixes for Safe Browsing with unrelated pending navigations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . 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/client_side_detection_host.h" 5 #include "chrome/browser/safe_browsing/client_side_detection_host.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 base::Bind(&ClientSideDetectionHost::OnPhishingPreClassificationDone, 398 base::Bind(&ClientSideDetectionHost::OnPhishingPreClassificationDone,
399 weak_factory_.GetWeakPtr()), 399 weak_factory_.GetWeakPtr()),
400 base::Bind(&ClientSideDetectionHost::OnMalwarePreClassificationDone, 400 base::Bind(&ClientSideDetectionHost::OnMalwarePreClassificationDone,
401 weak_factory_.GetWeakPtr()), 401 weak_factory_.GetWeakPtr()),
402 web_contents(), csd_service_, database_manager_.get(), this); 402 web_contents(), csd_service_, database_manager_.get(), this);
403 classification_request_->Start(); 403 classification_request_->Start();
404 } 404 }
405 405
406 void ClientSideDetectionHost::OnSafeBrowsingHit( 406 void ClientSideDetectionHost::OnSafeBrowsingHit(
407 const SafeBrowsingUIManager::UnsafeResource& resource) { 407 const SafeBrowsingUIManager::UnsafeResource& resource) {
408 if (!web_contents() || !web_contents()->GetController().GetActiveEntry()) 408 if (!web_contents())
Charlie Reis 2015/12/11 05:39:24 Unfortunately, you might still need a null check o
Nathan Parker 2015/12/11 19:48:06 How is web_contents_ different from what resource.
Charlie Reis 2015/12/11 21:10:04 resource.GetNavigationEntryForResource() handles t
mattm 2015/12/15 01:42:25 The UnsafeResource doesn't really have any enforce
mattm 2015/12/15 01:42:25 Thanks, done.
409 return; 409 return;
410 410
411 // Check that the hit is either malware or phishing. 411 // Check that the hit is either malware or phishing.
412 if (resource.threat_type != SB_THREAT_TYPE_URL_PHISHING && 412 if (resource.threat_type != SB_THREAT_TYPE_URL_PHISHING &&
413 resource.threat_type != SB_THREAT_TYPE_URL_MALWARE) 413 resource.threat_type != SB_THREAT_TYPE_URL_MALWARE)
414 return; 414 return;
415 415
416 // Check that this notification is really for us. 416 // Check that this notification is really for us.
417 content::RenderViewHost* hit_rvh = content::RenderViewHost::FromID( 417 content::RenderViewHost* hit_rvh = content::RenderViewHost::FromID(
418 resource.render_process_host_id, resource.render_view_id); 418 resource.render_process_host_id, resource.render_view_id);
419 if (!hit_rvh || 419 if (!hit_rvh ||
420 web_contents() != content::WebContents::FromRenderViewHost(hit_rvh)) 420 web_contents() != content::WebContents::FromRenderViewHost(hit_rvh))
421 return; 421 return;
422 422
423 // Store the unique page ID for later. 423 // Store the unique page ID for later.
424 unsafe_unique_page_id_ = 424 unsafe_unique_page_id_ =
425 web_contents()->GetController().GetActiveEntry()->GetUniqueID(); 425 resource.GetNavigationEntryForResource()->GetUniqueID();
426 426
427 // We also keep the resource around in order to be able to send the 427 // We also keep the resource around in order to be able to send the
428 // malicious URL to the server. 428 // malicious URL to the server.
429 unsafe_resource_.reset(new SafeBrowsingUIManager::UnsafeResource(resource)); 429 unsafe_resource_.reset(new SafeBrowsingUIManager::UnsafeResource(resource));
430 unsafe_resource_->callback.Reset(); // Don't do anything stupid. 430 unsafe_resource_->callback.Reset(); // Don't do anything stupid.
431 } 431 }
432 432
433 scoped_refptr<SafeBrowsingDatabaseManager> 433 scoped_refptr<SafeBrowsingDatabaseManager>
434 ClientSideDetectionHost::database_manager() { 434 ClientSideDetectionHost::database_manager() {
435 return database_manager_; 435 return database_manager_;
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 details.referrer, 667 details.referrer,
668 details.resource_type); 668 details.resource_type);
669 } 669 }
670 } 670 }
671 671
672 bool ClientSideDetectionHost::DidShowSBInterstitial() const { 672 bool ClientSideDetectionHost::DidShowSBInterstitial() const {
673 if (unsafe_unique_page_id_ <= 0 || !web_contents()) { 673 if (unsafe_unique_page_id_ <= 0 || !web_contents()) {
674 return false; 674 return false;
675 } 675 }
676 const NavigationEntry* nav_entry = 676 const NavigationEntry* nav_entry =
677 web_contents()->GetController().GetActiveEntry(); 677 web_contents()->GetController().GetLastCommittedEntry();
Charlie Reis 2015/12/11 05:39:24 Is this meant to be called while the interstitial
mattm 2015/12/15 01:42:25 If the interstitial was a blocking main page load,
678 return (nav_entry && nav_entry->GetUniqueID() == unsafe_unique_page_id_); 678 return (nav_entry && nav_entry->GetUniqueID() == unsafe_unique_page_id_);
679 } 679 }
680 680
681 void ClientSideDetectionHost::set_client_side_detection_service( 681 void ClientSideDetectionHost::set_client_side_detection_service(
682 ClientSideDetectionService* service) { 682 ClientSideDetectionService* service) {
683 csd_service_ = service; 683 csd_service_ = service;
684 } 684 }
685 685
686 void ClientSideDetectionHost::set_safe_browsing_managers( 686 void ClientSideDetectionHost::set_safe_browsing_managers(
687 SafeBrowsingUIManager* ui_manager, 687 SafeBrowsingUIManager* ui_manager,
688 SafeBrowsingDatabaseManager* database_manager) { 688 SafeBrowsingDatabaseManager* database_manager) {
689 if (ui_manager_.get()) 689 if (ui_manager_.get())
690 ui_manager_->RemoveObserver(this); 690 ui_manager_->RemoveObserver(this);
691 691
692 ui_manager_ = ui_manager; 692 ui_manager_ = ui_manager;
693 if (ui_manager) 693 if (ui_manager)
694 ui_manager_->AddObserver(this); 694 ui_manager_->AddObserver(this);
695 695
696 database_manager_ = database_manager; 696 database_manager_ = database_manager;
697 } 697 }
698 698
699 } // namespace safe_browsing 699 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698