| 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 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 TIMEDOUT, | 1223 TIMEDOUT, |
| 1224 WHITELIST_HIT, | 1224 WHITELIST_HIT, |
| 1225 REQUEST_MALFORMED, | 1225 REQUEST_MALFORMED, |
| 1226 FETCH_FAILED, | 1226 FETCH_FAILED, |
| 1227 RESPONSE_MALFORMED, | 1227 RESPONSE_MALFORMED, |
| 1228 SUCCEEDED | 1228 SUCCEEDED |
| 1229 }; | 1229 }; |
| 1230 | 1230 |
| 1231 PPAPIDownloadRequest( | 1231 PPAPIDownloadRequest( |
| 1232 const GURL& requestor_url, | 1232 const GURL& requestor_url, |
| 1233 const GURL& initiating_frame_url, |
| 1234 content::WebContents* web_contents, |
| 1233 const base::FilePath& default_file_path, | 1235 const base::FilePath& default_file_path, |
| 1234 const std::vector<base::FilePath::StringType>& alternate_extensions, | 1236 const std::vector<base::FilePath::StringType>& alternate_extensions, |
| 1235 Profile* profile, | 1237 Profile* profile, |
| 1236 const CheckDownloadCallback& callback, | 1238 const CheckDownloadCallback& callback, |
| 1237 DownloadProtectionService* service, | 1239 DownloadProtectionService* service, |
| 1238 scoped_refptr<SafeBrowsingDatabaseManager> database_manager) | 1240 scoped_refptr<SafeBrowsingDatabaseManager> database_manager) |
| 1239 : requestor_url_(requestor_url), | 1241 : requestor_url_(requestor_url), |
| 1242 initiating_frame_url_(initiating_frame_url), |
| 1243 tab_id_(SessionTabHelper::IdForTab(web_contents)), |
| 1240 default_file_path_(default_file_path), | 1244 default_file_path_(default_file_path), |
| 1241 alternate_extensions_(alternate_extensions), | 1245 alternate_extensions_(alternate_extensions), |
| 1242 callback_(callback), | 1246 callback_(callback), |
| 1243 service_(service), | 1247 service_(service), |
| 1244 database_manager_(database_manager), | 1248 database_manager_(database_manager), |
| 1245 start_time_(base::TimeTicks::Now()), | 1249 start_time_(base::TimeTicks::Now()), |
| 1246 supported_path_( | 1250 supported_path_( |
| 1247 GetSupportedFilePath(default_file_path, alternate_extensions)), | 1251 GetSupportedFilePath(default_file_path, alternate_extensions)), |
| 1248 weakptr_factory_(this) { | 1252 weakptr_factory_(this) { |
| 1249 DCHECK(profile); | 1253 DCHECK(profile); |
| 1250 is_extended_reporting_ = IsExtendedReportingEnabled(*profile->GetPrefs()); | 1254 is_extended_reporting_ = IsExtendedReportingEnabled(*profile->GetPrefs()); |
| 1255 |
| 1256 if (service->navigation_observer_manager()) { |
| 1257 has_user_gesture_ = |
| 1258 service->navigation_observer_manager()->HasUserGesture(web_contents); |
| 1259 if (has_user_gesture_) { |
| 1260 service->navigation_observer_manager()->OnUserGestureConsumed( |
| 1261 web_contents, base::Time::Now()); |
| 1262 } |
| 1263 } |
| 1251 } | 1264 } |
| 1252 | 1265 |
| 1253 ~PPAPIDownloadRequest() override { | 1266 ~PPAPIDownloadRequest() override { |
| 1254 if (fetcher_ && !callback_.is_null()) | 1267 if (fetcher_ && !callback_.is_null()) |
| 1255 Finish(RequestOutcome::REQUEST_DESTROYED, UNKNOWN); | 1268 Finish(RequestOutcome::REQUEST_DESTROYED, UNKNOWN); |
| 1256 } | 1269 } |
| 1257 | 1270 |
| 1258 // Start the process of checking the download request. The callback passed as | 1271 // Start the process of checking the download request. The callback passed as |
| 1259 // the |callback| parameter to the constructor will be invoked with the result | 1272 // the |callback| parameter to the constructor will be invoked with the result |
| 1260 // of the check at some point in the future. | 1273 // of the check at some point in the future. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1352 continue; | 1365 continue; |
| 1353 DCHECK_EQ(base::FilePath::kExtensionSeparator, alternate_extension[0]); | 1366 DCHECK_EQ(base::FilePath::kExtensionSeparator, alternate_extension[0]); |
| 1354 *(request.add_alternate_extensions()) = | 1367 *(request.add_alternate_extensions()) = |
| 1355 base::FilePath(alternate_extension).AsUTF8Unsafe(); | 1368 base::FilePath(alternate_extension).AsUTF8Unsafe(); |
| 1356 } | 1369 } |
| 1357 if (supported_path_ != default_file_path_) { | 1370 if (supported_path_ != default_file_path_) { |
| 1358 *(request.add_alternate_extensions()) = | 1371 *(request.add_alternate_extensions()) = |
| 1359 base::FilePath(default_file_path_.FinalExtension()).AsUTF8Unsafe(); | 1372 base::FilePath(default_file_path_.FinalExtension()).AsUTF8Unsafe(); |
| 1360 } | 1373 } |
| 1361 | 1374 |
| 1362 // TODO(676691): We should add reliable download referrer chain for PPAPI | 1375 service_->AddReferrerChainToPPAPIClientDownloadRequest( |
| 1363 // downloads too. | 1376 initiating_frame_url_, |
| 1377 tab_id_, |
| 1378 has_user_gesture_, |
| 1379 &request); |
| 1364 | 1380 |
| 1365 if (!request.SerializeToString(&client_download_request_data_)) { | 1381 if (!request.SerializeToString(&client_download_request_data_)) { |
| 1366 // More of an internal error than anything else. Note that the UNKNOWN | 1382 // More of an internal error than anything else. Note that the UNKNOWN |
| 1367 // verdict gets interpreted as "allowed". | 1383 // verdict gets interpreted as "allowed". |
| 1368 Finish(RequestOutcome::REQUEST_MALFORMED, UNKNOWN); | 1384 Finish(RequestOutcome::REQUEST_MALFORMED, UNKNOWN); |
| 1369 return; | 1385 return; |
| 1370 } | 1386 } |
| 1371 | 1387 |
| 1372 service_->ppapi_download_request_callbacks_.Notify(&request); | 1388 service_->ppapi_download_request_callbacks_.Notify(&request); |
| 1373 DVLOG(2) << "Sending a PPAPI download request for URL: " << request.url(); | 1389 DVLOG(2) << "Sending a PPAPI download request for URL: " << request.url(); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1477 | 1493 |
| 1478 return base::FilePath(); | 1494 return base::FilePath(); |
| 1479 } | 1495 } |
| 1480 | 1496 |
| 1481 std::unique_ptr<net::URLFetcher> fetcher_; | 1497 std::unique_ptr<net::URLFetcher> fetcher_; |
| 1482 std::string client_download_request_data_; | 1498 std::string client_download_request_data_; |
| 1483 | 1499 |
| 1484 // URL of document that requested the PPAPI download. | 1500 // URL of document that requested the PPAPI download. |
| 1485 const GURL requestor_url_; | 1501 const GURL requestor_url_; |
| 1486 | 1502 |
| 1503 // URL of the frame that hosted the PPAPI plugin. |
| 1504 const GURL initiating_frame_url_; |
| 1505 |
| 1506 // Tab id that associated with the PPAPI plugin, computed by |
| 1507 // SessionTabHelper::IdForTab(). |
| 1508 int tab_id_; |
| 1509 |
| 1510 // If the user interacted with this PPAPI plugin to trigger the download. |
| 1511 bool has_user_gesture_; |
| 1512 |
| 1487 // Default download path requested by the PPAPI plugin. | 1513 // Default download path requested by the PPAPI plugin. |
| 1488 const base::FilePath default_file_path_; | 1514 const base::FilePath default_file_path_; |
| 1489 | 1515 |
| 1490 // List of alternate extensions provided by the PPAPI plugin. Each extension | 1516 // List of alternate extensions provided by the PPAPI plugin. Each extension |
| 1491 // must begin with a leading extension separator. | 1517 // must begin with a leading extension separator. |
| 1492 const std::vector<base::FilePath::StringType> alternate_extensions_; | 1518 const std::vector<base::FilePath::StringType> alternate_extensions_; |
| 1493 | 1519 |
| 1494 // Callback to invoke with the result of the PPAPI download request check. | 1520 // Callback to invoke with the result of the PPAPI download request check. |
| 1495 CheckDownloadCallback callback_; | 1521 CheckDownloadCallback callback_; |
| 1496 | 1522 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1607 ClientDownloadRequest::WIN_EXECUTABLE; | 1633 ClientDownloadRequest::WIN_EXECUTABLE; |
| 1608 // TODO(nparker): Remove the CRX check here once can support | 1634 // TODO(nparker): Remove the CRX check here once can support |
| 1609 // UNKNOWN types properly. http://crbug.com/581044 | 1635 // UNKNOWN types properly. http://crbug.com/581044 |
| 1610 return (CheckClientDownloadRequest::IsSupportedDownload( | 1636 return (CheckClientDownloadRequest::IsSupportedDownload( |
| 1611 item, target_path, &reason, &type) && | 1637 item, target_path, &reason, &type) && |
| 1612 (ClientDownloadRequest::CHROME_EXTENSION != type)); | 1638 (ClientDownloadRequest::CHROME_EXTENSION != type)); |
| 1613 } | 1639 } |
| 1614 | 1640 |
| 1615 void DownloadProtectionService::CheckPPAPIDownloadRequest( | 1641 void DownloadProtectionService::CheckPPAPIDownloadRequest( |
| 1616 const GURL& requestor_url, | 1642 const GURL& requestor_url, |
| 1643 const GURL& initiating_frame_url, |
| 1644 content::WebContents* web_contents, |
| 1617 const base::FilePath& default_file_path, | 1645 const base::FilePath& default_file_path, |
| 1618 const std::vector<base::FilePath::StringType>& alternate_extensions, | 1646 const std::vector<base::FilePath::StringType>& alternate_extensions, |
| 1619 Profile* profile, | 1647 Profile* profile, |
| 1620 const CheckDownloadCallback& callback) { | 1648 const CheckDownloadCallback& callback) { |
| 1621 DVLOG(1) << __func__ << " url:" << requestor_url | 1649 DVLOG(1) << __func__ << " url:" << requestor_url |
| 1622 << " default_file_path:" << default_file_path.value(); | 1650 << " default_file_path:" << default_file_path.value(); |
| 1623 std::unique_ptr<PPAPIDownloadRequest> request(new PPAPIDownloadRequest( | 1651 std::unique_ptr<PPAPIDownloadRequest> request(new PPAPIDownloadRequest( |
| 1624 requestor_url, default_file_path, alternate_extensions, profile, callback, | 1652 requestor_url, initiating_frame_url, web_contents, default_file_path, |
| 1625 this, database_manager_)); | 1653 alternate_extensions, profile, callback, this, database_manager_)); |
| 1626 PPAPIDownloadRequest* request_copy = request.get(); | 1654 PPAPIDownloadRequest* request_copy = request.get(); |
| 1627 auto insertion_result = ppapi_download_requests_.insert( | 1655 auto insertion_result = ppapi_download_requests_.insert( |
| 1628 std::make_pair(request_copy, std::move(request))); | 1656 std::make_pair(request_copy, std::move(request))); |
| 1629 DCHECK(insertion_result.second); | 1657 DCHECK(insertion_result.second); |
| 1630 insertion_result.first->second->Start(); | 1658 insertion_result.first->second->Start(); |
| 1631 } | 1659 } |
| 1632 | 1660 |
| 1633 DownloadProtectionService::ClientDownloadRequestSubscription | 1661 DownloadProtectionService::ClientDownloadRequestSubscription |
| 1634 DownloadProtectionService::RegisterClientDownloadRequestCallback( | 1662 DownloadProtectionService::RegisterClientDownloadRequestCallback( |
| 1635 const ClientDownloadRequestCallback& callback) { | 1663 const ClientDownloadRequestCallback& callback) { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1801 !navigation_observer_manager_) { | 1829 !navigation_observer_manager_) { |
| 1802 return; | 1830 return; |
| 1803 } | 1831 } |
| 1804 | 1832 |
| 1805 int download_tab_id = SessionTabHelper::IdForTab(web_contents); | 1833 int download_tab_id = SessionTabHelper::IdForTab(web_contents); |
| 1806 UMA_HISTOGRAM_BOOLEAN( | 1834 UMA_HISTOGRAM_BOOLEAN( |
| 1807 "SafeBrowsing.ReferrerHasInvalidTabID.DownloadAttribution", | 1835 "SafeBrowsing.ReferrerHasInvalidTabID.DownloadAttribution", |
| 1808 download_tab_id == -1); | 1836 download_tab_id == -1); |
| 1809 std::vector<ReferrerChainEntry> attribution_chain; | 1837 std::vector<ReferrerChainEntry> attribution_chain; |
| 1810 SafeBrowsingNavigationObserverManager::AttributionResult result = | 1838 SafeBrowsingNavigationObserverManager::AttributionResult result = |
| 1811 navigation_observer_manager_->IdentifyReferrerChain( | 1839 navigation_observer_manager_->IdentifyReferrerChainForDownload( |
| 1812 download_url, | 1840 download_url, |
| 1813 download_tab_id, | 1841 download_tab_id, |
| 1814 kDownloadAttributionUserGestureLimit, | 1842 kDownloadAttributionUserGestureLimit, |
| 1815 &attribution_chain); | 1843 &attribution_chain); |
| 1816 UMA_HISTOGRAM_COUNTS_100( | 1844 UMA_HISTOGRAM_COUNTS_100( |
| 1817 "SafeBrowsing.ReferrerURLChainSize.DownloadAttribution", | 1845 "SafeBrowsing.ReferrerURLChainSize.DownloadAttribution", |
| 1818 attribution_chain.size()); | 1846 attribution_chain.size()); |
| 1819 UMA_HISTOGRAM_ENUMERATION( | 1847 UMA_HISTOGRAM_ENUMERATION( |
| 1820 "SafeBrowsing.ReferrerAttributionResult.DownloadAttribution", result, | 1848 "SafeBrowsing.ReferrerAttributionResult.DownloadAttribution", result, |
| 1821 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); | 1849 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); |
| 1822 for (auto entry : attribution_chain) | 1850 for (auto entry : attribution_chain) |
| 1823 out_request->add_referrer_chain()->Swap(&entry); | 1851 out_request->add_referrer_chain()->Swap(&entry); |
| 1824 } | 1852 } |
| 1825 | 1853 |
| 1854 void DownloadProtectionService::AddReferrerChainToPPAPIClientDownloadRequest( |
| 1855 const GURL& initiating_frame_url, |
| 1856 int tab_id, |
| 1857 bool has_user_gesture, |
| 1858 ClientDownloadRequest* out_request) { |
| 1859 if (!base::FeatureList::IsEnabled( |
| 1860 SafeBrowsingNavigationObserverManager::kDownloadAttribution) || |
| 1861 !navigation_observer_manager_) { |
| 1862 return; |
| 1863 } |
| 1864 |
| 1865 UMA_HISTOGRAM_BOOLEAN( |
| 1866 "SafeBrowsing.ReferrerHasInvalidTabID.DownloadAttribution", |
| 1867 tab_id == -1); |
| 1868 std::vector<ReferrerChainEntry> attribution_chain; |
| 1869 SafeBrowsingNavigationObserverManager::AttributionResult result = |
| 1870 navigation_observer_manager_->IdentifyReferrerChainForPPAPIDownload( |
| 1871 initiating_frame_url, |
| 1872 tab_id, |
| 1873 has_user_gesture, |
| 1874 kDownloadAttributionUserGestureLimit, |
| 1875 &attribution_chain); |
| 1876 UMA_HISTOGRAM_COUNTS_100( |
| 1877 "SafeBrowsing.ReferrerURLChainSize.PPAPIDownloadAttribution", |
| 1878 attribution_chain.size()); |
| 1879 UMA_HISTOGRAM_ENUMERATION( |
| 1880 "SafeBrowsing.ReferrerAttributionResult.PPAPIDownloadAttribution", result, |
| 1881 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); |
| 1882 for (auto entry : attribution_chain) |
| 1883 out_request->add_referrer_chain()->Swap(&entry); |
| 1884 } |
| 1885 |
| 1826 } // namespace safe_browsing | 1886 } // namespace safe_browsing |
| OLD | NEW |