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

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: 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 #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())
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 NavigationEntry *entry = resource.GetNavigationEntryForResource();
424 if (!entry)
425 return;
426
423 // Store the unique page ID for later. 427 // Store the unique page ID for later.
424 unsafe_unique_page_id_ = 428 unsafe_unique_page_id_ = entry->GetUniqueID();
425 web_contents()->GetController().GetActiveEntry()->GetUniqueID();
426 429
427 // We also keep the resource around in order to be able to send the 430 // We also keep the resource around in order to be able to send the
428 // malicious URL to the server. 431 // malicious URL to the server.
429 unsafe_resource_.reset(new SafeBrowsingUIManager::UnsafeResource(resource)); 432 unsafe_resource_.reset(new SafeBrowsingUIManager::UnsafeResource(resource));
430 unsafe_resource_->callback.Reset(); // Don't do anything stupid. 433 unsafe_resource_->callback.Reset(); // Don't do anything stupid.
431 } 434 }
432 435
433 scoped_refptr<SafeBrowsingDatabaseManager> 436 scoped_refptr<SafeBrowsingDatabaseManager>
434 ClientSideDetectionHost::database_manager() { 437 ClientSideDetectionHost::database_manager() {
435 return database_manager_; 438 return database_manager_;
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 details.method, 669 details.method,
667 details.referrer, 670 details.referrer,
668 details.resource_type); 671 details.resource_type);
669 } 672 }
670 } 673 }
671 674
672 bool ClientSideDetectionHost::DidShowSBInterstitial() const { 675 bool ClientSideDetectionHost::DidShowSBInterstitial() const {
673 if (unsafe_unique_page_id_ <= 0 || !web_contents()) { 676 if (unsafe_unique_page_id_ <= 0 || !web_contents()) {
674 return false; 677 return false;
675 } 678 }
679 // DidShowSBInterstitial is called after client side detection is finished to
680 // see if a SB interstitial was shown on the same page. Client Side Detection
681 // only runs on the currently committed page, so an unconditional
682 // GetLastCommittedEntry is correct here. GetNavigationEntryForResource cannot
683 // be used since it may no longer by valid (eg, if the UnsafeResource was for
Charlie Reis 2015/12/17 19:24:18 nit: s/by/be/
mattm 2015/12/18 21:41:04 Done.
684 // a blocking main page load which was then proceeded through).
676 const NavigationEntry* nav_entry = 685 const NavigationEntry* nav_entry =
677 web_contents()->GetController().GetActiveEntry(); 686 web_contents()->GetController().GetLastCommittedEntry();
678 return (nav_entry && nav_entry->GetUniqueID() == unsafe_unique_page_id_); 687 return (nav_entry && nav_entry->GetUniqueID() == unsafe_unique_page_id_);
679 } 688 }
680 689
681 void ClientSideDetectionHost::set_client_side_detection_service( 690 void ClientSideDetectionHost::set_client_side_detection_service(
682 ClientSideDetectionService* service) { 691 ClientSideDetectionService* service) {
683 csd_service_ = service; 692 csd_service_ = service;
684 } 693 }
685 694
686 void ClientSideDetectionHost::set_safe_browsing_managers( 695 void ClientSideDetectionHost::set_safe_browsing_managers(
687 SafeBrowsingUIManager* ui_manager, 696 SafeBrowsingUIManager* ui_manager,
688 SafeBrowsingDatabaseManager* database_manager) { 697 SafeBrowsingDatabaseManager* database_manager) {
689 if (ui_manager_.get()) 698 if (ui_manager_.get())
690 ui_manager_->RemoveObserver(this); 699 ui_manager_->RemoveObserver(this);
691 700
692 ui_manager_ = ui_manager; 701 ui_manager_ = ui_manager;
693 if (ui_manager) 702 if (ui_manager)
694 ui_manager_->AddObserver(this); 703 ui_manager_->AddObserver(this);
695 704
696 database_manager_ = database_manager; 705 database_manager_ = database_manager;
697 } 706 }
698 707
699 } // namespace safe_browsing 708 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698