Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Side by Side Diff: content/browser/loader/navigation_resource_throttle.cc

Issue 1645363002: Revert of Teach navigation throttles how to cancel requests in WillProcessResponse. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/bind.h"
8 #include "base/callback.h" 7 #include "base/callback.h"
9 #include "base/location.h"
10 #include "base/logging.h"
11 #include "content/browser/frame_host/navigation_handle_impl.h" 8 #include "content/browser/frame_host/navigation_handle_impl.h"
12 #include "content/browser/frame_host/render_frame_host_impl.h" 9 #include "content/browser/frame_host/render_frame_host_impl.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/resource_context.h" 10 #include "content/public/browser/resource_context.h"
15 #include "content/public/browser/resource_controller.h" 11 #include "content/public/browser/resource_controller.h"
16 #include "content/public/browser/resource_request_info.h" 12 #include "content/public/browser/resource_request_info.h"
17 #include "content/public/common/referrer.h" 13 #include "content/public/common/referrer.h"
18 #include "net/url_request/redirect_info.h" 14 #include "net/url_request/redirect_info.h"
19 #include "net/url_request/url_request.h" 15 #include "net/url_request/url_request.h"
20 #include "net/url_request/url_request_context.h" 16 #include "net/url_request/url_request_context.h"
21 #include "net/url_request/url_request_job_factory.h" 17 #include "net/url_request/url_request_job_factory.h"
22 #include "ui/base/page_transition_types.h" 18 #include "ui/base/page_transition_types.h"
23 19
24 namespace content { 20 namespace content {
25 21
26 namespace { 22 namespace {
27 typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)> 23 typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)>
28 UIChecksPerformedCallback; 24 UIChecksPerformedCallback;
29 25
30 void SendCheckResultToIOThread(UIChecksPerformedCallback callback, 26 void SendCheckResultToIOThread(UIChecksPerformedCallback callback,
31 NavigationThrottle::ThrottleCheckResult result) { 27 NavigationThrottle::ThrottleCheckResult result) {
32 DCHECK_CURRENTLY_ON(BrowserThread::UI); 28 DCHECK_CURRENTLY_ON(BrowserThread::UI);
33 DCHECK_NE(result, NavigationThrottle::DEFER); 29 CHECK(result != NavigationThrottle::DEFER);
34 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 30 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
35 base::Bind(callback, result)); 31 base::Bind(callback, result));
36 } 32 }
37 33
38 void CheckWillStartRequestOnUIThread(UIChecksPerformedCallback callback, 34 void CheckWillStartRequestOnUIThread(UIChecksPerformedCallback callback,
39 int render_process_id, 35 int render_process_id,
40 int render_frame_host_id, 36 int render_frame_host_id,
41 bool is_post, 37 bool is_post,
42 const Referrer& sanitized_referrer, 38 const Referrer& sanitized_referrer,
43 bool has_user_gesture, 39 bool has_user_gesture,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 GURL new_validated_url(new_url); 86 GURL new_validated_url(new_url);
91 RenderProcessHost::FromID(render_process_id) 87 RenderProcessHost::FromID(render_process_id)
92 ->FilterURL(false, &new_validated_url); 88 ->FilterURL(false, &new_validated_url);
93 navigation_handle->WillRedirectRequest( 89 navigation_handle->WillRedirectRequest(
94 new_validated_url, new_method_is_post, new_referrer_url, 90 new_validated_url, new_method_is_post, new_referrer_url,
95 new_is_external_protocol, headers, 91 new_is_external_protocol, headers,
96 base::Bind(&SendCheckResultToIOThread, callback)); 92 base::Bind(&SendCheckResultToIOThread, callback));
97 } 93 }
98 94
99 void WillProcessResponseOnUIThread( 95 void WillProcessResponseOnUIThread(
100 UIChecksPerformedCallback callback,
101 int render_process_id, 96 int render_process_id,
102 int render_frame_host_id, 97 int render_frame_host_id,
103 scoped_refptr<net::HttpResponseHeaders> headers) { 98 scoped_refptr<net::HttpResponseHeaders> headers) {
104 DCHECK_CURRENTLY_ON(BrowserThread::UI); 99 DCHECK_CURRENTLY_ON(BrowserThread::UI);
105 RenderFrameHostImpl* render_frame_host = 100 RenderFrameHostImpl* render_frame_host =
106 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); 101 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id);
107 if (!render_frame_host) { 102 if (!render_frame_host)
108 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED);
109 return; 103 return;
110 }
111 104
112 NavigationHandleImpl* navigation_handle = 105 NavigationHandleImpl* navigation_handle =
113 render_frame_host->navigation_handle(); 106 render_frame_host->navigation_handle();
114 if (!navigation_handle) { 107 if (!navigation_handle)
115 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED);
116 return; 108 return;
117 }
118 109
119 navigation_handle->WillProcessResponse( 110 navigation_handle->ReadyToCommitNavigation(render_frame_host, headers);
120 render_frame_host, headers,
121 base::Bind(&SendCheckResultToIOThread, callback));
122 } 111 }
123 112
124 } // namespace 113 } // namespace
125 114
126 NavigationResourceThrottle::NavigationResourceThrottle(net::URLRequest* request) 115 NavigationResourceThrottle::NavigationResourceThrottle(net::URLRequest* request)
127 : request_(request), weak_ptr_factory_(this) {} 116 : request_(request), weak_ptr_factory_(this) {}
128 117
129 NavigationResourceThrottle::~NavigationResourceThrottle() {} 118 NavigationResourceThrottle::~NavigationResourceThrottle() {}
130 119
131 void NavigationResourceThrottle::WillStartRequest(bool* defer) { 120 void NavigationResourceThrottle::WillStartRequest(bool* defer) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 return; 197 return;
209 198
210 // Send a copy of the response headers to the NavigationHandle on the UI 199 // Send a copy of the response headers to the NavigationHandle on the UI
211 // thread. 200 // thread.
212 scoped_refptr<net::HttpResponseHeaders> response_headers; 201 scoped_refptr<net::HttpResponseHeaders> response_headers;
213 if (request_->response_headers()) { 202 if (request_->response_headers()) {
214 response_headers = new net::HttpResponseHeaders( 203 response_headers = new net::HttpResponseHeaders(
215 request_->response_headers()->raw_headers()); 204 request_->response_headers()->raw_headers());
216 } 205 }
217 206
218 UIChecksPerformedCallback callback =
219 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed,
220 weak_ptr_factory_.GetWeakPtr());
221
222 BrowserThread::PostTask( 207 BrowserThread::PostTask(
223 BrowserThread::UI, FROM_HERE, 208 BrowserThread::UI, FROM_HERE,
224 base::Bind(&WillProcessResponseOnUIThread, callback, render_process_id, 209 base::Bind(&WillProcessResponseOnUIThread, render_process_id,
225 render_frame_id, response_headers)); 210 render_frame_id, response_headers));
226 *defer = true;
227 } 211 }
228 212
229 const char* NavigationResourceThrottle::GetNameForLogging() const { 213 const char* NavigationResourceThrottle::GetNameForLogging() const {
230 return "NavigationResourceThrottle"; 214 return "NavigationResourceThrottle";
231 } 215 }
232 216
233 void NavigationResourceThrottle::OnUIChecksPerformed( 217 void NavigationResourceThrottle::OnUIChecksPerformed(
234 NavigationThrottle::ThrottleCheckResult result) { 218 NavigationThrottle::ThrottleCheckResult result) {
235 DCHECK_CURRENTLY_ON(BrowserThread::IO); 219 DCHECK_CURRENTLY_ON(BrowserThread::IO);
236 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { 220 if (result == NavigationThrottle::CANCEL_AND_IGNORE) {
237 controller()->CancelAndIgnore(); 221 controller()->CancelAndIgnore();
238 } else if (result == NavigationThrottle::CANCEL) { 222 } else if (result == NavigationThrottle::CANCEL) {
239 controller()->Cancel(); 223 controller()->Cancel();
240 } else { 224 } else {
241 controller()->Resume(); 225 controller()->Resume();
242 } 226 }
243 } 227 }
244 228
245 } // namespace content 229 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_handle_impl_unittest.cc ('k') | content/public/browser/navigation_throttle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698