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 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
| |
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); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1352 continue; | 1356 continue; |
1353 DCHECK_EQ(base::FilePath::kExtensionSeparator, alternate_extension[0]); | 1357 DCHECK_EQ(base::FilePath::kExtensionSeparator, alternate_extension[0]); |
1354 *(request.add_alternate_extensions()) = | 1358 *(request.add_alternate_extensions()) = |
1355 base::FilePath(alternate_extension).AsUTF8Unsafe(); | 1359 base::FilePath(alternate_extension).AsUTF8Unsafe(); |
1356 } | 1360 } |
1357 if (supported_path_ != default_file_path_) { | 1361 if (supported_path_ != default_file_path_) { |
1358 *(request.add_alternate_extensions()) = | 1362 *(request.add_alternate_extensions()) = |
1359 base::FilePath(default_file_path_.FinalExtension()).AsUTF8Unsafe(); | 1363 base::FilePath(default_file_path_.FinalExtension()).AsUTF8Unsafe(); |
1360 } | 1364 } |
1361 | 1365 |
1362 // TODO(676691): We should add reliable download referrer chain for PPAPI | 1366 service_->AddReferrerChainToPPAPIClientDownloadRequest( |
1363 // downloads too. | 1367 initiating_frame_url_, |
1368 web_contents_, | |
1369 &request); | |
1364 | 1370 |
1365 if (!request.SerializeToString(&client_download_request_data_)) { | 1371 if (!request.SerializeToString(&client_download_request_data_)) { |
1366 // More of an internal error than anything else. Note that the UNKNOWN | 1372 // More of an internal error than anything else. Note that the UNKNOWN |
1367 // verdict gets interpreted as "allowed". | 1373 // verdict gets interpreted as "allowed". |
1368 Finish(RequestOutcome::REQUEST_MALFORMED, UNKNOWN); | 1374 Finish(RequestOutcome::REQUEST_MALFORMED, UNKNOWN); |
1369 return; | 1375 return; |
1370 } | 1376 } |
1371 | 1377 |
1372 service_->ppapi_download_request_callbacks_.Notify(&request); | 1378 service_->ppapi_download_request_callbacks_.Notify(&request); |
1373 DVLOG(2) << "Sending a PPAPI download request for URL: " << request.url(); | 1379 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 | 1483 |
1478 return base::FilePath(); | 1484 return base::FilePath(); |
1479 } | 1485 } |
1480 | 1486 |
1481 std::unique_ptr<net::URLFetcher> fetcher_; | 1487 std::unique_ptr<net::URLFetcher> fetcher_; |
1482 std::string client_download_request_data_; | 1488 std::string client_download_request_data_; |
1483 | 1489 |
1484 // URL of document that requested the PPAPI download. | 1490 // URL of document that requested the PPAPI download. |
1485 const GURL requestor_url_; | 1491 const GURL requestor_url_; |
1486 | 1492 |
1493 // URL of the frame that hosted the PPAPI plugin. | |
1494 const GURL initiating_frame_url_; | |
1495 | |
1496 // WebContents that is associated with this PPAPI download. | |
1497 content::WebContents* web_contents_; | |
1498 | |
1487 // Default download path requested by the PPAPI plugin. | 1499 // Default download path requested by the PPAPI plugin. |
1488 const base::FilePath default_file_path_; | 1500 const base::FilePath default_file_path_; |
1489 | 1501 |
1490 // List of alternate extensions provided by the PPAPI plugin. Each extension | 1502 // List of alternate extensions provided by the PPAPI plugin. Each extension |
1491 // must begin with a leading extension separator. | 1503 // must begin with a leading extension separator. |
1492 const std::vector<base::FilePath::StringType> alternate_extensions_; | 1504 const std::vector<base::FilePath::StringType> alternate_extensions_; |
1493 | 1505 |
1494 // Callback to invoke with the result of the PPAPI download request check. | 1506 // Callback to invoke with the result of the PPAPI download request check. |
1495 CheckDownloadCallback callback_; | 1507 CheckDownloadCallback callback_; |
1496 | 1508 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1607 ClientDownloadRequest::WIN_EXECUTABLE; | 1619 ClientDownloadRequest::WIN_EXECUTABLE; |
1608 // TODO(nparker): Remove the CRX check here once can support | 1620 // TODO(nparker): Remove the CRX check here once can support |
1609 // UNKNOWN types properly. http://crbug.com/581044 | 1621 // UNKNOWN types properly. http://crbug.com/581044 |
1610 return (CheckClientDownloadRequest::IsSupportedDownload( | 1622 return (CheckClientDownloadRequest::IsSupportedDownload( |
1611 item, target_path, &reason, &type) && | 1623 item, target_path, &reason, &type) && |
1612 (ClientDownloadRequest::CHROME_EXTENSION != type)); | 1624 (ClientDownloadRequest::CHROME_EXTENSION != type)); |
1613 } | 1625 } |
1614 | 1626 |
1615 void DownloadProtectionService::CheckPPAPIDownloadRequest( | 1627 void DownloadProtectionService::CheckPPAPIDownloadRequest( |
1616 const GURL& requestor_url, | 1628 const GURL& requestor_url, |
1629 const GURL& initiating_frame_url, | |
1630 content::WebContents* web_contents, | |
1617 const base::FilePath& default_file_path, | 1631 const base::FilePath& default_file_path, |
1618 const std::vector<base::FilePath::StringType>& alternate_extensions, | 1632 const std::vector<base::FilePath::StringType>& alternate_extensions, |
1619 Profile* profile, | 1633 Profile* profile, |
1620 const CheckDownloadCallback& callback) { | 1634 const CheckDownloadCallback& callback) { |
1621 DVLOG(1) << __func__ << " url:" << requestor_url | 1635 DVLOG(1) << __func__ << " url:" << requestor_url |
1622 << " default_file_path:" << default_file_path.value(); | 1636 << " default_file_path:" << default_file_path.value(); |
1623 std::unique_ptr<PPAPIDownloadRequest> request(new PPAPIDownloadRequest( | 1637 std::unique_ptr<PPAPIDownloadRequest> request(new PPAPIDownloadRequest( |
1624 requestor_url, default_file_path, alternate_extensions, profile, callback, | 1638 requestor_url, initiating_frame_url, web_contents, default_file_path, |
1625 this, database_manager_)); | 1639 alternate_extensions, profile, callback, this, database_manager_)); |
1626 PPAPIDownloadRequest* request_copy = request.get(); | 1640 PPAPIDownloadRequest* request_copy = request.get(); |
1627 auto insertion_result = ppapi_download_requests_.insert( | 1641 auto insertion_result = ppapi_download_requests_.insert( |
1628 std::make_pair(request_copy, std::move(request))); | 1642 std::make_pair(request_copy, std::move(request))); |
1629 DCHECK(insertion_result.second); | 1643 DCHECK(insertion_result.second); |
1630 insertion_result.first->second->Start(); | 1644 insertion_result.first->second->Start(); |
1631 } | 1645 } |
1632 | 1646 |
1633 DownloadProtectionService::ClientDownloadRequestSubscription | 1647 DownloadProtectionService::ClientDownloadRequestSubscription |
1634 DownloadProtectionService::RegisterClientDownloadRequestCallback( | 1648 DownloadProtectionService::RegisterClientDownloadRequestCallback( |
1635 const ClientDownloadRequestCallback& callback) { | 1649 const ClientDownloadRequestCallback& callback) { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1801 !navigation_observer_manager_) { | 1815 !navigation_observer_manager_) { |
1802 return; | 1816 return; |
1803 } | 1817 } |
1804 | 1818 |
1805 int download_tab_id = SessionTabHelper::IdForTab(web_contents); | 1819 int download_tab_id = SessionTabHelper::IdForTab(web_contents); |
1806 UMA_HISTOGRAM_BOOLEAN( | 1820 UMA_HISTOGRAM_BOOLEAN( |
1807 "SafeBrowsing.ReferrerHasInvalidTabID.DownloadAttribution", | 1821 "SafeBrowsing.ReferrerHasInvalidTabID.DownloadAttribution", |
1808 download_tab_id == -1); | 1822 download_tab_id == -1); |
1809 std::vector<ReferrerChainEntry> attribution_chain; | 1823 std::vector<ReferrerChainEntry> attribution_chain; |
1810 SafeBrowsingNavigationObserverManager::AttributionResult result = | 1824 SafeBrowsingNavigationObserverManager::AttributionResult result = |
1811 navigation_observer_manager_->IdentifyReferrerChain( | 1825 navigation_observer_manager_->IdentifyReferrerChainForDownload( |
1812 download_url, | 1826 download_url, |
1813 download_tab_id, | 1827 download_tab_id, |
1814 kDownloadAttributionUserGestureLimit, | 1828 kDownloadAttributionUserGestureLimit, |
1815 &attribution_chain); | 1829 &attribution_chain); |
1816 UMA_HISTOGRAM_COUNTS_100( | 1830 UMA_HISTOGRAM_COUNTS_100( |
1817 "SafeBrowsing.ReferrerURLChainSize.DownloadAttribution", | 1831 "SafeBrowsing.ReferrerURLChainSize.DownloadAttribution", |
1818 attribution_chain.size()); | 1832 attribution_chain.size()); |
1819 UMA_HISTOGRAM_ENUMERATION( | 1833 UMA_HISTOGRAM_ENUMERATION( |
1820 "SafeBrowsing.ReferrerAttributionResult.DownloadAttribution", result, | 1834 "SafeBrowsing.ReferrerAttributionResult.DownloadAttribution", result, |
1821 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); | 1835 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); |
1822 for (auto entry : attribution_chain) | 1836 for (auto entry : attribution_chain) |
1823 out_request->add_referrer_chain()->Swap(&entry); | 1837 out_request->add_referrer_chain()->Swap(&entry); |
1824 } | 1838 } |
1825 | 1839 |
1840 void DownloadProtectionService::AddReferrerChainToPPAPIClientDownloadRequest( | |
1841 const GURL& initiating_frame_url, | |
1842 content::WebContents* web_contents, | |
1843 ClientDownloadRequest* out_request) { | |
1844 if (!base::FeatureList::IsEnabled( | |
1845 SafeBrowsingNavigationObserverManager::kDownloadAttribution) || | |
1846 !navigation_observer_manager_) { | |
1847 return; | |
1848 } | |
1849 | |
1850 std::vector<ReferrerChainEntry> attribution_chain; | |
1851 SafeBrowsingNavigationObserverManager::AttributionResult result = | |
1852 navigation_observer_manager_->IdentifyReferrerChainForPPAPIDownload( | |
1853 initiating_frame_url, | |
1854 web_contents, | |
1855 kDownloadAttributionUserGestureLimit, | |
1856 &attribution_chain); | |
1857 UMA_HISTOGRAM_COUNTS_100( | |
1858 "SafeBrowsing.ReferrerURLChainSize.PPAPIDownloadAttribution", | |
1859 attribution_chain.size()); | |
1860 UMA_HISTOGRAM_ENUMERATION( | |
1861 "SafeBrowsing.ReferrerAttributionResult.PPAPIDownloadAttribution", result, | |
1862 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX); | |
1863 for (auto entry : attribution_chain) | |
1864 out_request->add_referrer_chain()->Swap(&entry); | |
1865 } | |
1866 | |
1826 } // namespace safe_browsing | 1867 } // namespace safe_browsing |
OLD | NEW |