Report malware redirectors as well.
BUG=none
TEST=unit_tests
Review URL: http://codereview.chromium.org/3028040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55966 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/safe_browsing/protocol_manager.cc b/chrome/browser/safe_browsing/protocol_manager.cc
index 23ed348..611349b 100644
--- a/chrome/browser/safe_browsing/protocol_manager.cc
+++ b/chrome/browser/safe_browsing/protocol_manager.cc
@@ -589,8 +589,10 @@
void SafeBrowsingProtocolManager::ReportMalware(const GURL& malware_url,
const GURL& page_url,
- const GURL& referrer_url) {
- GURL report_url = MalwareReportUrl(malware_url, page_url, referrer_url);
+ const GURL& referrer_url,
+ bool is_subresource) {
+ GURL report_url = MalwareReportUrl(malware_url, page_url, referrer_url,
+ is_subresource);
URLFetcher* report = new URLFetcher(report_url, URLFetcher::GET, this);
report->set_load_flags(net::LOAD_DISABLE_CACHE);
report->set_request_context(request_context_getter_);
@@ -680,13 +682,14 @@
GURL SafeBrowsingProtocolManager::MalwareReportUrl(
const GURL& malware_url, const GURL& page_url,
- const GURL& referrer_url) const {
+ const GURL& referrer_url, bool is_subresource) const {
std::string url = ComposeUrl(info_url_prefix_, "report", client_name_,
version_, additional_query_);
- return GURL(StringPrintf("%s&evts=malblhit&evtd=%s&evtr=%s&evhr=%s",
+ return GURL(StringPrintf("%s&evts=malblhit&evtd=%s&evtr=%s&evhr=%s&evtb=%d",
url.c_str(), EscapeQueryParamValue(malware_url.spec(), true).c_str(),
EscapeQueryParamValue(page_url.spec(), true).c_str(),
- EscapeQueryParamValue(referrer_url.spec(), true).c_str()));
+ EscapeQueryParamValue(referrer_url.spec(), true).c_str(),
+ is_subresource));
}
GURL SafeBrowsingProtocolManager::NextChunkUrl(const std::string& url) const {
diff --git a/chrome/browser/safe_browsing/protocol_manager.h b/chrome/browser/safe_browsing/protocol_manager.h
index e0c1c321..37f85a2 100644
--- a/chrome/browser/safe_browsing/protocol_manager.h
+++ b/chrome/browser/safe_browsing/protocol_manager.h
@@ -111,7 +111,8 @@
// Reports a malware resource to the SafeBrowsing service.
void ReportMalware(const GURL& malware_url,
const GURL& page_url,
- const GURL& referrer_url);
+ const GURL& referrer_url,
+ bool is_subresource);
// Setter for additional_query_. To make sure the additional_query_ won't
// be changed in the middle of an update, caller (e.g.: SafeBrowsingService)
@@ -154,7 +155,7 @@
GURL MacKeyUrl() const;
// Generates URL for reporting malware pages.
GURL MalwareReportUrl(const GURL& malware_url, const GURL& page_url,
- const GURL& referrer_url) const;
+ const GURL& referrer_url, bool is_subresource) const;
// Composes a ChunkUrl based on input string.
GURL NextChunkUrl(const std::string& input) const;
diff --git a/chrome/browser/safe_browsing/protocol_manager_unittest.cc b/chrome/browser/safe_browsing/protocol_manager_unittest.cc
index 4f45893..1df9a431 100644
--- a/chrome/browser/safe_browsing/protocol_manager_unittest.cc
+++ b/chrome/browser/safe_browsing/protocol_manager_unittest.cc
@@ -204,16 +204,18 @@
EXPECT_EQ("http://info.prefix.com/foo/report?client=unittest&appver=1.0&"
"pver=2.2&evts=malblhit&evtd=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttp%2Fmalware.url.com%2F&"
"evtr=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttp%2Fpage.url.com%2F&evhr=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttp%2Freferrer."
- "url.com%2F",
- pm.MalwareReportUrl(malware_url, page_url, referrer_url).spec());
+ "url.com%2F&evtb=1",
+ pm.MalwareReportUrl(malware_url, page_url, referrer_url,
+ true).spec());
pm.set_additional_query("&additional_query");
EXPECT_EQ("http://info.prefix.com/foo/report?client=unittest&appver=1.0&"
"pver=2.2&additional_query&evts=malblhit&"
"evtd=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttp%2Fmalware.url.com%2F&"
"evtr=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttp%2Fpage.url.com%2F&evhr=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttp%2Freferrer."
- "url.com%2F",
- pm.MalwareReportUrl(malware_url, page_url, referrer_url).spec());
+ "url.com%2F&evtb=0",
+ pm.MalwareReportUrl(malware_url, page_url, referrer_url,
+ false).spec());
}
TEST_F(SafeBrowsingProtocolManagerTest, TestMacKeyUrl) {
diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc
index a5aaa12..dfcfaa02 100644
--- a/chrome/browser/safe_browsing/safe_browsing_service.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_service.cc
@@ -750,20 +750,24 @@
const MetricsService* metrics = g_browser_process->metrics_service();
DCHECK(metrics);
if (metrics && metrics->reporting_active() &&
- resource.resource_type != ResourceType::MAIN_FRAME &&
resource.threat_type == SafeBrowsingService::URL_MALWARE) {
GURL page_url = wc->GetURL();
GURL referrer_url;
NavigationEntry* entry = wc->controller().GetActiveEntry();
if (entry)
referrer_url = entry->referrer();
- ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- NewRunnableMethod(this,
- &SafeBrowsingService::ReportMalware,
- resource.url,
- page_url,
- referrer_url));
+
+ if (resource.url != page_url || !referrer_url.is_empty()) {
+ bool is_subresource = resource.resource_type != ResourceType::MAIN_FRAME;
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(this,
+ &SafeBrowsingService::ReportMalware,
+ resource.url,
+ page_url,
+ referrer_url,
+ is_subresource));
+ }
}
SafeBrowsingBlockingPage::ShowBlockingPage(this, resource);
@@ -771,7 +775,8 @@
void SafeBrowsingService::ReportMalware(const GURL& malware_url,
const GURL& page_url,
- const GURL& referrer_url) {
+ const GURL& referrer_url,
+ bool is_subresource) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
if (!enabled_)
@@ -779,7 +784,8 @@
if (DatabaseAvailable()) {
// Check if 'page_url' is already blacklisted (exists in our cache). Only
- // report if it's not there.
+ // report if it's not there. This can happen if the user has ignored
+ // the warning for page_url and is now hitting a warning for a resource.
std::string list;
std::vector<SBPrefix> prefix_hits;
std::vector<SBFullHashResult> full_hits;
@@ -789,5 +795,6 @@
return;
}
- protocol_manager_->ReportMalware(malware_url, page_url, referrer_url);
+ protocol_manager_->ReportMalware(malware_url, page_url, referrer_url,
+ is_subresource);
}
diff --git a/chrome/browser/safe_browsing/safe_browsing_service.h b/chrome/browser/safe_browsing/safe_browsing_service.h
index 9ca369b..83b57eb 100644
--- a/chrome/browser/safe_browsing/safe_browsing_service.h
+++ b/chrome/browser/safe_browsing/safe_browsing_service.h
@@ -266,7 +266,8 @@
// service.
void ReportMalware(const GURL& malware_url,
const GURL& page_url,
- const GURL& referrer_url);
+ const GURL& referrer_url,
+ bool is_subresource);
CurrentChecks checks_;