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 "base/logging.h" | |
mmenke
2016/01/27 16:34:08
While you're here, should also include base/bind.h
| |
8 #include "content/browser/frame_host/navigation_handle_impl.h" | 9 #include "content/browser/frame_host/navigation_handle_impl.h" |
9 #include "content/browser/frame_host/render_frame_host_impl.h" | 10 #include "content/browser/frame_host/render_frame_host_impl.h" |
11 #include "content/public/browser/browser_thread.h" | |
10 #include "content/public/browser/resource_context.h" | 12 #include "content/public/browser/resource_context.h" |
11 #include "content/public/browser/resource_controller.h" | 13 #include "content/public/browser/resource_controller.h" |
12 #include "content/public/browser/resource_request_info.h" | 14 #include "content/public/browser/resource_request_info.h" |
13 #include "content/public/common/referrer.h" | 15 #include "content/public/common/referrer.h" |
14 #include "net/url_request/redirect_info.h" | 16 #include "net/url_request/redirect_info.h" |
15 #include "net/url_request/url_request.h" | 17 #include "net/url_request/url_request.h" |
16 #include "net/url_request/url_request_context.h" | 18 #include "net/url_request/url_request_context.h" |
17 #include "net/url_request/url_request_job_factory.h" | 19 #include "net/url_request/url_request_job_factory.h" |
18 #include "ui/base/page_transition_types.h" | 20 #include "ui/base/page_transition_types.h" |
19 | 21 |
20 namespace content { | 22 namespace content { |
21 | 23 |
22 namespace { | 24 namespace { |
23 typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)> | 25 typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)> |
24 UIChecksPerformedCallback; | 26 UIChecksPerformedCallback; |
25 | 27 |
26 void SendCheckResultToIOThread(UIChecksPerformedCallback callback, | 28 void SendCheckResultToIOThread(UIChecksPerformedCallback callback, |
27 NavigationThrottle::ThrottleCheckResult result) { | 29 NavigationThrottle::ThrottleCheckResult result) { |
28 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 30 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
29 CHECK(result != NavigationThrottle::DEFER); | 31 DCHECK_NE(result, NavigationThrottle::DEFER); |
30 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 32 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
31 base::Bind(callback, result)); | 33 base::Bind(callback, result)); |
32 } | 34 } |
33 | 35 |
34 void CheckWillStartRequestOnUIThread(UIChecksPerformedCallback callback, | 36 void CheckWillStartRequestOnUIThread(UIChecksPerformedCallback callback, |
35 int render_process_id, | 37 int render_process_id, |
36 int render_frame_host_id, | 38 int render_frame_host_id, |
37 bool is_post, | 39 bool is_post, |
38 const Referrer& sanitized_referrer, | 40 const Referrer& sanitized_referrer, |
39 bool has_user_gesture, | 41 bool has_user_gesture, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 GURL new_validated_url(new_url); | 88 GURL new_validated_url(new_url); |
87 RenderProcessHost::FromID(render_process_id) | 89 RenderProcessHost::FromID(render_process_id) |
88 ->FilterURL(false, &new_validated_url); | 90 ->FilterURL(false, &new_validated_url); |
89 navigation_handle->WillRedirectRequest( | 91 navigation_handle->WillRedirectRequest( |
90 new_validated_url, new_method_is_post, new_referrer_url, | 92 new_validated_url, new_method_is_post, new_referrer_url, |
91 new_is_external_protocol, headers, | 93 new_is_external_protocol, headers, |
92 base::Bind(&SendCheckResultToIOThread, callback)); | 94 base::Bind(&SendCheckResultToIOThread, callback)); |
93 } | 95 } |
94 | 96 |
95 void WillProcessResponseOnUIThread( | 97 void WillProcessResponseOnUIThread( |
98 UIChecksPerformedCallback callback, | |
96 int render_process_id, | 99 int render_process_id, |
97 int render_frame_host_id, | 100 int render_frame_host_id, |
98 scoped_refptr<net::HttpResponseHeaders> headers) { | 101 scoped_refptr<net::HttpResponseHeaders> headers) { |
99 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 102 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
100 RenderFrameHostImpl* render_frame_host = | 103 RenderFrameHostImpl* render_frame_host = |
101 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); | 104 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); |
102 if (!render_frame_host) | 105 if (!render_frame_host) { |
106 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); | |
103 return; | 107 return; |
108 } | |
104 | 109 |
105 NavigationHandleImpl* navigation_handle = | 110 NavigationHandleImpl* navigation_handle = |
106 render_frame_host->navigation_handle(); | 111 render_frame_host->navigation_handle(); |
107 if (!navigation_handle) | 112 if (!navigation_handle) { |
113 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); | |
108 return; | 114 return; |
115 } | |
109 | 116 |
110 navigation_handle->ReadyToCommitNavigation(render_frame_host, headers); | 117 navigation_handle->WillProcessResponse( |
118 render_frame_host, headers, | |
119 base::Bind(&SendCheckResultToIOThread, callback)); | |
111 } | 120 } |
112 | 121 |
113 } // namespace | 122 } // namespace |
114 | 123 |
115 NavigationResourceThrottle::NavigationResourceThrottle(net::URLRequest* request) | 124 NavigationResourceThrottle::NavigationResourceThrottle(net::URLRequest* request) |
116 : request_(request), weak_ptr_factory_(this) {} | 125 : request_(request), weak_ptr_factory_(this) {} |
117 | 126 |
118 NavigationResourceThrottle::~NavigationResourceThrottle() {} | 127 NavigationResourceThrottle::~NavigationResourceThrottle() {} |
119 | 128 |
120 void NavigationResourceThrottle::WillStartRequest(bool* defer) { | 129 void NavigationResourceThrottle::WillStartRequest(bool* defer) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 return; | 206 return; |
198 | 207 |
199 // Send a copy of the response headers to the NavigationHandle on the UI | 208 // Send a copy of the response headers to the NavigationHandle on the UI |
200 // thread. | 209 // thread. |
201 scoped_refptr<net::HttpResponseHeaders> response_headers; | 210 scoped_refptr<net::HttpResponseHeaders> response_headers; |
202 if (request_->response_headers()) { | 211 if (request_->response_headers()) { |
203 response_headers = new net::HttpResponseHeaders( | 212 response_headers = new net::HttpResponseHeaders( |
204 request_->response_headers()->raw_headers()); | 213 request_->response_headers()->raw_headers()); |
205 } | 214 } |
206 | 215 |
216 UIChecksPerformedCallback callback = | |
217 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed, | |
218 weak_ptr_factory_.GetWeakPtr()); | |
219 | |
207 BrowserThread::PostTask( | 220 BrowserThread::PostTask( |
208 BrowserThread::UI, FROM_HERE, | 221 BrowserThread::UI, FROM_HERE, |
209 base::Bind(&WillProcessResponseOnUIThread, render_process_id, | 222 base::Bind(&WillProcessResponseOnUIThread, callback, render_process_id, |
210 render_frame_id, response_headers)); | 223 render_frame_id, response_headers)); |
224 *defer = true; | |
211 } | 225 } |
212 | 226 |
213 const char* NavigationResourceThrottle::GetNameForLogging() const { | 227 const char* NavigationResourceThrottle::GetNameForLogging() const { |
214 return "NavigationResourceThrottle"; | 228 return "NavigationResourceThrottle"; |
215 } | 229 } |
216 | 230 |
217 void NavigationResourceThrottle::OnUIChecksPerformed( | 231 void NavigationResourceThrottle::OnUIChecksPerformed( |
218 NavigationThrottle::ThrottleCheckResult result) { | 232 NavigationThrottle::ThrottleCheckResult result) { |
219 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 233 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
220 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { | 234 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { |
221 controller()->CancelAndIgnore(); | 235 controller()->CancelAndIgnore(); |
222 } else if (result == NavigationThrottle::CANCEL) { | 236 } else if (result == NavigationThrottle::CANCEL) { |
223 controller()->Cancel(); | 237 controller()->Cancel(); |
224 } else { | 238 } else { |
225 controller()->Resume(); | 239 controller()->Resume(); |
226 } | 240 } |
227 } | 241 } |
228 | 242 |
229 } // namespace content | 243 } // namespace content |
OLD | NEW |