Chromium Code Reviews| 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 // Helper class which handles communication with the SafeBrowsing servers for | 5 // Helper class which handles communication with the SafeBrowsing servers for |
| 6 // improved binary download protection. | 6 // improved binary download protection. |
| 7 | 7 |
| 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ | 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ |
| 9 #define CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ | 9 #define CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ |
| 10 | 10 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 // is finished and written to disk. | 111 // is finished and written to disk. |
| 112 virtual void CheckClientDownload( | 112 virtual void CheckClientDownload( |
| 113 content::DownloadItem* item, | 113 content::DownloadItem* item, |
| 114 const CheckDownloadCallback& callback); | 114 const CheckDownloadCallback& callback); |
| 115 | 115 |
| 116 // Checks whether any of the URLs in the redirect chain of the | 116 // Checks whether any of the URLs in the redirect chain of the |
| 117 // download match the SafeBrowsing bad binary URL list. The result is | 117 // download match the SafeBrowsing bad binary URL list. The result is |
| 118 // delivered asynchronously via the given callback. This method must be | 118 // delivered asynchronously via the given callback. This method must be |
| 119 // called on the UI thread, and the callback will also be invoked on the UI | 119 // called on the UI thread, and the callback will also be invoked on the UI |
| 120 // thread. Pre-condition: !info.download_url_chain.empty(). | 120 // thread. Pre-condition: !info.download_url_chain.empty(). |
| 121 virtual void CheckDownloadUrl(const content::DownloadItem& item, | 121 virtual void CheckDownloadUrl(content::DownloadItem* item, |
| 122 const CheckDownloadCallback& callback); | 122 const CheckDownloadCallback& callback); |
| 123 | 123 |
| 124 // Returns true iff the download specified by |info| should be scanned by | 124 // Returns true iff the download specified by |info| should be scanned by |
| 125 // CheckClientDownload() for malicious content. | 125 // CheckClientDownload() for malicious content. |
| 126 virtual bool IsSupportedDownload( | 126 virtual bool IsSupportedDownload( |
| 127 const content::DownloadItem& item, | 127 const content::DownloadItem& item, |
| 128 const base::FilePath& target_path) const; | 128 const base::FilePath& target_path) const; |
| 129 | 129 |
| 130 virtual void CheckPPAPIDownloadRequest( | 130 virtual void CheckPPAPIDownloadRequest( |
| 131 const GURL& requestor_url, | 131 const GURL& requestor_url, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 REASON_LOCAL_FILE = 24, | 216 REASON_LOCAL_FILE = 24, |
| 217 REASON_REMOTE_FILE = 25, | 217 REASON_REMOTE_FILE = 25, |
| 218 REASON_SAMPLED_UNSUPPORTED_FILE = 26, | 218 REASON_SAMPLED_UNSUPPORTED_FILE = 26, |
| 219 REASON_VERDICT_UNKNOWN = 27, | 219 REASON_VERDICT_UNKNOWN = 27, |
| 220 REASON_MAX // Always add new values before this one. | 220 REASON_MAX // Always add new values before this one. |
| 221 }; | 221 }; |
| 222 | 222 |
| 223 private: | 223 private: |
| 224 class CheckClientDownloadRequest; | 224 class CheckClientDownloadRequest; |
| 225 class PPAPIDownloadRequest; | 225 class PPAPIDownloadRequest; |
| 226 friend class DownloadSBClient; | |
| 226 friend class DownloadProtectionServiceTest; | 227 friend class DownloadProtectionServiceTest; |
| 227 friend class DownloadDangerPromptTest; | 228 friend class DownloadDangerPromptTest; |
| 228 | 229 |
| 229 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, | 230 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, |
| 230 CheckClientDownloadWhitelistedUrlWithoutSampling); | 231 CheckClientDownloadWhitelistedUrlWithoutSampling); |
| 231 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, | 232 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, |
| 232 CheckClientDownloadWhitelistedUrlWithSampling); | 233 CheckClientDownloadWhitelistedUrlWithSampling); |
| 233 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, | 234 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, |
| 234 CheckClientDownloadValidateRequest); | 235 CheckClientDownloadValidateRequest); |
| 235 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, | 236 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 252 PPAPIDownloadRequest_InvalidResponse); | 253 PPAPIDownloadRequest_InvalidResponse); |
| 253 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, | 254 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, |
| 254 PPAPIDownloadRequest_Timeout); | 255 PPAPIDownloadRequest_Timeout); |
| 255 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceFlagTest, | 256 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceFlagTest, |
| 256 CheckClientDownloadOverridenByFlag); | 257 CheckClientDownloadOverridenByFlag); |
| 257 | 258 |
| 258 static const char kDownloadRequestUrl[]; | 259 static const char kDownloadRequestUrl[]; |
| 259 | 260 |
| 260 static const void* const kDownloadPingTokenKey; | 261 static const void* const kDownloadPingTokenKey; |
| 261 | 262 |
| 263 static const void* const kDownloadReferrerChainDataKey; | |
|
Nathan Parker
2017/01/24 22:46:46
nit: could this be in a anonymous namespace in the
Jialiu Lin
2017/01/25 00:11:20
Done.
kDownloadPingTokenKey is used in a browser t
| |
| 264 | |
| 262 // Helper class for easy setting and getting token string. | 265 // Helper class for easy setting and getting token string. |
| 263 class DownloadPingToken : public base::SupportsUserData::Data { | 266 class DownloadPingToken : public base::SupportsUserData::Data { |
| 264 public: | 267 public: |
| 265 explicit DownloadPingToken(const std::string& token) | 268 explicit DownloadPingToken(const std::string& token) |
| 266 : token_string_(token) {} | 269 : token_string_(token) {} |
| 267 | 270 |
| 268 std::string token_string() { | 271 std::string token_string() { |
| 269 return token_string_; | 272 return token_string_; |
| 270 } | 273 } |
| 271 private: | 274 private: |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 288 // list of strings that need to be checked against the download whitelist to | 291 // list of strings that need to be checked against the download whitelist to |
| 289 // determine whether the certificate is whitelisted. | 292 // determine whether the certificate is whitelisted. |
| 290 static void GetCertificateWhitelistStrings( | 293 static void GetCertificateWhitelistStrings( |
| 291 const net::X509Certificate& certificate, | 294 const net::X509Certificate& certificate, |
| 292 const net::X509Certificate& issuer, | 295 const net::X509Certificate& issuer, |
| 293 std::vector<std::string>* whitelist_strings); | 296 std::vector<std::string>* whitelist_strings); |
| 294 | 297 |
| 295 // Returns the URL that will be used for download requests. | 298 // Returns the URL that will be used for download requests. |
| 296 static GURL GetDownloadRequestUrl(); | 299 static GURL GetDownloadRequestUrl(); |
| 297 | 300 |
| 298 // If kDownloadAttribution feature is enabled, identify and add referrer chain | 301 // If kDownloadAttribution feature is enabled, identify referrer chain info of |
| 299 // info of a download to ClientDownloadRequest proto. This function also | 302 // a download. This function also records UMA stats of download attribution |
| 300 // records UMA stats of download attribution result. | 303 // result. |
| 301 void AddReferrerChainToClientDownloadRequest( | 304 void IdentifyReferrerChain( |
| 302 const GURL& download_url, | 305 const GURL& download_url, |
| 303 content::WebContents* web_contents, | 306 content::WebContents* web_contents, |
| 304 ClientDownloadRequest* out_request); | 307 ReferrerChain* out_referrer_chain); |
| 305 | 308 |
| 306 // If kDownloadAttribution feature is enabled, identify referrer chain of the | 309 // If kDownloadAttribution feature is enabled, identify referrer chain of the |
| 307 // PPAPI download based on the frame URL where the download is initiated. | 310 // PPAPI download based on the frame URL where the download is initiated. |
| 308 // Then add referrer chain info to ClientDownloadRequest proto. This function | 311 // Then add referrer chain info to ClientDownloadRequest proto. This function |
| 309 // also records UMA stats of download attribution result. | 312 // also records UMA stats of download attribution result. |
| 310 void AddReferrerChainToPPAPIClientDownloadRequest( | 313 void AddReferrerChainToPPAPIClientDownloadRequest( |
| 311 const GURL& initiating_frame_url, | 314 const GURL& initiating_frame_url, |
| 312 int tab_id, | 315 int tab_id, |
| 313 bool has_user_gesture, | 316 bool has_user_gesture, |
| 314 ClientDownloadRequest* out_request); | 317 ClientDownloadRequest* out_request); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 std::set<std::string> manual_blacklist_hashes_; | 357 std::set<std::string> manual_blacklist_hashes_; |
| 355 | 358 |
| 356 // Rate of whitelisted downloads we sample to send out download ping. | 359 // Rate of whitelisted downloads we sample to send out download ping. |
| 357 double whitelist_sample_rate_; | 360 double whitelist_sample_rate_; |
| 358 | 361 |
| 359 DISALLOW_COPY_AND_ASSIGN(DownloadProtectionService); | 362 DISALLOW_COPY_AND_ASSIGN(DownloadProtectionService); |
| 360 }; | 363 }; |
| 361 } // namespace safe_browsing | 364 } // namespace safe_browsing |
| 362 | 365 |
| 363 #endif // CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ | 366 #endif // CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ |
| OLD | NEW |