OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_ACTIVAT
ION_RESOURCE_THROTTLE_H_ |
| 6 #define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_ACTIVAT
ION_RESOURCE_THROTTLE_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/time/time.h" |
| 14 #include "base/timer/timer.h" |
| 15 #include "components/safe_browsing_db/database_manager.h" |
| 16 #include "content/public/browser/navigation_throttle.h" |
| 17 #include "url/gurl.h" |
| 18 |
| 19 namespace subresource_filter { |
| 20 |
| 21 // Client for accessing list with patterns to be used by the Subresource Filter. |
| 22 class SubresourceFilterActivationNavigationThrottle |
| 23 : public content::NavigationThrottle, |
| 24 public safe_browsing::SafeBrowsingDatabaseManager::Client, |
| 25 public base::SupportsWeakPtr< |
| 26 SubresourceFilterActivationNavigationThrottle> { |
| 27 public: |
| 28 SubresourceFilterActivationNavigationThrottle( |
| 29 content::NavigationHandle* handle, |
| 30 const scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>& |
| 31 database_manager); |
| 32 |
| 33 ~SubresourceFilterActivationNavigationThrottle() override; |
| 34 |
| 35 content::NavigationThrottle::ThrottleCheckResult WillProcessResponse() |
| 36 override; |
| 37 |
| 38 // SafeBrowsingDabaseManager::Client implementation (called on IO thread): |
| 39 void OnCheckBrowseUrlResult( |
| 40 const GURL& url, |
| 41 safe_browsing::SBThreatType result, |
| 42 const safe_browsing::ThreatMetadata& metadata) override; |
| 43 |
| 44 private: |
| 45 // Starts running |url| through the safe browsing check. Returns true if the |
| 46 // URL doesn't belong to the Subresource Filter only list. Otherwise returns |
| 47 // false and will call OnCheckBrowseUrlResult() when the check |
| 48 // has completed. |
| 49 bool CheckUrl(const GURL& url); |
| 50 |
| 51 // Callback for when the safe browsing check has taken longer than |
| 52 // kCheckUrlTimeoutMs. |
| 53 void OnCheckUrlTimeout(); |
| 54 |
| 55 void CheckUrlOnIO(const GURL& url); |
| 56 |
| 57 void OnCheckUrlResultOnUI(const GURL& url, |
| 58 safe_browsing::SBThreatType threat_type, |
| 59 safe_browsing::ThreatPatternType pattern_type); |
| 60 |
| 61 // The time when we started deferring the request. |
| 62 base::TimeTicks defer_start_time_; |
| 63 |
| 64 // Timer to abort the safe browsing check if it takes too long. |
| 65 base::OneShotTimer timer_; |
| 66 |
| 67 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager_; |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterActivationNavigationThrottle); |
| 70 }; |
| 71 |
| 72 } // namespace subresource_filter |
| 73 |
| 74 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_ACTI
VATION_RESOURCE_THROTTLE_H_ |
OLD | NEW |