OLD | NEW |
---|---|
(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 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.
| |
39 std::unordered_map<content::RenderFrameHost*, | |
40 std::unique_ptr<FrameActivationInfo>>; | |
41 using OngoingActivationThrottleMap = | |
42 std::unordered_map<content::NavigationHandle*, | |
43 ActivationStateComputingNavigationThrottle*>; | |
44 | |
45 class ContentSubresourceFilterThrottleManager | |
46 : public content::WebContentsObserver { | |
47 public: | |
48 // It is expected that the Delegate outlives |this|, and manages the lifetime | |
49 // of this class. | |
50 class Delegate : public base::SupportsWeakPtr<Delegate> { | |
51 public: | |
52 virtual VerifiedRulesetDealer::Handle* GetRulesetDealerHandle() = 0; | |
53 | |
54 // The embedder may be interested in displaying UI to the user when the | |
55 // 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.
| |
56 virtual void OnFirstSubresourceLoadDisallowed() {} | |
57 | |
58 // Instruct the delegate to send an IPC to the renderer informing it of | |
59 // activation. | |
60 virtual void OnActivationStateComputedForCommittingLoad( | |
61 content::NavigationHandle* navigation_handle, | |
62 const ActivationState& activation_state) {} | |
63 | |
64 // Let the delegate have the last word when it comes to activation. It might | |
65 // have a specific whitelist. | |
66 virtual bool ShouldVetoActivation( | |
67 content::NavigationHandle* navigation_handle); | |
68 }; | |
69 | |
70 ContentSubresourceFilterThrottleManager(Delegate* delegate, | |
71 content::WebContents* web_contents); | |
72 ~ContentSubresourceFilterThrottleManager() override; | |
73 | |
74 // 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.
| |
75 // activation state computing throttle. | |
76 std::unique_ptr<content::NavigationThrottle> | |
77 MaybeCreateSubframeNavigationFilteringThrottle( | |
78 content::NavigationHandle* navigation_handle); | |
79 std::unique_ptr<content::NavigationThrottle> | |
80 MaybeCreateActivationStateComputingThrottle( | |
81 content::NavigationHandle* navigation_handle); | |
82 | |
83 // Must be called during a navigation, before the corresponding throttle in | |
84 // |ongoing_activation_throttles_ ureaches WillProcessResponse. | |
85 void OnPageStateActivationComputed( | |
86 content::NavigationHandle* activated_navigation, | |
87 const ActivationState& state); | |
88 | |
89 // content::WebContentsObserver: | |
90 void RenderFrameDeleted(content::RenderFrameHost* frame_host) override; | |
91 void ReadyToCommitNavigation( | |
92 content::NavigationHandle* navigation_handle) override; | |
93 void DidFinishNavigation( | |
94 content::NavigationHandle* navigation_handle) override; | |
95 | |
96 private: | |
97 FrameActivationInfo* GetFrameActivationInfoForChildNavigation( | |
98 content::NavigationHandle* child_frame_navigation); | |
99 | |
100 VerifiedRuleset::Handle* EnsureRulesetHandle(); | |
101 | |
102 void OnFirstSubresourceLoadDisallowed(); | |
103 | |
104 // Map of all RenderFrameHosts that are currently activated, and their | |
105 // associated ActivationState and AsyncDocumentSubresourceFilters. | |
106 ActivatedFrameHostMap activated_frame_hosts_; | |
107 | |
108 // 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.
| |
109 // populate the activated_frame_hosts_ map when the navigation is ready to | |
110 // commit. | |
111 OngoingActivationThrottleMap ongoing_activation_throttles_; | |
112 | |
113 // Lazily instantiated in EnsureRulesetHandle when the first page level | |
114 // activation is triggered. Will go away when there are no more activated | |
115 // RenderFrameHosts (i.e. activated_frame_hosts_ is empty). | |
116 std::unique_ptr<VerifiedRuleset::Handle> ruleset_handle_; | |
117 | |
118 // Must outlive this class. | |
119 Delegate* delegate_; | |
120 | |
121 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterThrottleManager); | |
122 }; | |
123 | |
124 } // namespace subresource_filter | |
125 | |
126 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FIL TER_THROTTLE_MANAGER_H_ | |
OLD | NEW |