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