| OLD | NEW | 
|---|
| 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/browser_thread.h" | 10 #include "chrome/browser/browser_thread.h" | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 52                                                  ResourceResponse* response) { | 52                                                  ResourceResponse* response) { | 
| 53   // At this point, we know that the response is safe to send back to the | 53   // At this point, we know that the response is safe to send back to the | 
| 54   // renderer: it is not a download, and it has passed the SSL and safe | 54   // renderer: it is not a download, and it has passed the SSL and safe | 
| 55   // browsing checks. | 55   // browsing checks. | 
| 56   // We should not have already started the transition before now. | 56   // We should not have already started the transition before now. | 
| 57   DCHECK(!in_cross_site_transition_); | 57   DCHECK(!in_cross_site_transition_); | 
| 58   has_started_response_ = true; | 58   has_started_response_ = true; | 
| 59 | 59 | 
| 60   // Look up the request and associated info. | 60   // Look up the request and associated info. | 
| 61   GlobalRequestID global_id(render_process_host_id_, request_id); | 61   GlobalRequestID global_id(render_process_host_id_, request_id); | 
| 62   URLRequest* request = rdh_->GetURLRequest(global_id); | 62   net::URLRequest* request = rdh_->GetURLRequest(global_id); | 
| 63   if (!request) { | 63   if (!request) { | 
| 64     DLOG(WARNING) << "Request wasn't found"; | 64     DLOG(WARNING) << "Request wasn't found"; | 
| 65     return false; | 65     return false; | 
| 66   } | 66   } | 
| 67   ResourceDispatcherHostRequestInfo* info = | 67   ResourceDispatcherHostRequestInfo* info = | 
| 68       ResourceDispatcherHost::InfoForRequest(request); | 68       ResourceDispatcherHost::InfoForRequest(request); | 
| 69 | 69 | 
| 70   // If this is a download, just pass the response through without doing a | 70   // If this is a download, just pass the response through without doing a | 
| 71   // cross-site check.  The renderer will see it is a download and abort the | 71   // cross-site check.  The renderer will see it is a download and abort the | 
| 72   // request. | 72   // request. | 
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 134 | 134 | 
| 135 // We can now send the response to the new renderer, which will cause | 135 // We can now send the response to the new renderer, which will cause | 
| 136 // TabContents to swap in the new renderer and destroy the old one. | 136 // TabContents to swap in the new renderer and destroy the old one. | 
| 137 void CrossSiteResourceHandler::ResumeResponse() { | 137 void CrossSiteResourceHandler::ResumeResponse() { | 
| 138   DCHECK(request_id_ != -1); | 138   DCHECK(request_id_ != -1); | 
| 139   DCHECK(in_cross_site_transition_); | 139   DCHECK(in_cross_site_transition_); | 
| 140   in_cross_site_transition_ = false; | 140   in_cross_site_transition_ = false; | 
| 141 | 141 | 
| 142   // Find the request for this response. | 142   // Find the request for this response. | 
| 143   GlobalRequestID global_id(render_process_host_id_, request_id_); | 143   GlobalRequestID global_id(render_process_host_id_, request_id_); | 
| 144   URLRequest* request = rdh_->GetURLRequest(global_id); | 144   net::URLRequest* request = rdh_->GetURLRequest(global_id); | 
| 145   if (!request) { | 145   if (!request) { | 
| 146     DLOG(WARNING) << "Resuming a request that wasn't found"; | 146     DLOG(WARNING) << "Resuming a request that wasn't found"; | 
| 147     return; | 147     return; | 
| 148   } | 148   } | 
| 149 | 149 | 
| 150   if (has_started_response_) { | 150   if (has_started_response_) { | 
| 151     // Send OnResponseStarted to the new renderer. | 151     // Send OnResponseStarted to the new renderer. | 
| 152     DCHECK(response_); | 152     DCHECK(response_); | 
| 153     next_handler_->OnResponseStarted(request_id_, response_); | 153     next_handler_->OnResponseStarted(request_id_, response_); | 
| 154 | 154 | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
| 182 void CrossSiteResourceHandler::StartCrossSiteTransition( | 182 void CrossSiteResourceHandler::StartCrossSiteTransition( | 
| 183     int request_id, | 183     int request_id, | 
| 184     ResourceResponse* response, | 184     ResourceResponse* response, | 
| 185     const GlobalRequestID& global_id) { | 185     const GlobalRequestID& global_id) { | 
| 186   in_cross_site_transition_ = true; | 186   in_cross_site_transition_ = true; | 
| 187   request_id_ = request_id; | 187   request_id_ = request_id; | 
| 188   response_ = response; | 188   response_ = response; | 
| 189 | 189 | 
| 190   // Store this handler on the ExtraRequestInfo, so that RDH can call our | 190   // Store this handler on the ExtraRequestInfo, so that RDH can call our | 
| 191   // ResumeResponse method when the close ACK is received. | 191   // ResumeResponse method when the close ACK is received. | 
| 192   URLRequest* request = rdh_->GetURLRequest(global_id); | 192   net::URLRequest* request = rdh_->GetURLRequest(global_id); | 
| 193   if (!request) { | 193   if (!request) { | 
| 194     DLOG(WARNING) << "Cross site response for a request that wasn't found"; | 194     DLOG(WARNING) << "Cross site response for a request that wasn't found"; | 
| 195     return; | 195     return; | 
| 196   } | 196   } | 
| 197   ResourceDispatcherHostRequestInfo* info = | 197   ResourceDispatcherHostRequestInfo* info = | 
| 198       ResourceDispatcherHost::InfoForRequest(request); | 198       ResourceDispatcherHost::InfoForRequest(request); | 
| 199   info->set_cross_site_handler(this); | 199   info->set_cross_site_handler(this); | 
| 200 | 200 | 
| 201   if (has_started_response_) { | 201   if (has_started_response_) { | 
| 202     // Pause the request until the old renderer is finished and the new | 202     // Pause the request until the old renderer is finished and the new | 
| 203     // renderer is ready. | 203     // renderer is ready. | 
| 204     rdh_->PauseRequest(render_process_host_id_, request_id, true); | 204     rdh_->PauseRequest(render_process_host_id_, request_id, true); | 
| 205   } | 205   } | 
| 206   // If our OnResponseStarted wasn't called, then we're being called by | 206   // If our OnResponseStarted wasn't called, then we're being called by | 
| 207   // OnResponseCompleted after a failure.  We don't need to pause, because | 207   // OnResponseCompleted after a failure.  We don't need to pause, because | 
| 208   // there will be no reads. | 208   // there will be no reads. | 
| 209 | 209 | 
| 210   // Tell the tab responsible for this request that a cross-site response is | 210   // Tell the tab responsible for this request that a cross-site response is | 
| 211   // starting, so that it can tell its old renderer to run its onunload | 211   // starting, so that it can tell its old renderer to run its onunload | 
| 212   // handler now.  We will wait to hear the corresponding ClosePage_ACK. | 212   // handler now.  We will wait to hear the corresponding ClosePage_ACK. | 
| 213   CallRenderViewHostRendererManagementDelegate( | 213   CallRenderViewHostRendererManagementDelegate( | 
| 214       render_process_host_id_, render_view_id_, | 214       render_process_host_id_, render_view_id_, | 
| 215       &RenderViewHostDelegate::RendererManagement::OnCrossSiteResponse, | 215       &RenderViewHostDelegate::RendererManagement::OnCrossSiteResponse, | 
| 216       render_process_host_id_, request_id); | 216       render_process_host_id_, request_id); | 
| 217 | 217 | 
| 218   // TODO(creis): If the above call should fail, then we need to notify the IO | 218   // TODO(creis): If the above call should fail, then we need to notify the IO | 
| 219   // thread to proceed anyway, using ResourceDispatcherHost::OnClosePageACK. | 219   // thread to proceed anyway, using ResourceDispatcherHost::OnClosePageACK. | 
| 220 } | 220 } | 
| OLD | NEW | 
|---|