Index: components/subresource_filter/content/browser/subresource_filter_activation_navigation_throttle.h |
diff --git a/components/subresource_filter/content/browser/subresource_filter_activation_navigation_throttle.h b/components/subresource_filter/content/browser/subresource_filter_activation_navigation_throttle.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..81770789b169c1b9a9f1a970858b18d0f021ccc7 |
--- /dev/null |
+++ b/components/subresource_filter/content/browser/subresource_filter_activation_navigation_throttle.h |
@@ -0,0 +1,74 @@ |
+// Copyright (c) 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_ACTIVATION_RESOURCE_THROTTLE_H_ |
+#define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_ACTIVATION_RESOURCE_THROTTLE_H_ |
+ |
+#include <string> |
+#include <vector> |
+ |
+#include "base/macros.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/time/time.h" |
+#include "base/timer/timer.h" |
+#include "components/safe_browsing_db/database_manager.h" |
+#include "content/public/browser/navigation_throttle.h" |
+#include "url/gurl.h" |
+ |
+namespace subresource_filter { |
+ |
+// Client for accessing list with patterns to be used by the Subresource Filter. |
+class SubresourceFilterActivationNavigationThrottle |
+ : public content::NavigationThrottle, |
+ public safe_browsing::SafeBrowsingDatabaseManager::Client, |
+ public base::SupportsWeakPtr< |
+ SubresourceFilterActivationNavigationThrottle> { |
+ public: |
+ SubresourceFilterActivationNavigationThrottle( |
+ content::NavigationHandle* handle, |
+ const scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>& |
+ database_manager); |
+ |
+ ~SubresourceFilterActivationNavigationThrottle() override; |
+ |
+ content::NavigationThrottle::ThrottleCheckResult WillProcessResponse() |
+ override; |
+ |
+ // SafeBrowsingDabaseManager::Client implementation (called on IO thread): |
+ void OnCheckBrowseUrlResult( |
+ const GURL& url, |
+ safe_browsing::SBThreatType result, |
+ const safe_browsing::ThreatMetadata& metadata) override; |
+ |
+ private: |
+ // Starts running |url| through the safe browsing check. Returns true if the |
+ // URL doesn't belong to the Subresource Filter only list. Otherwise returns |
+ // false and will call OnCheckBrowseUrlResult() when the check |
+ // has completed. |
+ bool CheckUrl(const GURL& url); |
+ |
+ // Callback for when the safe browsing check has taken longer than |
+ // kCheckUrlTimeoutMs. |
+ void OnCheckUrlTimeout(); |
+ |
+ void CheckUrlOnIO(const GURL& url); |
+ |
+ void OnCheckUrlResultOnUI(const GURL& url, |
+ safe_browsing::SBThreatType threat_type, |
+ safe_browsing::ThreatPatternType pattern_type); |
+ |
+ // The time when we started deferring the request. |
+ base::TimeTicks defer_start_time_; |
+ |
+ // Timer to abort the safe browsing check if it takes too long. |
+ base::OneShotTimer timer_; |
+ |
+ scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SubresourceFilterActivationNavigationThrottle); |
+}; |
+ |
+} // namespace subresource_filter |
+ |
+#endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_ACTIVATION_RESOURCE_THROTTLE_H_ |