OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/browser/loader/navigation_resource_throttle.h" | 5 #include "content/browser/loader/navigation_resource_throttle.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "content/browser/frame_host/navigation_handle_impl.h" | 8 #include "content/browser/frame_host/navigation_handle_impl.h" |
9 #include "content/browser/frame_host/render_frame_host_impl.h" | 9 #include "content/browser/frame_host/render_frame_host_impl.h" |
10 #include "content/public/browser/resource_context.h" | 10 #include "content/public/browser/resource_context.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 UIChecksPerformedCallback; | 24 UIChecksPerformedCallback; |
25 | 25 |
26 void SendCheckResultToIOThread(UIChecksPerformedCallback callback, | 26 void SendCheckResultToIOThread(UIChecksPerformedCallback callback, |
27 NavigationThrottle::ThrottleCheckResult result) { | 27 NavigationThrottle::ThrottleCheckResult result) { |
28 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 28 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
29 CHECK(result != NavigationThrottle::DEFER); | 29 CHECK(result != NavigationThrottle::DEFER); |
30 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 30 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
31 base::Bind(callback, result)); | 31 base::Bind(callback, result)); |
32 } | 32 } |
33 | 33 |
34 void MaybeCommitNavigationAndSendCheckResultToIOThread( | |
35 UIChecksPerformedCallback callback, | |
36 int render_process_id, | |
37 int render_frame_host_id, | |
38 scoped_refptr<net::HttpResponseHeaders> headers, | |
39 NavigationThrottle::ThrottleCheckResult result) { | |
40 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
mmenke
2016/01/25 17:57:33
Should include browser_thread header.
Mike West
2016/01/26 09:41:42
Done.
| |
41 CHECK(result != NavigationThrottle::DEFER); | |
mmenke
2016/01/25 17:57:33
CHECK_NE is generally preferred. This file should
Mike West
2016/01/26 09:41:42
Done.
| |
42 if (result == NavigationThrottle::PROCEED) { | |
43 RenderFrameHostImpl* render_frame_host = | |
44 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); | |
45 if (render_frame_host && render_frame_host->navigation_handle()) { | |
46 render_frame_host->navigation_handle()->ReadyToCommitNavigation( | |
clamy
2016/01/25 16:36:21
Could we make this call part of NavigationHandle:
Mike West
2016/01/26 09:41:41
It made more sense to me for NavigationResourceThr
| |
47 render_frame_host, headers); | |
48 } | |
49 } | |
50 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
51 base::Bind(callback, result)); | |
52 } | |
53 | |
34 void CheckWillStartRequestOnUIThread(UIChecksPerformedCallback callback, | 54 void CheckWillStartRequestOnUIThread(UIChecksPerformedCallback callback, |
35 int render_process_id, | 55 int render_process_id, |
36 int render_frame_host_id, | 56 int render_frame_host_id, |
37 bool is_post, | 57 bool is_post, |
38 const Referrer& sanitized_referrer, | 58 const Referrer& sanitized_referrer, |
39 bool has_user_gesture, | 59 bool has_user_gesture, |
40 ui::PageTransition transition, | 60 ui::PageTransition transition, |
41 bool is_external_protocol) { | 61 bool is_external_protocol) { |
42 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 62 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
43 RenderFrameHostImpl* render_frame_host = | 63 RenderFrameHostImpl* render_frame_host = |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 | 105 |
86 GURL new_validated_url(new_url); | 106 GURL new_validated_url(new_url); |
87 RenderProcessHost::FromID(render_process_id) | 107 RenderProcessHost::FromID(render_process_id) |
88 ->FilterURL(false, &new_validated_url); | 108 ->FilterURL(false, &new_validated_url); |
89 navigation_handle->WillRedirectRequest( | 109 navigation_handle->WillRedirectRequest( |
90 new_validated_url, new_method_is_post, new_referrer_url, | 110 new_validated_url, new_method_is_post, new_referrer_url, |
91 new_is_external_protocol, headers, | 111 new_is_external_protocol, headers, |
92 base::Bind(&SendCheckResultToIOThread, callback)); | 112 base::Bind(&SendCheckResultToIOThread, callback)); |
93 } | 113 } |
94 | 114 |
95 void WillProcessResponseOnUIThread( | 115 void WillProcessResponseOnUIThread( |
mmenke
2016/01/25 17:57:33
This is an old method...but was never being used b
Mike West
2016/01/26 09:41:42
It was being used, see the PostTask in NavigationR
| |
116 UIChecksPerformedCallback callback, | |
96 int render_process_id, | 117 int render_process_id, |
97 int render_frame_host_id, | 118 int render_frame_host_id, |
98 scoped_refptr<net::HttpResponseHeaders> headers) { | 119 scoped_refptr<net::HttpResponseHeaders> headers) { |
99 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 120 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
100 RenderFrameHostImpl* render_frame_host = | 121 RenderFrameHostImpl* render_frame_host = |
101 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); | 122 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); |
102 if (!render_frame_host) | 123 if (!render_frame_host) { |
124 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); | |
mmenke
2016/01/25 17:57:33
If there's no RFH, should we really just proceed?
Mike West
2016/01/26 09:41:42
This matches the existing behavior in the other me
clamy
2016/01/26 14:08:54
I think it's possible for downloads started from t
| |
103 return; | 125 return; |
126 } | |
104 | 127 |
105 NavigationHandleImpl* navigation_handle = | 128 NavigationHandleImpl* navigation_handle = |
106 render_frame_host->navigation_handle(); | 129 render_frame_host->navigation_handle(); |
107 if (!navigation_handle) | 130 if (!navigation_handle) { |
131 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); | |
mmenke
2016/01/25 17:57:33
Again, when does this happen?
clamy
2016/01/26 14:08:54
Actually this should never happen. We should proba
| |
108 return; | 132 return; |
133 } | |
109 | 134 |
110 navigation_handle->ReadyToCommitNavigation(render_frame_host, headers); | 135 navigation_handle->WillProcessResponse( |
136 headers, | |
137 base::Bind(&MaybeCommitNavigationAndSendCheckResultToIOThread, callback, | |
138 render_process_id, render_frame_host_id, headers)); | |
111 } | 139 } |
112 | 140 |
113 } // namespace | 141 } // namespace |
114 | 142 |
115 NavigationResourceThrottle::NavigationResourceThrottle(net::URLRequest* request) | 143 NavigationResourceThrottle::NavigationResourceThrottle(net::URLRequest* request) |
116 : request_(request), weak_ptr_factory_(this) {} | 144 : request_(request), weak_ptr_factory_(this) {} |
117 | 145 |
118 NavigationResourceThrottle::~NavigationResourceThrottle() {} | 146 NavigationResourceThrottle::~NavigationResourceThrottle() {} |
119 | 147 |
120 void NavigationResourceThrottle::WillStartRequest(bool* defer) { | 148 void NavigationResourceThrottle::WillStartRequest(bool* defer) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 return; | 225 return; |
198 | 226 |
199 // Send a copy of the response headers to the NavigationHandle on the UI | 227 // Send a copy of the response headers to the NavigationHandle on the UI |
200 // thread. | 228 // thread. |
201 scoped_refptr<net::HttpResponseHeaders> response_headers; | 229 scoped_refptr<net::HttpResponseHeaders> response_headers; |
202 if (request_->response_headers()) { | 230 if (request_->response_headers()) { |
203 response_headers = new net::HttpResponseHeaders( | 231 response_headers = new net::HttpResponseHeaders( |
204 request_->response_headers()->raw_headers()); | 232 request_->response_headers()->raw_headers()); |
205 } | 233 } |
206 | 234 |
235 UIChecksPerformedCallback callback = | |
236 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed, | |
237 weak_ptr_factory_.GetWeakPtr()); | |
238 | |
207 BrowserThread::PostTask( | 239 BrowserThread::PostTask( |
208 BrowserThread::UI, FROM_HERE, | 240 BrowserThread::UI, FROM_HERE, |
209 base::Bind(&WillProcessResponseOnUIThread, render_process_id, | 241 base::Bind(&WillProcessResponseOnUIThread, callback, render_process_id, |
210 render_frame_id, response_headers)); | 242 render_frame_id, response_headers)); |
243 *defer = true; | |
211 } | 244 } |
212 | 245 |
213 const char* NavigationResourceThrottle::GetNameForLogging() const { | 246 const char* NavigationResourceThrottle::GetNameForLogging() const { |
214 return "NavigationResourceThrottle"; | 247 return "NavigationResourceThrottle"; |
215 } | 248 } |
216 | 249 |
217 void NavigationResourceThrottle::OnUIChecksPerformed( | 250 void NavigationResourceThrottle::OnUIChecksPerformed( |
218 NavigationThrottle::ThrottleCheckResult result) { | 251 NavigationThrottle::ThrottleCheckResult result) { |
219 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 252 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
220 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { | 253 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { |
221 controller()->CancelAndIgnore(); | 254 controller()->CancelAndIgnore(); |
222 } else if (result == NavigationThrottle::CANCEL) { | 255 } else if (result == NavigationThrottle::CANCEL) { |
223 controller()->Cancel(); | 256 controller()->Cancel(); |
224 } else { | 257 } else { |
225 controller()->Resume(); | 258 controller()->Resume(); |
226 } | 259 } |
227 } | 260 } |
228 | 261 |
229 } // namespace content | 262 } // namespace content |
OLD | NEW |