Index: components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h |
diff --git a/components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h b/components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..82cda705da6d8ac1a87e4e24da288de43c1f98e6 |
--- /dev/null |
+++ b/components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h |
@@ -0,0 +1,118 @@ |
+// Copyright 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_CONTENT_SUBRESOURCE_FILTER_THROTTLE_MANAGER_H_ |
+#define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FILTER_THROTTLE_MANAGER_H_ |
+ |
+#include <memory> |
+#include <unordered_map> |
+ |
+#include "base/macros.h" |
+#include "base/memory/weak_ptr.h" |
+#include "components/subresource_filter/content/browser/verified_ruleset_dealer.h" |
+#include "components/subresource_filter/core/common/activation_state.h" |
+#include "content/public/browser/web_contents_observer.h" |
+ |
+namespace content { |
+class NavigationHandle; |
+class NavigationThrottle; |
+class RenderFrameHost; |
+} // namespace content |
+ |
+namespace subresource_filter { |
+ |
+class AsyncDocumentSubresourceFilter; |
+class ActivationStateComputingNavigationThrottle; |
+ |
+// Simple struct which contains useful information regarding a frame's |
+// activation. This includes its DocumentSubresourceFilter, as well as its |
+// ActivationState. |
+struct FrameActivationInfo { |
+ FrameActivationInfo(); |
+ ~FrameActivationInfo(); |
+ std::unique_ptr<AsyncDocumentSubresourceFilter> subresource_filter; |
+ ActivationState activation_state; |
+}; |
+ |
+class ContentSubresourceFilterThrottleManager |
+ : public content::WebContentsObserver { |
+ public: |
+ // It is expected that the Delegate outlives |this|, and manages the lifetime |
+ // of this class. |
+ class Delegate : public base::SupportsWeakPtr<Delegate> { |
+ public: |
+ // The embedder may be interested in displaying UI to the user when the |
+ // first load is disallowed for a given page load. |
+ virtual void OnFirstSubresourceLoadDisallowed() {} |
+ |
+ // Let the delegate have the last word when it comes to activation. It might |
+ // have a specific whitelist. |
+ virtual bool ShouldVetoActivation( |
+ content::NavigationHandle* navigation_handle); |
+ }; |
+ |
+ ContentSubresourceFilterThrottleManager( |
+ Delegate* delegate, |
+ VerifiedRulesetDealer::Handle* dealer_handle, |
+ content::WebContents* web_contents); |
+ ~ContentSubresourceFilterThrottleManager() override; |
+ |
+ // Must be called during a navigation, before the corresponding throttle in |
+ // |ongoing_activation_throttles_| reaches WillProcessResponse. |
+ void OnPageStateActivationComputed( |
+ content::NavigationHandle* activated_navigation, |
+ const ActivationState& state); |
+ |
+ // content::WebContentsObserver: |
+ void RenderFrameDeleted(content::RenderFrameHost* frame_host) override; |
+ void ReadyToCommitNavigation( |
+ content::NavigationHandle* navigation_handle) override; |
+ void DidFinishNavigation( |
+ content::NavigationHandle* navigation_handle) override; |
+ |
+ void MaybeInsertNavigationThrottles( |
+ content::NavigationHandle* navigation_handle, |
+ std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles); |
+ |
+ private: |
+ std::unique_ptr<content::NavigationThrottle> |
+ MaybeCreateSubframeNavigationFilteringThrottle( |
+ content::NavigationHandle* navigation_handle); |
+ std::unique_ptr<content::NavigationThrottle> |
+ MaybeCreateActivationStateComputingThrottle( |
+ content::NavigationHandle* navigation_handle); |
+ |
+ FrameActivationInfo* GetFrameActivationInfoForChildNavigation( |
+ content::NavigationHandle* child_frame_navigation); |
+ |
+ VerifiedRuleset::Handle* EnsureRulesetHandle(); |
+ |
+ // Map of all RenderFrameHosts that are currently activated, and their |
+ // associated ActivationState and AsyncDocumentSubresourceFilters. |
+ std::unordered_map<content::RenderFrameHost*, |
+ std::unique_ptr<FrameActivationInfo>> |
+ activated_frame_hosts_; |
+ |
+ // For each ongoing navigation that requires activation state computation, |
+ // keeps track of the throttle that is carrying out that computation, so that |
+ // the result can be retrieved when the navigation is ready to commit. |
+ std::unordered_map<content::NavigationHandle*, |
+ ActivationStateComputingNavigationThrottle*> |
+ ongoing_activation_throttles_; |
+ |
+ // Lazily instantiated in EnsureRulesetHandle when the first page level |
+ // activation is triggered. Will go away when there are no more activated |
+ // RenderFrameHosts (i.e. activated_frame_hosts_ is empty). |
+ std::unique_ptr<VerifiedRuleset::Handle> ruleset_handle_; |
+ |
+ // These members outlive this class. |
+ VerifiedRulesetDealer::Handle* dealer_handle_; |
+ Delegate* delegate_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterThrottleManager); |
+}; |
+ |
+} // namespace subresource_filter |
+ |
+#endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FILTER_THROTTLE_MANAGER_H_ |