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

Side by Side Diff: components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h

Issue 2691423006: Introduce the ThrottleManager (Closed)
Patch Set: engedy initial comments 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FILTER _THROTTLE_MANAGER_H_
6 #define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FILTER _THROTTLE_MANAGER_H_
7
8 #include <memory>
9 #include <unordered_map>
10
11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h"
13 #include "components/subresource_filter/content/browser/verified_ruleset_dealer. h"
14 #include "components/subresource_filter/core/common/activation_state.h"
15 #include "content/public/browser/web_contents_observer.h"
16
17 namespace content {
18 class NavigationHandle;
19 class NavigationThrottle;
20 class RenderFrameHost;
21 } // namespace content
22
23 namespace subresource_filter {
24
25 class AsyncDocumentSubresourceFilter;
26 class ActivationStateComputingNavigationThrottle;
27
28 // Simple struct which contains useful information regarding a frame's
29 // activation. This includes its DocumentSubresourceFilter, as well as its
30 // ActivationState.
31 struct FrameActivationInfo {
32 FrameActivationInfo();
33 ~FrameActivationInfo();
34 std::unique_ptr<AsyncDocumentSubresourceFilter> subresource_filter;
35 ActivationState activation_state;
36 };
37
38 class ContentSubresourceFilterThrottleManager
39 : public content::WebContentsObserver {
40 public:
41 // It is expected that the Delegate outlives |this|, and manages the lifetime
42 // of this class.
43 class Delegate : public base::SupportsWeakPtr<Delegate> {
44 public:
45 // The embedder may be interested in displaying UI to the user when the
46 // first load is disallowed for a given page load.
47 virtual void OnFirstSubresourceLoadDisallowed() {}
48
49 // Let the delegate have the last word when it comes to activation. It might
50 // have a specific whitelist.
51 virtual bool ShouldVetoActivation(
52 content::NavigationHandle* navigation_handle);
53 };
54
55 ContentSubresourceFilterThrottleManager(
56 Delegate* delegate,
57 VerifiedRulesetDealer::Handle* dealer_handle,
58 content::WebContents* web_contents);
59 ~ContentSubresourceFilterThrottleManager() override;
60
61 // Must be called during a navigation, before the corresponding throttle in
62 // |ongoing_activation_throttles_| reaches WillProcessResponse.
63 void OnPageStateActivationComputed(
64 content::NavigationHandle* activated_navigation,
65 const ActivationState& state);
66
67 // content::WebContentsObserver:
68 void RenderFrameDeleted(content::RenderFrameHost* frame_host) override;
69 void ReadyToCommitNavigation(
70 content::NavigationHandle* navigation_handle) override;
71 void DidFinishNavigation(
72 content::NavigationHandle* navigation_handle) override;
73
74 void MaybeInsertNavigationThrottles(
75 content::NavigationHandle* navigation_handle,
76 std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles);
77
78 private:
79 std::unique_ptr<content::NavigationThrottle>
80 MaybeCreateSubframeNavigationFilteringThrottle(
81 content::NavigationHandle* navigation_handle);
82 std::unique_ptr<content::NavigationThrottle>
83 MaybeCreateActivationStateComputingThrottle(
84 content::NavigationHandle* navigation_handle);
85
86 FrameActivationInfo* GetFrameActivationInfoForChildNavigation(
87 content::NavigationHandle* child_frame_navigation);
88
89 VerifiedRuleset::Handle* EnsureRulesetHandle();
90
91 // Map of all RenderFrameHosts that are currently activated, and their
92 // associated ActivationState and AsyncDocumentSubresourceFilters.
93 std::unordered_map<content::RenderFrameHost*,
94 std::unique_ptr<FrameActivationInfo>>
95 activated_frame_hosts_;
96
97 // For each ongoing navigation that requires activation state computation,
98 // keeps track of the throttle that is carrying out that computation, so that
99 // the result can be retrieved when the navigation is ready to commit.
100 std::unordered_map<content::NavigationHandle*,
101 ActivationStateComputingNavigationThrottle*>
102 ongoing_activation_throttles_;
103
104 // Lazily instantiated in EnsureRulesetHandle when the first page level
105 // activation is triggered. Will go away when there are no more activated
106 // RenderFrameHosts (i.e. activated_frame_hosts_ is empty).
107 std::unique_ptr<VerifiedRuleset::Handle> ruleset_handle_;
108
109 // These members outlive this class.
110 VerifiedRulesetDealer::Handle* dealer_handle_;
111 Delegate* delegate_;
112
113 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterThrottleManager);
114 };
115
116 } // namespace subresource_filter
117
118 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FIL TER_THROTTLE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698