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 74 matching lines...) Loading... |
85 | 85 |
86 GURL new_validated_url(new_url); | 86 GURL new_validated_url(new_url); |
87 RenderProcessHost::FromID(render_process_id) | 87 RenderProcessHost::FromID(render_process_id) |
88 ->FilterURL(false, &new_validated_url); | 88 ->FilterURL(false, &new_validated_url); |
89 navigation_handle->WillRedirectRequest( | 89 navigation_handle->WillRedirectRequest( |
90 new_validated_url, new_method_is_post, new_referrer_url, | 90 new_validated_url, new_method_is_post, new_referrer_url, |
91 new_is_external_protocol, headers, | 91 new_is_external_protocol, headers, |
92 base::Bind(&SendCheckResultToIOThread, callback)); | 92 base::Bind(&SendCheckResultToIOThread, callback)); |
93 } | 93 } |
94 | 94 |
95 void WillProcessResponseOnUIThread( | 95 void CheckWillProcessResponseOnUIThread( |
| 96 UIChecksPerformedCallback callback, |
96 int render_process_id, | 97 int render_process_id, |
97 int render_frame_host_id, | 98 int render_frame_host_id, |
98 scoped_refptr<net::HttpResponseHeaders> headers) { | 99 scoped_refptr<net::HttpResponseHeaders> headers) { |
99 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 100 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
100 RenderFrameHostImpl* render_frame_host = | 101 RenderFrameHostImpl* render_frame_host = |
101 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); | 102 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); |
102 if (!render_frame_host) | 103 if (!render_frame_host) |
103 return; | 104 return; |
104 | 105 |
105 NavigationHandleImpl* navigation_handle = | 106 NavigationHandleImpl* navigation_handle = |
106 render_frame_host->navigation_handle(); | 107 render_frame_host->navigation_handle(); |
107 if (!navigation_handle) | 108 if (!navigation_handle) |
108 return; | 109 return; |
109 | 110 |
110 navigation_handle->ReadyToCommitNavigation(render_frame_host, headers); | 111 navigation_handle->WillProcessResponse( |
| 112 render_frame_host, headers, |
| 113 base::Bind(&SendCheckResultToIOThread, callback)); |
111 } | 114 } |
112 | 115 |
113 } // namespace | 116 } // namespace |
114 | 117 |
115 NavigationResourceThrottle::NavigationResourceThrottle(net::URLRequest* request) | 118 NavigationResourceThrottle::NavigationResourceThrottle(net::URLRequest* request) |
116 : request_(request), weak_ptr_factory_(this) {} | 119 : request_(request), weak_ptr_factory_(this) {} |
117 | 120 |
118 NavigationResourceThrottle::~NavigationResourceThrottle() {} | 121 NavigationResourceThrottle::~NavigationResourceThrottle() {} |
119 | 122 |
120 void NavigationResourceThrottle::WillStartRequest(bool* defer) { | 123 void NavigationResourceThrottle::WillStartRequest(bool* defer) { |
(...skipping 76 matching lines...) Loading... |
197 return; | 200 return; |
198 | 201 |
199 // Send a copy of the response headers to the NavigationHandle on the UI | 202 // Send a copy of the response headers to the NavigationHandle on the UI |
200 // thread. | 203 // thread. |
201 scoped_refptr<net::HttpResponseHeaders> response_headers; | 204 scoped_refptr<net::HttpResponseHeaders> response_headers; |
202 if (request_->response_headers()) { | 205 if (request_->response_headers()) { |
203 response_headers = new net::HttpResponseHeaders( | 206 response_headers = new net::HttpResponseHeaders( |
204 request_->response_headers()->raw_headers()); | 207 request_->response_headers()->raw_headers()); |
205 } | 208 } |
206 | 209 |
| 210 UIChecksPerformedCallback callback = |
| 211 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed, |
| 212 weak_ptr_factory_.GetWeakPtr()); |
| 213 |
207 BrowserThread::PostTask( | 214 BrowserThread::PostTask( |
208 BrowserThread::UI, FROM_HERE, | 215 BrowserThread::UI, FROM_HERE, |
209 base::Bind(&WillProcessResponseOnUIThread, render_process_id, | 216 base::Bind(&CheckWillProcessResponseOnUIThread, callback, |
210 render_frame_id, response_headers)); | 217 render_process_id, render_frame_id, response_headers)); |
211 } | 218 } |
212 | 219 |
213 const char* NavigationResourceThrottle::GetNameForLogging() const { | 220 const char* NavigationResourceThrottle::GetNameForLogging() const { |
214 return "NavigationResourceThrottle"; | 221 return "NavigationResourceThrottle"; |
215 } | 222 } |
216 | 223 |
217 void NavigationResourceThrottle::OnUIChecksPerformed( | 224 void NavigationResourceThrottle::OnUIChecksPerformed( |
218 NavigationThrottle::ThrottleCheckResult result) { | 225 NavigationThrottle::ThrottleCheckResult result) { |
219 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 226 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
220 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { | 227 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { |
221 controller()->CancelAndIgnore(); | 228 controller()->CancelAndIgnore(); |
222 } else if (result == NavigationThrottle::CANCEL) { | 229 } else if (result == NavigationThrottle::CANCEL) { |
223 controller()->Cancel(); | 230 controller()->Cancel(); |
224 } else { | 231 } else { |
225 controller()->Resume(); | 232 controller()->Resume(); |
226 } | 233 } |
227 } | 234 } |
228 | 235 |
229 } // namespace content | 236 } // namespace content |
OLD | NEW |