Chromium Code Reviews| Index: chrome/browser/safe_browsing/client_side_detection_host.cc |
| diff --git a/chrome/browser/safe_browsing/client_side_detection_host.cc b/chrome/browser/safe_browsing/client_side_detection_host.cc |
| index 6eeb6f7d60d378e3f65a3ec079a2dce0472dd0cd..31b19807aa1a07aa8183581afd34f78d1b0a6db8 100644 |
| --- a/chrome/browser/safe_browsing/client_side_detection_host.cc |
| +++ b/chrome/browser/safe_browsing/client_side_detection_host.cc |
| @@ -12,6 +12,7 @@ |
| #include "base/metrics/histogram.h" |
| #include "base/prefs/pref_service.h" |
| #include "base/sequenced_task_runner_helpers.h" |
| +#include "base/strings/utf_string_conversions.h" |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/safe_browsing/browser_feature_extractor.h" |
| @@ -47,6 +48,8 @@ namespace safe_browsing { |
| const int ClientSideDetectionHost::kMaxUrlsPerIP = 20; |
| const int ClientSideDetectionHost::kMaxIPsPerBrowse = 200; |
| +const char kSafeBrowsingMatchKey[] = "safe_browsing_match"; |
| + |
| // This class is instantiated each time a new toplevel URL loads, and |
| // asynchronously checks whether the phishing classifier should run for this |
| // URL. If so, it notifies the renderer with a StartPhishingDetection IPC. |
| @@ -248,8 +251,7 @@ ClientSideDetectionHost::ClientSideDetectionHost(WebContents* tab) |
| weak_factory_(this), |
| unsafe_unique_page_id_(-1), |
| malware_killswitch_on_(false), |
| - malware_report_enabled_(false), |
| - malware_or_phishing_match_(false) { |
| + malware_report_enabled_(false) { |
| DCHECK(tab); |
| // Note: csd_service_ and sb_service will be NULL here in testing. |
| csd_service_ = g_browser_process->safe_browsing_detection_service(); |
| @@ -291,8 +293,6 @@ bool ClientSideDetectionHost::OnMessageReceived(const IPC::Message& message) { |
| void ClientSideDetectionHost::DidNavigateMainFrame( |
| const content::LoadCommittedDetails& details, |
| const content::FrameNavigateParams& params) { |
| - malware_or_phishing_match_ = false; |
| - |
| // TODO(noelutz): move this DCHECK to WebContents and fix all the unit tests |
| // that don't call this method on the UI thread. |
| // DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| @@ -355,6 +355,7 @@ void ClientSideDetectionHost::OnSafeBrowsingHit( |
| // Store the unique page ID for later. |
| unsafe_unique_page_id_ = |
| web_contents()->GetController().GetActiveEntry()->GetUniqueID(); |
| + |
| // We also keep the resource around in order to be able to send the |
| // malicious URL to the server. |
| unsafe_resource_.reset(new SafeBrowsingUIManager::UnsafeResource(resource)); |
| @@ -363,7 +364,18 @@ void ClientSideDetectionHost::OnSafeBrowsingHit( |
| void ClientSideDetectionHost::OnSafeBrowsingMatch( |
| const SafeBrowsingUIManager::UnsafeResource& resource) { |
| - malware_or_phishing_match_ = true; |
| + if (!web_contents() || !web_contents()->GetController().GetActiveEntry()) |
| + return; |
| + |
| + // Check that this notification is really for us. |
| + content::RenderViewHost* hit_rvh = content::RenderViewHost::FromID( |
| + resource.render_process_host_id, resource.render_view_id); |
| + if (!hit_rvh || |
| + web_contents() != content::WebContents::FromRenderViewHost(hit_rvh)) |
| + return; |
| + |
| + web_contents()->GetController().GetActiveEntry()->SetExtraData( |
| + kSafeBrowsingMatchKey, base::ASCIIToUTF16("1")); |
| } |
| scoped_refptr<SafeBrowsingDatabaseManager> |
| @@ -372,7 +384,15 @@ ClientSideDetectionHost::database_manager() { |
| } |
| bool ClientSideDetectionHost::DidPageReceiveSafeBrowsingMatch() const { |
| - return malware_or_phishing_match_ || DidShowSBInterstitial(); |
| + if (!web_contents() || !web_contents()->GetController().GetActiveEntry()) |
| + return false; |
| + |
| + NavigationEntry* entry = web_contents()->GetController().GetPendingEntry(); |
|
mattm
2013/12/16 23:28:51
I think there should still be some comment about t
Greg Billock
2013/12/16 23:59:43
drat. That got dropped in the shuffle. Done.
|
| + if (!entry) |
| + entry = web_contents()->GetController().GetActiveEntry(); |
| + |
| + base::string16 value; |
| + return entry->GetExtraData(kSafeBrowsingMatchKey, &value); |
| } |
| void ClientSideDetectionHost::WebContentsDestroyed(WebContents* tab) { |