| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/cross_site_resource_handler.h" | 5 #include "content/browser/loader/cross_site_resource_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "content/browser/cross_site_request_manager.h" | 11 #include "content/browser/cross_site_request_manager.h" |
| 12 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 12 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 13 #include "content/browser/loader/resource_request_info_impl.h" | 13 #include "content/browser/loader/resource_request_info_impl.h" |
| 14 #include "content/browser/renderer_host/render_view_host_delegate.h" | 14 #include "content/browser/renderer_host/render_view_host_delegate.h" |
| 15 #include "content/browser/renderer_host/render_view_host_impl.h" | 15 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/content_browser_client.h" | 17 #include "content/public/browser/content_browser_client.h" |
| 18 #include "content/public/browser/global_request_id.h" | 18 #include "content/public/browser/global_request_id.h" |
| 19 #include "content/public/browser/resource_controller.h" | 19 #include "content/public/browser/resource_controller.h" |
| 20 #include "content/public/common/resource_response.h" | 20 #include "content/public/common/resource_response.h" |
| 21 #include "content/public/common/url_constants.h" |
| 21 #include "net/http/http_response_headers.h" | 22 #include "net/http/http_response_headers.h" |
| 22 #include "net/url_request/url_request.h" | 23 #include "net/url_request/url_request.h" |
| 23 | 24 |
| 24 namespace content { | 25 namespace content { |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 void OnCrossSiteResponseHelper(int render_view_id, | 29 void OnCrossSiteResponseHelper(int render_view_id, |
| 29 const GlobalRequestID& global_request_id, | 30 const GlobalRequestID& global_request_id, |
| 30 bool is_transfer, | 31 bool is_transfer, |
| 31 const std::vector<GURL>& transfer_url_chain, | 32 const std::vector<GURL>& transfer_url_chain, |
| 32 const Referrer& referrer, | 33 const Referrer& referrer, |
| 33 PageTransition page_transition, | 34 PageTransition page_transition, |
| 34 int64 frame_id) { | 35 int64 frame_id) { |
| 35 RenderViewHostImpl* rvh = | 36 RenderViewHostImpl* rvh = |
| 36 RenderViewHostImpl::FromID(global_request_id.child_id, render_view_id); | 37 RenderViewHostImpl::FromID(global_request_id.child_id, render_view_id); |
| 37 if (!rvh) | |
| 38 return; | |
| 39 RenderViewHostDelegate* delegate = rvh->GetDelegate(); | |
| 40 if (!delegate || !delegate->GetRendererManagementDelegate()) | |
| 41 return; | |
| 42 | 38 |
| 43 delegate->GetRendererManagementDelegate()->OnCrossSiteResponse( | 39 rvh->OnCrossSiteResponse( |
| 44 rvh, global_request_id, is_transfer, transfer_url_chain, referrer, | 40 global_request_id, is_transfer, transfer_url_chain, referrer, |
| 45 page_transition, frame_id); | 41 page_transition, frame_id); |
| 46 } | 42 } |
| 47 | 43 |
| 48 } // namespace | 44 } // namespace |
| 49 | 45 |
| 50 CrossSiteResourceHandler::CrossSiteResourceHandler( | 46 CrossSiteResourceHandler::CrossSiteResourceHandler( |
| 51 scoped_ptr<ResourceHandler> next_handler, | 47 scoped_ptr<ResourceHandler> next_handler, |
| 52 net::URLRequest* request) | 48 net::URLRequest* request) |
| 53 : LayeredResourceHandler(request, next_handler.Pass()), | 49 : LayeredResourceHandler(request, next_handler.Pass()), |
| 54 has_started_response_(false), | 50 has_started_response_(false), |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 84 |
| 89 ResourceRequestInfoImpl* info = GetRequestInfo(); | 85 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 90 | 86 |
| 91 // We will need to swap processes if either (1) a redirect that requires a | 87 // We will need to swap processes if either (1) a redirect that requires a |
| 92 // transfer occurred before we got here, or (2) a pending cross-site request | 88 // transfer occurred before we got here, or (2) a pending cross-site request |
| 93 // was already in progress. Note that a swap may no longer be needed if we | 89 // was already in progress. Note that a swap may no longer be needed if we |
| 94 // transferred back into the original process due to a redirect. | 90 // transferred back into the original process due to a redirect. |
| 95 bool should_transfer = | 91 bool should_transfer = |
| 96 GetContentClient()->browser()->ShouldSwapProcessesForRedirect( | 92 GetContentClient()->browser()->ShouldSwapProcessesForRedirect( |
| 97 info->GetContext(), request()->original_url(), request()->url()); | 93 info->GetContext(), request()->original_url(), request()->url()); |
| 94 // TODO(creis): Always do this. |
| 95 if (info->GetResourceType() == ResourceType::SUB_FRAME && |
| 96 !request()->url().SchemeIs(chrome::kChromeUIScheme) && |
| 97 !SiteInstance::IsSameWebSite(NULL, request()->url(), |
| 98 GURL(request()->referrer()))) { |
| 99 LOG(INFO) << "CSRH: Transferring for a cross-process subframe."; |
| 100 should_transfer = true; |
| 101 } |
| 102 |
| 98 bool swap_needed = should_transfer || | 103 bool swap_needed = should_transfer || |
| 99 CrossSiteRequestManager::GetInstance()-> | 104 CrossSiteRequestManager::GetInstance()-> |
| 100 HasPendingCrossSiteRequest(info->GetChildID(), info->GetRouteID()); | 105 HasPendingCrossSiteRequest(info->GetChildID(), info->GetRouteID()); |
| 101 | 106 |
| 102 // If this is a download, just pass the response through without doing a | 107 // If this is a download, just pass the response through without doing a |
| 103 // cross-site check. The renderer will see it is a download and abort the | 108 // cross-site check. The renderer will see it is a download and abort the |
| 104 // request. | 109 // request. |
| 105 // | 110 // |
| 106 // Similarly, HTTP 204 (No Content) responses leave us showing the previous | 111 // Similarly, HTTP 204 (No Content) responses leave us showing the previous |
| 107 // page. We should allow the navigation to finish without running the unload | 112 // page. We should allow the navigation to finish without running the unload |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 } | 259 } |
| 255 | 260 |
| 256 void CrossSiteResourceHandler::ResumeIfDeferred() { | 261 void CrossSiteResourceHandler::ResumeIfDeferred() { |
| 257 if (did_defer_) { | 262 if (did_defer_) { |
| 258 did_defer_ = false; | 263 did_defer_ = false; |
| 259 controller()->Resume(); | 264 controller()->Resume(); |
| 260 } | 265 } |
| 261 } | 266 } |
| 262 | 267 |
| 263 } // namespace content | 268 } // namespace content |
| OLD | NEW |