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