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

Side by Side Diff: chrome/browser/renderer_host/cross_site_resource_handler.cc

Issue 460108: Implement ResourceQueue, an object that makes it easy to delay starting (Closed)
Patch Set: nitfixing Created 11 years 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 (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <string> 5 #include <string>
6 6
7 #include "chrome/browser/renderer_host/cross_site_resource_handler.h" 7 #include "chrome/browser/renderer_host/cross_site_resource_handler.h"
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "chrome/browser/chrome_thread.h" 10 #include "chrome/browser/chrome_thread.h"
11 #include "chrome/browser/renderer_host/global_request_id.h"
11 #include "chrome/browser/renderer_host/render_view_host.h" 12 #include "chrome/browser/renderer_host/render_view_host.h"
12 #include "chrome/browser/renderer_host/render_view_host_delegate.h" 13 #include "chrome/browser/renderer_host/render_view_host_delegate.h"
14 #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
13 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" 15 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h"
14 #include "net/base/io_buffer.h" 16 #include "net/base/io_buffer.h"
15 17
16 namespace { 18 namespace {
17 19
18 // Task to notify the TabContents that a cross-site response has begun, so that 20 // Task to notify the TabContents that a cross-site response has begun, so that
19 // TabContents can tell the old page to run its onunload handler. 21 // TabContents can tell the old page to run its onunload handler.
20 class CrossSiteNotifyTask : public Task { 22 class CrossSiteNotifyTask : public Task {
21 public: 23 public:
22 CrossSiteNotifyTask(int render_process_host_id, 24 CrossSiteNotifyTask(int render_process_host_id,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 bool CrossSiteResourceHandler::OnResponseStarted(int request_id, 100 bool CrossSiteResourceHandler::OnResponseStarted(int request_id,
99 ResourceResponse* response) { 101 ResourceResponse* response) {
100 // At this point, we know that the response is safe to send back to the 102 // At this point, we know that the response is safe to send back to the
101 // renderer: it is not a download, and it has passed the SSL and safe 103 // renderer: it is not a download, and it has passed the SSL and safe
102 // browsing checks. 104 // browsing checks.
103 // We should not have already started the transition before now. 105 // We should not have already started the transition before now.
104 DCHECK(!in_cross_site_transition_); 106 DCHECK(!in_cross_site_transition_);
105 has_started_response_ = true; 107 has_started_response_ = true;
106 108
107 // Look up the request and associated info. 109 // Look up the request and associated info.
108 ResourceDispatcherHost::GlobalRequestID global_id(render_process_host_id_, 110 GlobalRequestID global_id(render_process_host_id_, request_id);
109 request_id);
110 URLRequest* request = rdh_->GetURLRequest(global_id); 111 URLRequest* request = rdh_->GetURLRequest(global_id);
111 if (!request) { 112 if (!request) {
112 DLOG(WARNING) << "Request wasn't found"; 113 DLOG(WARNING) << "Request wasn't found";
113 return false; 114 return false;
114 } 115 }
115 ResourceDispatcherHostRequestInfo* info = 116 ResourceDispatcherHostRequestInfo* info =
116 ResourceDispatcherHost::InfoForRequest(request); 117 ResourceDispatcherHost::InfoForRequest(request);
117 118
118 // If this is a download, just pass the response through without doing a 119 // If this is a download, just pass the response through without doing a
119 // cross-site check. The renderer will see it is a download and abort the 120 // cross-site check. The renderer will see it is a download and abort the
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 ChromeThread::UI, FROM_HERE, 166 ChromeThread::UI, FROM_HERE,
166 new CancelPendingRenderViewTask( 167 new CancelPendingRenderViewTask(
167 render_process_host_id_, render_view_id_)); 168 render_process_host_id_, render_view_id_));
168 return next_handler_->OnResponseCompleted(request_id, status, 169 return next_handler_->OnResponseCompleted(request_id, status,
169 security_info); 170 security_info);
170 } else { 171 } else {
171 // An error occured, we should wait now for the cross-site transition, 172 // An error occured, we should wait now for the cross-site transition,
172 // so that the error message (e.g., 404) can be displayed to the user. 173 // so that the error message (e.g., 404) can be displayed to the user.
173 // Also continue with the logic below to remember that we completed 174 // Also continue with the logic below to remember that we completed
174 // during the cross-site transition. 175 // during the cross-site transition.
175 ResourceDispatcherHost::GlobalRequestID global_id( 176 GlobalRequestID global_id(render_process_host_id_, request_id);
176 render_process_host_id_, request_id);
177 StartCrossSiteTransition(request_id, NULL, global_id); 177 StartCrossSiteTransition(request_id, NULL, global_id);
178 } 178 }
179 } 179 }
180 } 180 }
181 181
182 // We have to buffer the call until after the transition completes. 182 // We have to buffer the call until after the transition completes.
183 completed_during_transition_ = true; 183 completed_during_transition_ = true;
184 completed_status_ = status; 184 completed_status_ = status;
185 completed_security_info_ = security_info; 185 completed_security_info_ = security_info;
186 186
187 // Return false to tell RDH not to notify the world or clean up the 187 // Return false to tell RDH not to notify the world or clean up the
188 // pending request. We will do so in ResumeResponse. 188 // pending request. We will do so in ResumeResponse.
189 return false; 189 return false;
190 } 190 }
191 191
192 // We can now send the response to the new renderer, which will cause 192 // We can now send the response to the new renderer, which will cause
193 // TabContents to swap in the new renderer and destroy the old one. 193 // TabContents to swap in the new renderer and destroy the old one.
194 void CrossSiteResourceHandler::ResumeResponse() { 194 void CrossSiteResourceHandler::ResumeResponse() {
195 DCHECK(request_id_ != -1); 195 DCHECK(request_id_ != -1);
196 DCHECK(in_cross_site_transition_); 196 DCHECK(in_cross_site_transition_);
197 in_cross_site_transition_ = false; 197 in_cross_site_transition_ = false;
198 198
199 // Find the request for this response. 199 // Find the request for this response.
200 ResourceDispatcherHost::GlobalRequestID global_id(render_process_host_id_, 200 GlobalRequestID global_id(render_process_host_id_, request_id_);
201 request_id_);
202 URLRequest* request = rdh_->GetURLRequest(global_id); 201 URLRequest* request = rdh_->GetURLRequest(global_id);
203 if (!request) { 202 if (!request) {
204 DLOG(WARNING) << "Resuming a request that wasn't found"; 203 DLOG(WARNING) << "Resuming a request that wasn't found";
205 return; 204 return;
206 } 205 }
207 206
208 if (has_started_response_) { 207 if (has_started_response_) {
209 // Send OnResponseStarted to the new renderer. 208 // Send OnResponseStarted to the new renderer.
210 DCHECK(response_); 209 DCHECK(response_);
211 next_handler_->OnResponseStarted(request_id_, response_); 210 next_handler_->OnResponseStarted(request_id_, response_);
(...skipping 19 matching lines...) Expand all
231 rdh_->NotifyResponseCompleted(request, render_process_host_id_); 230 rdh_->NotifyResponseCompleted(request, render_process_host_id_);
232 rdh_->RemovePendingRequest(render_process_host_id_, request_id_); 231 rdh_->RemovePendingRequest(render_process_host_id_, request_id_);
233 } 232 }
234 } 233 }
235 234
236 // Prepare to render the cross-site response in a new RenderViewHost, by 235 // Prepare to render the cross-site response in a new RenderViewHost, by
237 // telling the old RenderViewHost to run its onunload handler. 236 // telling the old RenderViewHost to run its onunload handler.
238 void CrossSiteResourceHandler::StartCrossSiteTransition( 237 void CrossSiteResourceHandler::StartCrossSiteTransition(
239 int request_id, 238 int request_id,
240 ResourceResponse* response, 239 ResourceResponse* response,
241 ResourceDispatcherHost::GlobalRequestID global_id) { 240 const GlobalRequestID& global_id) {
242 in_cross_site_transition_ = true; 241 in_cross_site_transition_ = true;
243 request_id_ = request_id; 242 request_id_ = request_id;
244 response_ = response; 243 response_ = response;
245 244
246 // Store this handler on the ExtraRequestInfo, so that RDH can call our 245 // Store this handler on the ExtraRequestInfo, so that RDH can call our
247 // ResumeResponse method when the close ACK is received. 246 // ResumeResponse method when the close ACK is received.
248 URLRequest* request = rdh_->GetURLRequest(global_id); 247 URLRequest* request = rdh_->GetURLRequest(global_id);
249 if (!request) { 248 if (!request) {
250 DLOG(WARNING) << "Cross site response for a request that wasn't found"; 249 DLOG(WARNING) << "Cross site response for a request that wasn't found";
251 return; 250 return;
(...skipping 12 matching lines...) Expand all
264 // there will be no reads. 263 // there will be no reads.
265 264
266 // Tell the tab responsible for this request that a cross-site response is 265 // Tell the tab responsible for this request that a cross-site response is
267 // starting, so that it can tell its old renderer to run its onunload 266 // starting, so that it can tell its old renderer to run its onunload
268 // handler now. We will wait to hear the corresponding ClosePage_ACK. 267 // handler now. We will wait to hear the corresponding ClosePage_ACK.
269 ChromeThread::PostTask( 268 ChromeThread::PostTask(
270 ChromeThread::UI, FROM_HERE, 269 ChromeThread::UI, FROM_HERE,
271 new CrossSiteNotifyTask( 270 new CrossSiteNotifyTask(
272 render_process_host_id_, render_view_id_, request_id)); 271 render_process_host_id_, render_view_id_, request_id));
273 } 272 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/cross_site_resource_handler.h ('k') | chrome/browser/renderer_host/download_resource_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698