| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/loader/transfer_navigation_resource_throttle.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "content/browser/loader/resource_dispatcher_host_impl.h" | |
| 9 #include "content/browser/renderer_host/render_view_host_delegate.h" | |
| 10 #include "content/public/browser/browser_thread.h" | |
| 11 #include "content/public/browser/content_browser_client.h" | |
| 12 #include "content/public/browser/global_request_id.h" | |
| 13 #include "content/public/browser/render_view_host.h" | |
| 14 #include "content/public/browser/resource_request_info.h" | |
| 15 #include "content/public/common/referrer.h" | |
| 16 #include "net/url_request/url_request.h" | |
| 17 | |
| 18 namespace content { | |
| 19 | |
| 20 namespace { | |
| 21 | |
| 22 void RequestTransferURLOnUIThread(int render_process_id, | |
| 23 int render_view_id, | |
| 24 const GURL& new_url, | |
| 25 const Referrer& referrer, | |
| 26 WindowOpenDisposition window_open_disposition, | |
| 27 int64 frame_id, | |
| 28 const GlobalRequestID& global_request_id) { | |
| 29 RenderViewHost* rvh = | |
| 30 RenderViewHost::FromID(render_process_id, render_view_id); | |
| 31 if (!rvh) | |
| 32 return; | |
| 33 | |
| 34 RenderViewHostDelegate* delegate = rvh->GetDelegate(); | |
| 35 if (!delegate) | |
| 36 return; | |
| 37 | |
| 38 delegate->RequestTransferURL( | |
| 39 new_url, referrer, window_open_disposition, | |
| 40 frame_id, global_request_id, false); | |
| 41 } | |
| 42 | |
| 43 } // namespace | |
| 44 | |
| 45 TransferNavigationResourceThrottle::TransferNavigationResourceThrottle( | |
| 46 net::URLRequest* request) | |
| 47 : request_(request) { | |
| 48 } | |
| 49 | |
| 50 TransferNavigationResourceThrottle::~TransferNavigationResourceThrottle() { | |
| 51 } | |
| 52 | |
| 53 void TransferNavigationResourceThrottle::WillRedirectRequest( | |
| 54 const GURL& new_url, | |
| 55 bool* defer) { | |
| 56 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); | |
| 57 | |
| 58 // If a toplevel request is redirecting across extension extents, we want to | |
| 59 // switch processes. We do this by deferring the redirect and resuming the | |
| 60 // request once the navigation controller properly assigns the right process | |
| 61 // to host the new URL. | |
| 62 // TODO(mpcomplete): handle for cases other than extensions (e.g. WebUI). | |
| 63 ResourceContext* resource_context = info->GetContext(); | |
| 64 if (GetContentClient()->browser()->ShouldSwapProcessesForRedirect( | |
| 65 resource_context, request_->url(), new_url)) { | |
| 66 int render_process_id, render_view_id; | |
| 67 if (info->GetAssociatedRenderView(&render_process_id, &render_view_id)) { | |
| 68 GlobalRequestID global_id(info->GetChildID(), info->GetRequestID()); | |
| 69 | |
| 70 ResourceDispatcherHostImpl::Get()->MarkAsTransferredNavigation(global_id); | |
| 71 | |
| 72 BrowserThread::PostTask( | |
| 73 BrowserThread::UI, | |
| 74 FROM_HERE, | |
| 75 base::Bind(&RequestTransferURLOnUIThread, | |
| 76 render_process_id, | |
| 77 render_view_id, | |
| 78 new_url, | |
| 79 Referrer(GURL(request_->referrer()), info->GetReferrerPolicy()), | |
| 80 CURRENT_TAB, | |
| 81 info->GetFrameID(), | |
| 82 global_id)); | |
| 83 | |
| 84 *defer = true; | |
| 85 } | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 } // namespace content | |
| OLD | NEW |