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

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

Issue 2691423006: Introduce the ThrottleManager (Closed)
Patch Set: respond to more 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 {
engedy 2017/02/20 15:58:13 nit: Can the definition of this struct be moved to
Charlie Harrison 2017/03/01 00:02:58 Let me just move the ActivationState into ADSF in
32 FrameActivationInfo();
33 ~FrameActivationInfo();
34 std::unique_ptr<AsyncDocumentSubresourceFilter> subresource_filter;
35 ActivationState activation_state;
36 };
37
38 class ContentSubresourceFilterThrottleManager
engedy 2017/02/20 15:58:13 nit: Let's describe what this is in a comment!
Charlie Harrison 2017/03/01 00:02:59 Done.
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 {
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(
engedy 2017/02/20 15:58:13 nit: s/Veto/Suppress/, my understanding is that a
Charlie Harrison 2017/03/01 00:02:58 Done.
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
engedy 2017/02/20 15:58:13 Let's make this interface less implementation-orie
Charlie Harrison 2017/03/01 00:02:58 Done.
62 // |ongoing_activation_throttles_| reaches WillProcessResponse.
63 void NotifyPageActivationComputed(
64 content::NavigationHandle* activated_navigation,
engedy 2017/02/20 15:58:13 nit: s/activated_navigation/navigation/, it's not
Charlie Harrison 2017/03/01 00:02:56 I s/activated_navigation/navigation_handle/
65 const ActivationState& activation_state);
66
67 // content::WebContentsObserver:
engedy 2017/02/20 15:58:13 Could we make these protected?
Charlie Harrison 2017/03/01 00:02:58 Done.
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 MaybeAppendNavigationThrottles(
engedy 2017/02/20 15:58:13 nit: Given this is the public API of this class, a
Charlie Harrison 2017/03/01 00:02:58 Done, I mentioned that in fact there are no orderi
engedy 2017/03/10 17:36:20 Sounds good.
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 // Calls OnFirstSubresourceLoadDisallowed on the Delegate at most once per
90 // committed load.
engedy 2017/02/20 15:58:13 nit: once per committed, non-same-page navigation
Charlie Harrison 2017/03/01 00:02:58 Done.
91 // TODO(csharrison): Ensure IPCs from the renderer go through this path when
92 // they disallow subresource loads.
93 void MaybeCallFirstDisallowedLoad();
94
95 VerifiedRuleset::Handle* EnsureRulesetHandle();
96 void DestroyRulesetHandleIfNecessary();
engedy 2017/02/20 15:58:13 nit: s/Necessary/NoLongerUsed/
Charlie Harrison 2017/03/01 00:02:58 Done.
97
98 // Map of all RenderFrameHosts that are currently activated, and their
engedy 2017/02/20 15:58:13 Phrasing nit: For each RenderFrameHost where the l
Charlie Harrison 2017/03/01 00:02:58 Done.
99 // associated ActivationState and AsyncDocumentSubresourceFilters.
100 std::unordered_map<content::RenderFrameHost*,
101 std::unique_ptr<FrameActivationInfo>>
102 activated_frame_hosts_;
103
104 // For each ongoing navigation that requires activation state computation,
105 // keeps track of the throttle that is carrying out that computation, so that
106 // the result can be retrieved when the navigation is ready to commit.
107 std::unordered_map<content::NavigationHandle*,
108 ActivationStateComputingNavigationThrottle*>
109 ongoing_activation_throttles_;
110
111 // Lazily instantiated in EnsureRulesetHandle when the first page level
112 // activation is triggered. Will go away when there are no more activated
113 // RenderFrameHosts (i.e. activated_frame_hosts_ is empty).
114 std::unique_ptr<VerifiedRuleset::Handle> ruleset_handle_;
115
116 // True if the current committed main frame load in this WebContents has
117 // notified the delegate that a subresource was disallowed. The callback
118 // should only be called at most once per main frame load.
119 bool current_committed_load_has_notified_disallowed_load_ = false;
120
121 // These members outlive this class.
122 VerifiedRulesetDealer::Handle* dealer_handle_;
123 Delegate* delegate_;
124
125 base::WeakPtrFactory<ContentSubresourceFilterThrottleManager>
126 weak_ptr_factory_;
127
128 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterThrottleManager);
129 };
130
131 } // namespace subresource_filter
132
133 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FIL TER_THROTTLE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698