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" | |
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 CHECK_NE(result, NavigationThrottle::DEFER); |
clamy
2016/01/26 14:08:55
DCHECK? I think we're trying to avoid CHECKs in th
Mike West
2016/01/27 07:44:33
Done.
| |
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 } |
35 | |
36 void MaybeCommitNavigationAndSendCheckResultToIOThread( | |
37 UIChecksPerformedCallback callback, | |
38 int render_process_id, | |
39 int render_frame_host_id, | |
40 scoped_refptr<net::HttpResponseHeaders> headers, | |
41 NavigationThrottle::ThrottleCheckResult result) { | |
42 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
43 CHECK_NE(result, NavigationThrottle::DEFER); | |
mmenke
2016/01/26 16:40:08
DCHECK here, as well, I assume.
Mike West
2016/01/27 07:44:33
Done.
| |
44 if (result == NavigationThrottle::PROCEED) { | |
45 RenderFrameHostImpl* render_frame_host = | |
46 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); | |
47 if (render_frame_host && render_frame_host->navigation_handle()) { | |
48 render_frame_host->navigation_handle()->ReadyToCommitNavigation( | |
49 render_frame_host, headers); | |
mmenke
2016/01/26 16:40:08
This seems weird. We call into the NavigationHand
Mike West
2016/01/27 07:44:33
As I noted in my response to clamy@, it made sense
| |
50 } | |
51 } | |
52 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
53 base::Bind(callback, result)); | |
54 } | |
33 | 55 |
34 void CheckWillStartRequestOnUIThread(UIChecksPerformedCallback callback, | 56 void CheckWillStartRequestOnUIThread(UIChecksPerformedCallback callback, |
35 int render_process_id, | 57 int render_process_id, |
36 int render_frame_host_id, | 58 int render_frame_host_id, |
37 bool is_post, | 59 bool is_post, |
38 const Referrer& sanitized_referrer, | 60 const Referrer& sanitized_referrer, |
39 bool has_user_gesture, | 61 bool has_user_gesture, |
40 ui::PageTransition transition, | 62 ui::PageTransition transition, |
41 bool is_external_protocol) { | 63 bool is_external_protocol) { |
42 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 64 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
43 RenderFrameHostImpl* render_frame_host = | 65 RenderFrameHostImpl* render_frame_host = |
44 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); | 66 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); |
45 if (!render_frame_host) { | 67 if (!render_frame_host) { |
46 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); | 68 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); |
47 return; | 69 return; |
48 } | 70 } |
49 | 71 |
50 NavigationHandleImpl* navigation_handle = | 72 NavigationHandleImpl* navigation_handle = |
51 render_frame_host->navigation_handle(); | 73 render_frame_host->navigation_handle(); |
52 if (!navigation_handle) { | 74 if (!navigation_handle) { |
mmenke
2016/01/26 16:40:08
How certain are we that this is "our" navigation h
clamy
2016/01/26 16:48:05
Because the ResourceRequest is started after the b
| |
53 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); | 75 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); |
54 return; | 76 return; |
55 } | 77 } |
56 | 78 |
57 navigation_handle->WillStartRequest( | 79 navigation_handle->WillStartRequest( |
58 is_post, sanitized_referrer, has_user_gesture, transition, | 80 is_post, sanitized_referrer, has_user_gesture, transition, |
59 is_external_protocol, base::Bind(&SendCheckResultToIOThread, callback)); | 81 is_external_protocol, base::Bind(&SendCheckResultToIOThread, callback)); |
60 } | 82 } |
61 | 83 |
62 void CheckWillRedirectRequestOnUIThread( | 84 void CheckWillRedirectRequestOnUIThread( |
(...skipping 23 matching lines...) Expand all Loading... | |
86 GURL new_validated_url(new_url); | 108 GURL new_validated_url(new_url); |
87 RenderProcessHost::FromID(render_process_id) | 109 RenderProcessHost::FromID(render_process_id) |
88 ->FilterURL(false, &new_validated_url); | 110 ->FilterURL(false, &new_validated_url); |
89 navigation_handle->WillRedirectRequest( | 111 navigation_handle->WillRedirectRequest( |
90 new_validated_url, new_method_is_post, new_referrer_url, | 112 new_validated_url, new_method_is_post, new_referrer_url, |
91 new_is_external_protocol, headers, | 113 new_is_external_protocol, headers, |
92 base::Bind(&SendCheckResultToIOThread, callback)); | 114 base::Bind(&SendCheckResultToIOThread, callback)); |
93 } | 115 } |
94 | 116 |
95 void WillProcessResponseOnUIThread( | 117 void WillProcessResponseOnUIThread( |
118 UIChecksPerformedCallback callback, | |
96 int render_process_id, | 119 int render_process_id, |
97 int render_frame_host_id, | 120 int render_frame_host_id, |
98 scoped_refptr<net::HttpResponseHeaders> headers) { | 121 scoped_refptr<net::HttpResponseHeaders> headers) { |
99 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 122 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
100 RenderFrameHostImpl* render_frame_host = | 123 RenderFrameHostImpl* render_frame_host = |
101 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); | 124 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); |
102 if (!render_frame_host) | 125 if (!render_frame_host) { |
126 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); | |
103 return; | 127 return; |
128 } | |
104 | 129 |
105 NavigationHandleImpl* navigation_handle = | 130 NavigationHandleImpl* navigation_handle = |
106 render_frame_host->navigation_handle(); | 131 render_frame_host->navigation_handle(); |
mmenke
2016/01/26 16:40:08
How sure are we that this is our navigation handle
| |
107 if (!navigation_handle) | 132 if (!navigation_handle) { |
133 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); | |
108 return; | 134 return; |
135 } | |
109 | 136 |
110 navigation_handle->ReadyToCommitNavigation(render_frame_host, headers); | 137 navigation_handle->WillProcessResponse( |
138 headers, | |
139 base::Bind(&MaybeCommitNavigationAndSendCheckResultToIOThread, callback, | |
140 render_process_id, render_frame_host_id, headers)); | |
mmenke
2016/01/26 16:40:08
Hrm...Does seem kinda weird to me that the Navigat
clamy
2016/01/26 16:48:05
This is because the NavigationHandle was built as
| |
111 } | 141 } |
112 | 142 |
113 } // namespace | 143 } // namespace |
114 | 144 |
115 NavigationResourceThrottle::NavigationResourceThrottle(net::URLRequest* request) | 145 NavigationResourceThrottle::NavigationResourceThrottle(net::URLRequest* request) |
116 : request_(request), weak_ptr_factory_(this) {} | 146 : request_(request), weak_ptr_factory_(this) {} |
117 | 147 |
118 NavigationResourceThrottle::~NavigationResourceThrottle() {} | 148 NavigationResourceThrottle::~NavigationResourceThrottle() {} |
119 | 149 |
120 void NavigationResourceThrottle::WillStartRequest(bool* defer) { | 150 void NavigationResourceThrottle::WillStartRequest(bool* defer) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 return; | 227 return; |
198 | 228 |
199 // Send a copy of the response headers to the NavigationHandle on the UI | 229 // Send a copy of the response headers to the NavigationHandle on the UI |
200 // thread. | 230 // thread. |
201 scoped_refptr<net::HttpResponseHeaders> response_headers; | 231 scoped_refptr<net::HttpResponseHeaders> response_headers; |
202 if (request_->response_headers()) { | 232 if (request_->response_headers()) { |
203 response_headers = new net::HttpResponseHeaders( | 233 response_headers = new net::HttpResponseHeaders( |
204 request_->response_headers()->raw_headers()); | 234 request_->response_headers()->raw_headers()); |
205 } | 235 } |
206 | 236 |
237 UIChecksPerformedCallback callback = | |
238 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed, | |
239 weak_ptr_factory_.GetWeakPtr()); | |
240 | |
207 BrowserThread::PostTask( | 241 BrowserThread::PostTask( |
208 BrowserThread::UI, FROM_HERE, | 242 BrowserThread::UI, FROM_HERE, |
209 base::Bind(&WillProcessResponseOnUIThread, render_process_id, | 243 base::Bind(&WillProcessResponseOnUIThread, callback, render_process_id, |
210 render_frame_id, response_headers)); | 244 render_frame_id, response_headers)); |
245 *defer = true; | |
211 } | 246 } |
212 | 247 |
213 const char* NavigationResourceThrottle::GetNameForLogging() const { | 248 const char* NavigationResourceThrottle::GetNameForLogging() const { |
214 return "NavigationResourceThrottle"; | 249 return "NavigationResourceThrottle"; |
215 } | 250 } |
216 | 251 |
217 void NavigationResourceThrottle::OnUIChecksPerformed( | 252 void NavigationResourceThrottle::OnUIChecksPerformed( |
218 NavigationThrottle::ThrottleCheckResult result) { | 253 NavigationThrottle::ThrottleCheckResult result) { |
219 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 254 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
220 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { | 255 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { |
221 controller()->CancelAndIgnore(); | 256 controller()->CancelAndIgnore(); |
222 } else if (result == NavigationThrottle::CANCEL) { | 257 } else if (result == NavigationThrottle::CANCEL) { |
223 controller()->Cancel(); | 258 controller()->Cancel(); |
224 } else { | 259 } else { |
225 controller()->Resume(); | 260 controller()->Resume(); |
226 } | 261 } |
227 } | 262 } |
228 | 263 |
229 } // namespace content | 264 } // namespace content |
OLD | NEW |