| OLD | NEW |
| 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/download_protection_service.h" | 5 #include "chrome/browser/safe_browsing/download_protection_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 1047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 .AsUTF8Unsafe()); | 1058 .AsUTF8Unsafe()); |
| 1059 } else { | 1059 } else { |
| 1060 request.set_file_basename( | 1060 request.set_file_basename( |
| 1061 item_->GetTargetFilePath().BaseName().AsUTF8Unsafe()); | 1061 item_->GetTargetFilePath().BaseName().AsUTF8Unsafe()); |
| 1062 } | 1062 } |
| 1063 request.set_download_type(type_); | 1063 request.set_download_type(type_); |
| 1064 | 1064 |
| 1065 ReferrerChainData* referrer_chain_data = | 1065 ReferrerChainData* referrer_chain_data = |
| 1066 static_cast<ReferrerChainData*>( | 1066 static_cast<ReferrerChainData*>( |
| 1067 item_->GetUserData(kDownloadReferrerChainDataKey)); | 1067 item_->GetUserData(kDownloadReferrerChainDataKey)); |
| 1068 if (referrer_chain_data && | 1068 if (referrer_chain_data) { |
| 1069 !referrer_chain_data->GetReferrerChain()->empty()) { | 1069 request.set_download_attribution_finch_enabled(true); |
| 1070 request.mutable_referrer_chain()->Swap( | 1070 if (!referrer_chain_data->GetReferrerChain()->empty()) { |
| 1071 referrer_chain_data->GetReferrerChain()); | 1071 request.mutable_referrer_chain()->Swap( |
| 1072 referrer_chain_data->GetReferrerChain()); |
| 1073 } |
| 1072 } | 1074 } |
| 1073 | 1075 |
| 1074 if (archive_is_valid_ != ArchiveValid::UNSET) | 1076 if (archive_is_valid_ != ArchiveValid::UNSET) |
| 1075 request.set_archive_valid(archive_is_valid_ == ArchiveValid::VALID); | 1077 request.set_archive_valid(archive_is_valid_ == ArchiveValid::VALID); |
| 1076 request.mutable_signature()->CopyFrom(signature_info_); | 1078 request.mutable_signature()->CopyFrom(signature_info_); |
| 1077 if (image_headers_) | 1079 if (image_headers_) |
| 1078 request.set_allocated_image_headers(image_headers_.release()); | 1080 request.set_allocated_image_headers(image_headers_.release()); |
| 1079 if (archived_executable_) | 1081 if (archived_executable_) |
| 1080 request.mutable_archived_binary()->Swap(&archived_binary_); | 1082 request.mutable_archived_binary()->Swap(&archived_binary_); |
| 1081 if (!request.SerializeToString(&client_download_request_data_)) { | 1083 if (!request.SerializeToString(&client_download_request_data_)) { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1293 const GURL& initiating_frame_url, | 1295 const GURL& initiating_frame_url, |
| 1294 content::WebContents* web_contents, | 1296 content::WebContents* web_contents, |
| 1295 const base::FilePath& default_file_path, | 1297 const base::FilePath& default_file_path, |
| 1296 const std::vector<base::FilePath::StringType>& alternate_extensions, | 1298 const std::vector<base::FilePath::StringType>& alternate_extensions, |
| 1297 Profile* profile, | 1299 Profile* profile, |
| 1298 const CheckDownloadCallback& callback, | 1300 const CheckDownloadCallback& callback, |
| 1299 DownloadProtectionService* service, | 1301 DownloadProtectionService* service, |
| 1300 scoped_refptr<SafeBrowsingDatabaseManager> database_manager) | 1302 scoped_refptr<SafeBrowsingDatabaseManager> database_manager) |
| 1301 : requestor_url_(requestor_url), | 1303 : requestor_url_(requestor_url), |
| 1302 initiating_frame_url_(initiating_frame_url), | 1304 initiating_frame_url_(initiating_frame_url), |
| 1305 initiating_main_frame_url_( |
| 1306 web_contents ? web_contents->GetLastCommittedURL() : GURL()), |
| 1303 tab_id_(SessionTabHelper::IdForTab(web_contents)), | 1307 tab_id_(SessionTabHelper::IdForTab(web_contents)), |
| 1304 default_file_path_(default_file_path), | 1308 default_file_path_(default_file_path), |
| 1305 alternate_extensions_(alternate_extensions), | 1309 alternate_extensions_(alternate_extensions), |
| 1306 callback_(callback), | 1310 callback_(callback), |
| 1307 service_(service), | 1311 service_(service), |
| 1308 database_manager_(database_manager), | 1312 database_manager_(database_manager), |
| 1309 start_time_(base::TimeTicks::Now()), | 1313 start_time_(base::TimeTicks::Now()), |
| 1310 supported_path_( | 1314 supported_path_( |
| 1311 GetSupportedFilePath(default_file_path, alternate_extensions)), | 1315 GetSupportedFilePath(default_file_path, alternate_extensions)), |
| 1312 weakptr_factory_(this) { | 1316 weakptr_factory_(this) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1426 DCHECK_EQ(base::FilePath::kExtensionSeparator, alternate_extension[0]); | 1430 DCHECK_EQ(base::FilePath::kExtensionSeparator, alternate_extension[0]); |
| 1427 *(request.add_alternate_extensions()) = | 1431 *(request.add_alternate_extensions()) = |
| 1428 base::FilePath(alternate_extension).AsUTF8Unsafe(); | 1432 base::FilePath(alternate_extension).AsUTF8Unsafe(); |
| 1429 } | 1433 } |
| 1430 if (supported_path_ != default_file_path_) { | 1434 if (supported_path_ != default_file_path_) { |
| 1431 *(request.add_alternate_extensions()) = | 1435 *(request.add_alternate_extensions()) = |
| 1432 base::FilePath(default_file_path_.FinalExtension()).AsUTF8Unsafe(); | 1436 base::FilePath(default_file_path_.FinalExtension()).AsUTF8Unsafe(); |
| 1433 } | 1437 } |
| 1434 | 1438 |
| 1435 service_->AddReferrerChainToPPAPIClientDownloadRequest( | 1439 service_->AddReferrerChainToPPAPIClientDownloadRequest( |
| 1436 initiating_frame_url_, | 1440 initiating_frame_url_, initiating_main_frame_url_, tab_id_, |
| 1437 tab_id_, | 1441 has_user_gesture_, &request); |
| 1438 has_user_gesture_, | |
| 1439 &request); | |
| 1440 | 1442 |
| 1441 if (!request.SerializeToString(&client_download_request_data_)) { | 1443 if (!request.SerializeToString(&client_download_request_data_)) { |
| 1442 // More of an internal error than anything else. Note that the UNKNOWN | 1444 // More of an internal error than anything else. Note that the UNKNOWN |
| 1443 // verdict gets interpreted as "allowed". | 1445 // verdict gets interpreted as "allowed". |
| 1444 Finish(RequestOutcome::REQUEST_MALFORMED, UNKNOWN); | 1446 Finish(RequestOutcome::REQUEST_MALFORMED, UNKNOWN); |
| 1445 return; | 1447 return; |
| 1446 } | 1448 } |
| 1447 | 1449 |
| 1448 service_->ppapi_download_request_callbacks_.Notify(&request); | 1450 service_->ppapi_download_request_callbacks_.Notify(&request); |
| 1449 DVLOG(2) << "Sending a PPAPI download request for URL: " << request.url(); | 1451 DVLOG(2) << "Sending a PPAPI download request for URL: " << request.url(); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1553 | 1555 |
| 1554 return base::FilePath(); | 1556 return base::FilePath(); |
| 1555 } | 1557 } |
| 1556 | 1558 |
| 1557 std::unique_ptr<net::URLFetcher> fetcher_; | 1559 std::unique_ptr<net::URLFetcher> fetcher_; |
| 1558 std::string client_download_request_data_; | 1560 std::string client_download_request_data_; |
| 1559 | 1561 |
| 1560 // URL of document that requested the PPAPI download. | 1562 // URL of document that requested the PPAPI download. |
| 1561 const GURL requestor_url_; | 1563 const GURL requestor_url_; |
| 1562 | 1564 |
| 1563 // URL of the frame that hosted the PPAPI plugin. | 1565 // URL of the frame that hosts the PPAPI plugin. |
| 1564 const GURL initiating_frame_url_; | 1566 const GURL initiating_frame_url_; |
| 1565 | 1567 |
| 1568 // URL of the tab that contains the initialting_frame. |
| 1569 const GURL initiating_main_frame_url_; |
| 1570 |
| 1566 // Tab id that associated with the PPAPI plugin, computed by | 1571 // Tab id that associated with the PPAPI plugin, computed by |
| 1567 // SessionTabHelper::IdForTab(). | 1572 // SessionTabHelper::IdForTab(). |
| 1568 int tab_id_; | 1573 int tab_id_; |
| 1569 | 1574 |
| 1570 // If the user interacted with this PPAPI plugin to trigger the download. | 1575 // If the user interacted with this PPAPI plugin to trigger the download. |
| 1571 bool has_user_gesture_; | 1576 bool has_user_gesture_; |
| 1572 | 1577 |
| 1573 // Default download path requested by the PPAPI plugin. | 1578 // Default download path requested by the PPAPI plugin. |
| 1574 const base::FilePath default_file_path_; | 1579 const base::FilePath default_file_path_; |
| 1575 | 1580 |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1899 UMA_HISTOGRAM_COUNTS_100( | 1904 UMA_HISTOGRAM_COUNTS_100( |
| 1900 "SafeBrowsing.ReferrerURLChainSize.DownloadAttribution", | 1905 "SafeBrowsing.ReferrerURLChainSize.DownloadAttribution", |
| 1901 referrer_chain->size()); | 1906 referrer_chain->size()); |
| 1902 UMA_HISTOGRAM_ENUMERATION( | 1907 UMA_HISTOGRAM_ENUMERATION( |
| 1903 "SafeBrowsing.ReferrerAttributionResult.DownloadAttribution", result, | 1908 "SafeBrowsing.ReferrerAttributionResult.DownloadAttribution", result, |
| 1904 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); | 1909 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); |
| 1905 return referrer_chain; | 1910 return referrer_chain; |
| 1906 } | 1911 } |
| 1907 | 1912 |
| 1908 void DownloadProtectionService::AddReferrerChainToPPAPIClientDownloadRequest( | 1913 void DownloadProtectionService::AddReferrerChainToPPAPIClientDownloadRequest( |
| 1909 const GURL& initiating_frame_url, | 1914 const GURL& initiating_frame_url, |
| 1910 int tab_id, | 1915 const GURL& initiating_main_frame_url, |
| 1911 bool has_user_gesture, | 1916 int tab_id, |
| 1912 ClientDownloadRequest* out_request) { | 1917 bool has_user_gesture, |
| 1918 ClientDownloadRequest* out_request) { |
| 1913 if (!base::FeatureList::IsEnabled( | 1919 if (!base::FeatureList::IsEnabled( |
| 1914 SafeBrowsingNavigationObserverManager::kDownloadAttribution) || | 1920 SafeBrowsingNavigationObserverManager::kDownloadAttribution) || |
| 1915 !navigation_observer_manager_) { | 1921 !navigation_observer_manager_) { |
| 1916 return; | 1922 return; |
| 1917 } | 1923 } |
| 1918 | 1924 |
| 1919 UMA_HISTOGRAM_BOOLEAN( | 1925 UMA_HISTOGRAM_BOOLEAN( |
| 1920 "SafeBrowsing.ReferrerHasInvalidTabID.DownloadAttribution", | 1926 "SafeBrowsing.ReferrerHasInvalidTabID.DownloadAttribution", |
| 1921 tab_id == -1); | 1927 tab_id == -1); |
| 1922 SafeBrowsingNavigationObserverManager::AttributionResult result = | 1928 SafeBrowsingNavigationObserverManager::AttributionResult result = |
| 1923 navigation_observer_manager_->IdentifyReferrerChainForPPAPIDownload( | 1929 navigation_observer_manager_->IdentifyReferrerChainForPPAPIDownload( |
| 1924 initiating_frame_url, | 1930 initiating_frame_url, initiating_main_frame_url, tab_id, |
| 1925 tab_id, | 1931 has_user_gesture, kDownloadAttributionUserGestureLimit, |
| 1926 has_user_gesture, | |
| 1927 kDownloadAttributionUserGestureLimit, | |
| 1928 out_request->mutable_referrer_chain()); | 1932 out_request->mutable_referrer_chain()); |
| 1929 UMA_HISTOGRAM_COUNTS_100( | 1933 UMA_HISTOGRAM_COUNTS_100( |
| 1930 "SafeBrowsing.ReferrerURLChainSize.PPAPIDownloadAttribution", | 1934 "SafeBrowsing.ReferrerURLChainSize.PPAPIDownloadAttribution", |
| 1931 out_request->referrer_chain_size()); | 1935 out_request->referrer_chain_size()); |
| 1932 UMA_HISTOGRAM_ENUMERATION( | 1936 UMA_HISTOGRAM_ENUMERATION( |
| 1933 "SafeBrowsing.ReferrerAttributionResult.PPAPIDownloadAttribution", result, | 1937 "SafeBrowsing.ReferrerAttributionResult.PPAPIDownloadAttribution", result, |
| 1934 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); | 1938 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); |
| 1939 out_request->set_download_attribution_finch_enabled(true); |
| 1935 } | 1940 } |
| 1936 | 1941 |
| 1937 } // namespace safe_browsing | 1942 } // namespace safe_browsing |
| OLD | NEW |