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