Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(472)

Unified Diff: components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h

Issue 2691423006: Introduce the ThrottleManager (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..3e7dfe7f691ffb513fafede22e18b3dae851716c
--- /dev/null
+++ b/components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h
@@ -0,0 +1,126 @@
+// 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;
+};
+
+using ActivatedFrameHostMap =
engedy 2017/02/17 15:34:27 nit: We should at least move this down to the `pri
Charlie Harrison 2017/02/17 18:04:35 Got rid of them.
+ std::unordered_map<content::RenderFrameHost*,
+ std::unique_ptr<FrameActivationInfo>>;
+using OngoingActivationThrottleMap =
+ std::unordered_map<content::NavigationHandle*,
+ ActivationStateComputingNavigationThrottle*>;
+
+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:
+ virtual VerifiedRulesetDealer::Handle* GetRulesetDealerHandle() = 0;
+
+ // The embedder may be interested in displaying UI to the user when the
+ // first load is disallowed.
engedy 2017/02/17 15:34:27 nit: ... for a given page load.
Charlie Harrison 2017/02/17 18:04:35 Done.
+ virtual void OnFirstSubresourceLoadDisallowed() {}
+
+ // Instruct the delegate to send an IPC to the renderer informing it of
+ // activation.
+ virtual void OnActivationStateComputedForCommittingLoad(
+ content::NavigationHandle* navigation_handle,
+ const ActivationState& activation_state) {}
+
+ // 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,
+ content::WebContents* web_contents);
+ ~ContentSubresourceFilterThrottleManager() override;
+
+ // The subframe navigation filtering throttle must be inserted before the
engedy 2017/02/17 15:34:27 On second thought, does the order really matter he
Charlie Harrison 2017/02/17 18:04:36 You're right, I've removed the comment.
+ // activation state computing throttle.
+ std::unique_ptr<content::NavigationThrottle>
+ MaybeCreateSubframeNavigationFilteringThrottle(
+ content::NavigationHandle* navigation_handle);
+ std::unique_ptr<content::NavigationThrottle>
+ MaybeCreateActivationStateComputingThrottle(
+ content::NavigationHandle* navigation_handle);
+
+ // Must be called during a navigation, before the corresponding throttle in
+ // |ongoing_activation_throttles_ ureaches 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;
+
+ private:
+ FrameActivationInfo* GetFrameActivationInfoForChildNavigation(
+ content::NavigationHandle* child_frame_navigation);
+
+ VerifiedRuleset::Handle* EnsureRulesetHandle();
+
+ void OnFirstSubresourceLoadDisallowed();
+
+ // Map of all RenderFrameHosts that are currently activated, and their
+ // associated ActivationState and AsyncDocumentSubresourceFilters.
+ ActivatedFrameHostMap activated_frame_hosts_;
+
+ // Map of all ongoing activation computing throttles. This is needed to
engedy 2017/02/17 15:34:27 Phrasing suggestion: For each ongoing navigation
Charlie Harrison 2017/02/17 18:04:35 Done.
+ // populate the activated_frame_hosts_ map when the navigation is ready to
+ // commit.
+ OngoingActivationThrottleMap 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_;
+
+ // Must outlive this class.
+ Delegate* delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterThrottleManager);
+};
+
+} // namespace subresource_filter
+
+#endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FILTER_THROTTLE_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698