OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // The Safe Browsing service is responsible for downloading anti-phishing and | 5 // The Safe Browsing service is responsible for downloading anti-phishing and |
6 // anti-malware tables and checking urls against them. | 6 // anti-malware tables and checking urls against them. |
7 | 7 |
8 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ | 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ |
9 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ | 9 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ |
10 #pragma once | 10 #pragma once |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 176 |
177 // Called on the IO thread to cancel a pending check if the result is no | 177 // Called on the IO thread to cancel a pending check if the result is no |
178 // longer needed. | 178 // longer needed. |
179 void CancelCheck(Client* client); | 179 void CancelCheck(Client* client); |
180 | 180 |
181 // Called on the IO thread to display an interstitial page. | 181 // Called on the IO thread to display an interstitial page. |
182 // |url| is the url of the resource that matches a safe browsing list. | 182 // |url| is the url of the resource that matches a safe browsing list. |
183 // If the request contained a chain of redirects, |url| is the last url | 183 // If the request contained a chain of redirects, |url| is the last url |
184 // in the chain, and |original_url| is the first one (the root of the | 184 // in the chain, and |original_url| is the first one (the root of the |
185 // chain). Otherwise, |original_url| = |url|. | 185 // chain). Otherwise, |original_url| = |url|. |
186 virtual void DisplayBlockingPage(const GURL& url, | 186 void DisplayBlockingPage(const GURL& url, |
187 const GURL& original_url, | 187 const GURL& original_url, |
188 const std::vector<GURL>& redirect_urls, | 188 const std::vector<GURL>& redirect_urls, |
189 ResourceType::Type resource_type, | 189 ResourceType::Type resource_type, |
190 UrlCheckResult result, | 190 UrlCheckResult result, |
191 Client* client, | 191 Client* client, |
192 int render_process_host_id, | 192 int render_process_host_id, |
193 int render_view_id); | 193 int render_view_id); |
| 194 |
| 195 // Same as above but gets invoked on the UI thread. |
| 196 virtual void DoDisplayBlockingPage(const UnsafeResource& resource); |
| 197 |
| 198 // Returns true if we already displayed an interstitial for that resource. |
| 199 // Called on the UI thread. |
| 200 bool IsWhitelisted(const UnsafeResource& resource); |
194 | 201 |
195 // Called on the IO thread when the SafeBrowsingProtocolManager has received | 202 // Called on the IO thread when the SafeBrowsingProtocolManager has received |
196 // the full hash results for prefix hits detected in the database. | 203 // the full hash results for prefix hits detected in the database. |
197 void HandleGetHashResults( | 204 void HandleGetHashResults( |
198 SafeBrowsingCheck* check, | 205 SafeBrowsingCheck* check, |
199 const std::vector<SBFullHashResult>& full_hashes, | 206 const std::vector<SBFullHashResult>& full_hashes, |
200 bool can_cache); | 207 bool can_cache); |
201 | 208 |
202 // Called on the IO thread. | 209 // Called on the IO thread. |
203 void HandleChunk(const std::string& list, SBChunkList* chunks); | 210 void HandleChunk(const std::string& list, SBChunkList* chunks); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 | 365 |
359 // Internal worker function for processing full hashes. | 366 // Internal worker function for processing full hashes. |
360 void OnHandleGetHashResults(SafeBrowsingCheck* check, | 367 void OnHandleGetHashResults(SafeBrowsingCheck* check, |
361 const std::vector<SBFullHashResult>& full_hashes); | 368 const std::vector<SBFullHashResult>& full_hashes); |
362 | 369 |
363 // Run one check against |full_hashes|. Returns |true| if the check | 370 // Run one check against |full_hashes|. Returns |true| if the check |
364 // finds a match in |full_hashes|. | 371 // finds a match in |full_hashes|. |
365 bool HandleOneCheck(SafeBrowsingCheck* check, | 372 bool HandleOneCheck(SafeBrowsingCheck* check, |
366 const std::vector<SBFullHashResult>& full_hashes); | 373 const std::vector<SBFullHashResult>& full_hashes); |
367 | 374 |
368 // Invoked on the UI thread to show the blocking page. | |
369 void DoDisplayBlockingPage(const UnsafeResource& resource); | |
370 | |
371 // Call protocol manager on IO thread to report hits of unsafe contents. | 375 // Call protocol manager on IO thread to report hits of unsafe contents. |
372 void ReportSafeBrowsingHitOnIOThread(const GURL& malicious_url, | 376 void ReportSafeBrowsingHitOnIOThread(const GURL& malicious_url, |
373 const GURL& page_url, | 377 const GURL& page_url, |
374 const GURL& referrer_url, | 378 const GURL& referrer_url, |
375 bool is_subresource, | 379 bool is_subresource, |
376 UrlCheckResult threat_type, | 380 UrlCheckResult threat_type, |
377 const std::string& post_data); | 381 const std::string& post_data); |
378 | 382 |
379 // Checks the download hash on safe_browsing_thread_. | 383 // Checks the download hash on safe_browsing_thread_. |
380 void CheckDownloadHashOnSBThread(SafeBrowsingCheck* check); | 384 void CheckDownloadHashOnSBThread(SafeBrowsingCheck* check); |
(...skipping 16 matching lines...) Expand all Loading... |
397 void SafeBrowsingCheckDone(SafeBrowsingCheck* check); | 401 void SafeBrowsingCheckDone(SafeBrowsingCheck* check); |
398 | 402 |
399 // Helper function to set |check| with default values and start a safe | 403 // Helper function to set |check| with default values and start a safe |
400 // browsing check with timeout of |timeout_ms|. |task| will be called upon | 404 // browsing check with timeout of |timeout_ms|. |task| will be called upon |
401 // success, otherwise TimeoutCallback will be called. | 405 // success, otherwise TimeoutCallback will be called. |
402 void StartDownloadCheck(SafeBrowsingCheck* check, | 406 void StartDownloadCheck(SafeBrowsingCheck* check, |
403 Client* client, | 407 Client* client, |
404 CancelableTask* task, | 408 CancelableTask* task, |
405 int64 timeout_ms); | 409 int64 timeout_ms); |
406 | 410 |
| 411 // Adds the given entry to the whitelist. Called on the UI thread. |
| 412 void UpdateWhitelist(UnsafeResource resource); |
| 413 |
407 // The factory used to instanciate a SafeBrowsingService object. | 414 // The factory used to instanciate a SafeBrowsingService object. |
408 // Useful for tests, so they can provide their own implementation of | 415 // Useful for tests, so they can provide their own implementation of |
409 // SafeBrowsingService. | 416 // SafeBrowsingService. |
410 static SafeBrowsingServiceFactory* factory_; | 417 static SafeBrowsingServiceFactory* factory_; |
411 | 418 |
412 CurrentChecks checks_; | 419 CurrentChecks checks_; |
413 | 420 |
414 // Used for issuing only one GetHash request for a given prefix. | 421 // Used for issuing only one GetHash request for a given prefix. |
415 GetHashRequests gethash_requests_; | 422 GetHashRequests gethash_requests_; |
416 | 423 |
417 // The persistent database. We don't use a scoped_ptr because it | 424 // The persistent database. We don't use a scoped_ptr because it |
418 // needs to be destructed on a different thread than this object. | 425 // needs to be destructed on a different thread than this object. |
419 SafeBrowsingDatabase* database_; | 426 SafeBrowsingDatabase* database_; |
420 | 427 |
421 // Lock used to prevent possible data races due to compiler optimizations. | 428 // Lock used to prevent possible data races due to compiler optimizations. |
422 mutable base::Lock database_lock_; | 429 mutable base::Lock database_lock_; |
423 | 430 |
424 // Handles interaction with SafeBrowsing servers. | 431 // Handles interaction with SafeBrowsing servers. |
425 SafeBrowsingProtocolManager* protocol_manager_; | 432 SafeBrowsingProtocolManager* protocol_manager_; |
426 | 433 |
| 434 // Only access this whitelist from the UI thread. |
427 std::vector<WhiteListedEntry> white_listed_entries_; | 435 std::vector<WhiteListedEntry> white_listed_entries_; |
428 | 436 |
429 // Whether the service is running. 'enabled_' is used by SafeBrowsingService | 437 // Whether the service is running. 'enabled_' is used by SafeBrowsingService |
430 // on the IO thread during normal operations. | 438 // on the IO thread during normal operations. |
431 bool enabled_; | 439 bool enabled_; |
432 | 440 |
433 // Indicate if download_protection is enabled by command switch | 441 // Indicate if download_protection is enabled by command switch |
434 // so we allow this feature to be exersized. | 442 // so we allow this feature to be exersized. |
435 bool enable_download_protection_; | 443 bool enable_download_protection_; |
436 | 444 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 class SafeBrowsingServiceFactory { | 480 class SafeBrowsingServiceFactory { |
473 public: | 481 public: |
474 SafeBrowsingServiceFactory() { } | 482 SafeBrowsingServiceFactory() { } |
475 virtual ~SafeBrowsingServiceFactory() { } | 483 virtual ~SafeBrowsingServiceFactory() { } |
476 virtual SafeBrowsingService* CreateSafeBrowsingService() = 0; | 484 virtual SafeBrowsingService* CreateSafeBrowsingService() = 0; |
477 private: | 485 private: |
478 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactory); | 486 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactory); |
479 }; | 487 }; |
480 | 488 |
481 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ | 489 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ |
OLD | NEW |