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

Unified Diff: chrome/browser/safe_browsing/download_protection_service.cc

Issue 2601303002: Wireup SafeBrowsingNavigationObserverManager to help PPAPI download attribution (Closed)
Patch Set: nit Created 3 years, 12 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/download_protection_service.cc
diff --git a/chrome/browser/safe_browsing/download_protection_service.cc b/chrome/browser/safe_browsing/download_protection_service.cc
index cc34930f95ae5da4d718050233bcc952f30bcbf4..861c85f2a7c26c89829f8fce9b65dab4aa4bca7e 100644
--- a/chrome/browser/safe_browsing/download_protection_service.cc
+++ b/chrome/browser/safe_browsing/download_protection_service.cc
@@ -1230,6 +1230,8 @@ class DownloadProtectionService::PPAPIDownloadRequest
PPAPIDownloadRequest(
const GURL& requestor_url,
+ const GURL& initiating_frame_url,
+ content::WebContents* web_contents,
const base::FilePath& default_file_path,
const std::vector<base::FilePath::StringType>& alternate_extensions,
Profile* profile,
@@ -1237,6 +1239,8 @@ class DownloadProtectionService::PPAPIDownloadRequest
DownloadProtectionService* service,
scoped_refptr<SafeBrowsingDatabaseManager> database_manager)
: requestor_url_(requestor_url),
+ initiating_frame_url_(initiating_frame_url),
+ web_contents_(web_contents),
asanka 2017/01/05 18:00:44 not safe to store web_contents without observing i
Jialiu Lin 2017/01/05 20:12:21 Though my current code can work with null web_cont
asanka 2017/01/05 20:35:31 Cool. Though my worry here was that web_contents_
Jialiu Lin 2017/01/05 22:10:12 We can probably trust WebContents::FromRenderFrame
default_file_path_(default_file_path),
alternate_extensions_(alternate_extensions),
callback_(callback),
@@ -1359,8 +1363,10 @@ class DownloadProtectionService::PPAPIDownloadRequest
base::FilePath(default_file_path_.FinalExtension()).AsUTF8Unsafe();
}
- // TODO(676691): We should add reliable download referrer chain for PPAPI
- // downloads too.
+ service_->AddReferrerChainToPPAPIClientDownloadRequest(
+ initiating_frame_url_,
+ web_contents_,
+ &request);
if (!request.SerializeToString(&client_download_request_data_)) {
// More of an internal error than anything else. Note that the UNKNOWN
@@ -1484,6 +1490,12 @@ class DownloadProtectionService::PPAPIDownloadRequest
// URL of document that requested the PPAPI download.
const GURL requestor_url_;
+ // URL of the frame that hosted the PPAPI plugin.
+ const GURL initiating_frame_url_;
+
+ // WebContents that is associated with this PPAPI download.
+ content::WebContents* web_contents_;
+
// Default download path requested by the PPAPI plugin.
const base::FilePath default_file_path_;
@@ -1614,6 +1626,8 @@ bool DownloadProtectionService::IsSupportedDownload(
void DownloadProtectionService::CheckPPAPIDownloadRequest(
const GURL& requestor_url,
+ const GURL& initiating_frame_url,
+ content::WebContents* web_contents,
const base::FilePath& default_file_path,
const std::vector<base::FilePath::StringType>& alternate_extensions,
Profile* profile,
@@ -1621,8 +1635,8 @@ void DownloadProtectionService::CheckPPAPIDownloadRequest(
DVLOG(1) << __func__ << " url:" << requestor_url
<< " default_file_path:" << default_file_path.value();
std::unique_ptr<PPAPIDownloadRequest> request(new PPAPIDownloadRequest(
- requestor_url, default_file_path, alternate_extensions, profile, callback,
- this, database_manager_));
+ requestor_url, initiating_frame_url, web_contents, default_file_path,
+ alternate_extensions, profile, callback, this, database_manager_));
PPAPIDownloadRequest* request_copy = request.get();
auto insertion_result = ppapi_download_requests_.insert(
std::make_pair(request_copy, std::move(request)));
@@ -1808,7 +1822,7 @@ void DownloadProtectionService::AddReferrerChainToClientDownloadRequest(
download_tab_id == -1);
std::vector<ReferrerChainEntry> attribution_chain;
SafeBrowsingNavigationObserverManager::AttributionResult result =
- navigation_observer_manager_->IdentifyReferrerChain(
+ navigation_observer_manager_->IdentifyReferrerChainForDownload(
download_url,
download_tab_id,
kDownloadAttributionUserGestureLimit,
@@ -1823,4 +1837,31 @@ void DownloadProtectionService::AddReferrerChainToClientDownloadRequest(
out_request->add_referrer_chain()->Swap(&entry);
}
+void DownloadProtectionService::AddReferrerChainToPPAPIClientDownloadRequest(
+ const GURL& initiating_frame_url,
+ content::WebContents* web_contents,
+ ClientDownloadRequest* out_request) {
+ if (!base::FeatureList::IsEnabled(
+ SafeBrowsingNavigationObserverManager::kDownloadAttribution) ||
+ !navigation_observer_manager_) {
+ return;
+ }
+
+ std::vector<ReferrerChainEntry> attribution_chain;
+ SafeBrowsingNavigationObserverManager::AttributionResult result =
+ navigation_observer_manager_->IdentifyReferrerChainForPPAPIDownload(
+ initiating_frame_url,
+ web_contents,
+ kDownloadAttributionUserGestureLimit,
+ &attribution_chain);
+ UMA_HISTOGRAM_COUNTS_100(
+ "SafeBrowsing.ReferrerURLChainSize.PPAPIDownloadAttribution",
+ attribution_chain.size());
+ UMA_HISTOGRAM_ENUMERATION(
+ "SafeBrowsing.ReferrerAttributionResult.PPAPIDownloadAttribution", result,
+ SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX);
+ for (auto entry : attribution_chain)
+ out_request->add_referrer_chain()->Swap(&entry);
+}
+
} // namespace safe_browsing

Powered by Google App Engine
This is Rietveld 408576698