| OLD | NEW |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #ifndef COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_SAFE_BR
OWSING_ACTIVATION_THROTTLE_H_ | 5 #ifndef COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_SAFE_BR
OWSING_ACTIVATION_THROTTLE_H_ |
| 6 #define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_SAFE_BR
OWSING_ACTIVATION_THROTTLE_H_ | 6 #define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_SAFE_BR
OWSING_ACTIVATION_THROTTLE_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 9 #include <vector> |
| 10 |
| 8 #include "base/macros.h" | 11 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 11 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/time/time.h" |
| 12 #include "components/safe_browsing_db/database_manager.h" | 16 #include "components/safe_browsing_db/database_manager.h" |
| 13 #include "content/public/browser/navigation_throttle.h" | 17 #include "content/public/browser/navigation_throttle.h" |
| 14 #include "url/gurl.h" | 18 |
| 19 class GURL; |
| 15 | 20 |
| 16 namespace subresource_filter { | 21 namespace subresource_filter { |
| 17 | 22 |
| 23 class SubresourceFilterSafeBrowsingClient; |
| 24 |
| 18 // Navigation throttle responsible for activating subresource filtering on page | 25 // Navigation throttle responsible for activating subresource filtering on page |
| 19 // loads that match the SUBRESOURCE_FILTER Safe Browsing list. | 26 // loads that match the SUBRESOURCE_FILTER Safe Browsing list. |
| 20 class SubresourceFilterSafeBrowsingActivationThrottle | 27 class SubresourceFilterSafeBrowsingActivationThrottle |
| 21 : public content::NavigationThrottle, | 28 : public content::NavigationThrottle, |
| 22 public base::SupportsWeakPtr< | 29 public base::SupportsWeakPtr< |
| 23 SubresourceFilterSafeBrowsingActivationThrottle> { | 30 SubresourceFilterSafeBrowsingActivationThrottle> { |
| 24 public: | 31 public: |
| 25 SubresourceFilterSafeBrowsingActivationThrottle( | 32 SubresourceFilterSafeBrowsingActivationThrottle( |
| 26 content::NavigationHandle* handle, | 33 content::NavigationHandle* handle, |
| 34 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 27 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> | 35 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> |
| 28 database_manager); | 36 database_manager); |
| 29 | 37 |
| 30 ~SubresourceFilterSafeBrowsingActivationThrottle() override; | 38 ~SubresourceFilterSafeBrowsingActivationThrottle() override; |
| 31 | 39 |
| 32 // content::NavigationThrottle: | 40 // content::NavigationThrottle: |
| 41 content::NavigationThrottle::ThrottleCheckResult WillStartRequest() override; |
| 42 content::NavigationThrottle::ThrottleCheckResult WillRedirectRequest() |
| 43 override; |
| 33 content::NavigationThrottle::ThrottleCheckResult WillProcessResponse() | 44 content::NavigationThrottle::ThrottleCheckResult WillProcessResponse() |
| 34 override; | 45 override; |
| 35 const char* GetNameForLogging() override; | 46 const char* GetNameForLogging() override; |
| 36 | 47 |
| 37 void OnCheckUrlResultOnUI(const GURL& url, | 48 void OnCheckUrlResultOnUI(const GURL& url, |
| 49 size_t request_id, |
| 38 safe_browsing::SBThreatType threat_type, | 50 safe_browsing::SBThreatType threat_type, |
| 39 safe_browsing::ThreatPatternType pattern_type); | 51 safe_browsing::ThreatPatternType pattern_type); |
| 40 | 52 |
| 41 private: | 53 private: |
| 42 class SBDatabaseClient; | 54 void CheckUrl(); |
| 55 void NotifyResult(); |
| 43 | 56 |
| 57 struct CheckResult { |
| 58 safe_browsing::SBThreatType threat_type = |
| 59 safe_browsing::SBThreatType::SB_THREAT_TYPE_SAFE; |
| 60 safe_browsing::ThreatPatternType pattern_type = |
| 61 safe_browsing::ThreatPatternType::NONE; |
| 62 bool finished = false; |
| 63 }; |
| 64 std::vector<CheckResult> check_results_; |
| 65 |
| 66 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager_; |
| 44 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 67 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 45 std::unique_ptr<SBDatabaseClient, base::OnTaskRunnerDeleter> database_client_; | 68 |
| 69 std::unique_ptr<SubresourceFilterSafeBrowsingClient, |
| 70 base::OnTaskRunnerDeleter> |
| 71 database_client_; |
| 72 |
| 73 // Set to TimeTicks::Now() when the navigation is deferred in |
| 74 // WillProcessResponse. If deferral was not necessary, will remain null. |
| 75 base::TimeTicks defer_time_; |
| 46 | 76 |
| 47 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterSafeBrowsingActivationThrottle); | 77 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterSafeBrowsingActivationThrottle); |
| 48 }; | 78 }; |
| 49 | 79 |
| 50 } // namespace subresource_filter | 80 } // namespace subresource_filter |
| 51 | 81 |
| 52 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_SAFE
_BROWSING_ACTIVATION_THROTTLE_H_ | 82 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_SAFE
_BROWSING_ACTIVATION_THROTTLE_H_ |
| OLD | NEW |