OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/subresource_filter/content/browser/content_subresource_filt
er_throttle_manager.h" | 5 #include "components/subresource_filter/content/browser/content_subresource_filt
er_throttle_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "components/subresource_filter/content/browser/activation_state_computi
ng_navigation_throttle.h" | 10 #include "components/subresource_filter/content/browser/activation_state_computi
ng_navigation_throttle.h" |
11 #include "components/subresource_filter/content/browser/async_document_subresour
ce_filter.h" | 11 #include "components/subresource_filter/content/browser/async_document_subresour
ce_filter.h" |
12 #include "components/subresource_filter/content/browser/page_load_statistics.h" | 12 #include "components/subresource_filter/content/browser/page_load_statistics.h" |
13 #include "components/subresource_filter/content/browser/subframe_navigation_filt
ering_throttle.h" | 13 #include "components/subresource_filter/content/browser/subframe_navigation_filt
ering_throttle.h" |
14 #include "components/subresource_filter/content/common/subresource_filter_messag
es.h" | 14 #include "components/subresource_filter/content/common/subresource_filter_messag
es.h" |
15 #include "content/public/browser/navigation_handle.h" | 15 #include "content/public/browser/navigation_handle.h" |
16 #include "content/public/browser/navigation_throttle.h" | 16 #include "content/public/browser/navigation_throttle.h" |
17 #include "content/public/browser/render_frame_host.h" | 17 #include "content/public/browser/render_frame_host.h" |
18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
19 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
20 | 20 |
21 namespace subresource_filter { | 21 namespace subresource_filter { |
22 | 22 |
23 namespace { | |
24 | |
25 // Used to forward calls to WillProcessResonse to the driver. | |
26 // TODO(https://crbug.com/708181): Remove this once the safe browsing navigation | |
27 // throttle is responsible for all activation decisions. | |
28 class ForwardingNavigationThrottle : public content::NavigationThrottle { | |
29 public: | |
30 ForwardingNavigationThrottle( | |
31 content::NavigationHandle* handle, | |
32 ContentSubresourceFilterThrottleManager::Delegate* delegate) | |
33 : content::NavigationThrottle(handle), delegate_(delegate) {} | |
34 ~ForwardingNavigationThrottle() override {} | |
35 | |
36 // content::NavigationThrottle: | |
37 content::NavigationThrottle::ThrottleCheckResult WillProcessResponse() | |
38 override { | |
39 delegate_->WillProcessResponse(navigation_handle()); | |
40 return content::NavigationThrottle::PROCEED; | |
41 } | |
42 const char* GetNameForLogging() override { | |
43 return "ForwardingNavigationThrottle"; | |
44 } | |
45 | |
46 private: | |
47 ContentSubresourceFilterThrottleManager::Delegate* delegate_; | |
48 | |
49 DISALLOW_COPY_AND_ASSIGN(ForwardingNavigationThrottle); | |
50 }; | |
51 | |
52 } // namespace | |
53 | |
54 ContentSubresourceFilterThrottleManager:: | 23 ContentSubresourceFilterThrottleManager:: |
55 ContentSubresourceFilterThrottleManager( | 24 ContentSubresourceFilterThrottleManager( |
56 Delegate* delegate, | 25 Delegate* delegate, |
57 VerifiedRulesetDealer::Handle* dealer_handle, | 26 VerifiedRulesetDealer::Handle* dealer_handle, |
58 content::WebContents* web_contents) | 27 content::WebContents* web_contents) |
59 : content::WebContentsObserver(web_contents), | 28 : content::WebContentsObserver(web_contents), |
60 dealer_handle_(dealer_handle), | 29 dealer_handle_(dealer_handle), |
61 delegate_(delegate), | 30 delegate_(delegate), |
62 weak_ptr_factory_(this) {} | 31 weak_ptr_factory_(this) {} |
63 | 32 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 OnDocumentLoadStatistics) | 136 OnDocumentLoadStatistics) |
168 IPC_MESSAGE_UNHANDLED(handled = false) | 137 IPC_MESSAGE_UNHANDLED(handled = false) |
169 IPC_END_MESSAGE_MAP() | 138 IPC_END_MESSAGE_MAP() |
170 return handled; | 139 return handled; |
171 } | 140 } |
172 | 141 |
173 void ContentSubresourceFilterThrottleManager::MaybeAppendNavigationThrottles( | 142 void ContentSubresourceFilterThrottleManager::MaybeAppendNavigationThrottles( |
174 content::NavigationHandle* navigation_handle, | 143 content::NavigationHandle* navigation_handle, |
175 std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles) { | 144 std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles) { |
176 DCHECK(!navigation_handle->IsSameDocument()); | 145 DCHECK(!navigation_handle->IsSameDocument()); |
177 if (navigation_handle->IsInMainFrame()) { | |
178 throttles->push_back(base::MakeUnique<ForwardingNavigationThrottle>( | |
179 navigation_handle, delegate_)); | |
180 } | |
181 if (!dealer_handle_) | 146 if (!dealer_handle_) |
182 return; | 147 return; |
183 if (auto filtering_throttle = | 148 if (auto filtering_throttle = |
184 MaybeCreateSubframeNavigationFilteringThrottle(navigation_handle)) { | 149 MaybeCreateSubframeNavigationFilteringThrottle(navigation_handle)) { |
185 throttles->push_back(std::move(filtering_throttle)); | 150 throttles->push_back(std::move(filtering_throttle)); |
186 } | 151 } |
187 if (auto activation_throttle = | 152 if (auto activation_throttle = |
188 MaybeCreateActivationStateComputingThrottle(navigation_handle)) { | 153 MaybeCreateActivationStateComputingThrottle(navigation_handle)) { |
189 ongoing_activation_throttles_[navigation_handle] = | 154 ongoing_activation_throttles_[navigation_handle] = |
190 activation_throttle.get(); | 155 activation_throttle.get(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 } | 235 } |
271 } | 236 } |
272 | 237 |
273 void ContentSubresourceFilterThrottleManager::OnDocumentLoadStatistics( | 238 void ContentSubresourceFilterThrottleManager::OnDocumentLoadStatistics( |
274 const DocumentLoadStatistics& statistics) { | 239 const DocumentLoadStatistics& statistics) { |
275 if (statistics_) | 240 if (statistics_) |
276 statistics_->OnDocumentLoadStatistics(statistics); | 241 statistics_->OnDocumentLoadStatistics(statistics); |
277 } | 242 } |
278 | 243 |
279 } // namespace subresource_filter | 244 } // namespace subresource_filter |
OLD | NEW |