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 |
23 ContentSubresourceFilterThrottleManager:: | 54 ContentSubresourceFilterThrottleManager:: |
24 ContentSubresourceFilterThrottleManager( | 55 ContentSubresourceFilterThrottleManager( |
25 Delegate* delegate, | 56 Delegate* delegate, |
26 VerifiedRulesetDealer::Handle* dealer_handle, | 57 VerifiedRulesetDealer::Handle* dealer_handle, |
27 content::WebContents* web_contents) | 58 content::WebContents* web_contents) |
28 : content::WebContentsObserver(web_contents), | 59 : content::WebContentsObserver(web_contents), |
29 dealer_handle_(dealer_handle), | 60 dealer_handle_(dealer_handle), |
30 delegate_(delegate), | 61 delegate_(delegate), |
31 weak_ptr_factory_(this) {} | 62 weak_ptr_factory_(this) {} |
32 | 63 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 OnDocumentLoadStatistics) | 167 OnDocumentLoadStatistics) |
137 IPC_MESSAGE_UNHANDLED(handled = false) | 168 IPC_MESSAGE_UNHANDLED(handled = false) |
138 IPC_END_MESSAGE_MAP() | 169 IPC_END_MESSAGE_MAP() |
139 return handled; | 170 return handled; |
140 } | 171 } |
141 | 172 |
142 void ContentSubresourceFilterThrottleManager::MaybeAppendNavigationThrottles( | 173 void ContentSubresourceFilterThrottleManager::MaybeAppendNavigationThrottles( |
143 content::NavigationHandle* navigation_handle, | 174 content::NavigationHandle* navigation_handle, |
144 std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles) { | 175 std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles) { |
145 DCHECK(!navigation_handle->IsSameDocument()); | 176 DCHECK(!navigation_handle->IsSameDocument()); |
| 177 if (navigation_handle->IsInMainFrame()) { |
| 178 throttles->push_back(base::MakeUnique<ForwardingNavigationThrottle>( |
| 179 navigation_handle, delegate_)); |
| 180 } |
146 if (!dealer_handle_) | 181 if (!dealer_handle_) |
147 return; | 182 return; |
148 if (auto filtering_throttle = | 183 if (auto filtering_throttle = |
149 MaybeCreateSubframeNavigationFilteringThrottle(navigation_handle)) { | 184 MaybeCreateSubframeNavigationFilteringThrottle(navigation_handle)) { |
150 throttles->push_back(std::move(filtering_throttle)); | 185 throttles->push_back(std::move(filtering_throttle)); |
151 } | 186 } |
152 if (auto activation_throttle = | 187 if (auto activation_throttle = |
153 MaybeCreateActivationStateComputingThrottle(navigation_handle)) { | 188 MaybeCreateActivationStateComputingThrottle(navigation_handle)) { |
154 ongoing_activation_throttles_[navigation_handle] = | 189 ongoing_activation_throttles_[navigation_handle] = |
155 activation_throttle.get(); | 190 activation_throttle.get(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 } | 270 } |
236 } | 271 } |
237 | 272 |
238 void ContentSubresourceFilterThrottleManager::OnDocumentLoadStatistics( | 273 void ContentSubresourceFilterThrottleManager::OnDocumentLoadStatistics( |
239 const DocumentLoadStatistics& statistics) { | 274 const DocumentLoadStatistics& statistics) { |
240 if (statistics_) | 275 if (statistics_) |
241 statistics_->OnDocumentLoadStatistics(statistics); | 276 statistics_->OnDocumentLoadStatistics(statistics); |
242 } | 277 } |
243 | 278 |
244 } // namespace subresource_filter | 279 } // namespace subresource_filter |
OLD | NEW |