| 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 "content/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 "content/browser/renderer_host/resource_dispatcher_host_impl.h" |
| 9 #include "chrome/browser/profiles/profile_io_data.h" | 9 #include "content/public/browser/content_browser_client.h" |
| 10 #include "chrome/common/extensions/extension_process_policy.h" | |
| 11 #include "content/public/browser/global_request_id.h" | 10 #include "content/public/browser/global_request_id.h" |
| 12 #include "content/public/browser/render_view_host.h" | 11 #include "content/public/browser/render_view_host.h" |
| 13 #include "content/public/browser/render_view_host_delegate.h" | 12 #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" | 13 #include "content/public/browser/resource_request_info.h" |
| 16 #include "content/public/common/referrer.h" | 14 #include "content/public/common/referrer.h" |
| 17 #include "net/url_request/url_request.h" | 15 #include "net/url_request/url_request.h" |
| 18 | 16 |
| 19 using content::GlobalRequestID; | 17 using content::GlobalRequestID; |
| 20 using content::Referrer; | 18 using content::Referrer; |
| 21 using content::RenderViewHostDelegate; | 19 using content::RenderViewHostDelegate; |
| 22 using content::ResourceDispatcherHost; | 20 using content::ResourceDispatcherHostImpl; |
| 23 using content::ResourceRequestInfo; | 21 using content::ResourceRequestInfo; |
| 24 | 22 |
| 25 namespace { | 23 namespace { |
| 26 | 24 |
| 27 void RequestTransferURLOnUIThread(int render_process_id, | 25 void RequestTransferURLOnUIThread(int render_process_id, |
| 28 int render_view_id, | 26 int render_view_id, |
| 29 const GURL& new_url, | 27 const GURL& new_url, |
| 30 const Referrer& referrer, | 28 const Referrer& referrer, |
| 31 WindowOpenDisposition window_open_disposition, | 29 WindowOpenDisposition window_open_disposition, |
| 32 int64 frame_id, | 30 int64 frame_id, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 50 net::URLRequest* request) | 48 net::URLRequest* request) |
| 51 : request_(request) { | 49 : request_(request) { |
| 52 } | 50 } |
| 53 | 51 |
| 54 TransferNavigationResourceThrottle::~TransferNavigationResourceThrottle() { | 52 TransferNavigationResourceThrottle::~TransferNavigationResourceThrottle() { |
| 55 } | 53 } |
| 56 | 54 |
| 57 void TransferNavigationResourceThrottle::WillRedirectRequest( | 55 void TransferNavigationResourceThrottle::WillRedirectRequest( |
| 58 const GURL& new_url, | 56 const GURL& new_url, |
| 59 bool* defer) { | 57 bool* defer) { |
| 60 // TODO(darin): Move this logic into src/content. | |
| 61 | |
| 62 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); | 58 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); |
| 63 | 59 |
| 64 // 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 |
| 65 // 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 |
| 66 // request once the navigation controller properly assigns the right process | 62 // request once the navigation controller properly assigns the right process |
| 67 // to host the new URL. | 63 // to host the new URL. |
| 68 // TODO(mpcomplete): handle for cases other than extensions (e.g. WebUI). | 64 // TODO(mpcomplete): handle for cases other than extensions (e.g. WebUI). |
| 69 content::ResourceContext* resource_context = info->GetContext(); | 65 content::ResourceContext* resource_context = info->GetContext(); |
| 70 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); | 66 if (content::GetContentClient()->browser()->ShouldSwapProcessesForRedirect( |
| 71 if (extensions::CrossesExtensionProcessBoundary( | 67 resource_context, request_->url(), new_url)) { |
| 72 io_data->GetExtensionInfoMap()->extensions(), | |
| 73 ExtensionURLInfo(request_->url()), ExtensionURLInfo(new_url))) { | |
| 74 int render_process_id, render_view_id; | 68 int render_process_id, render_view_id; |
| 75 if (info->GetAssociatedRenderView(&render_process_id, &render_view_id)) { | 69 if (info->GetAssociatedRenderView(&render_process_id, &render_view_id)) { |
| 76 ResourceDispatcherHost::Get()->MarkAsTransferredNavigation(request_); | 70 ResourceDispatcherHostImpl::Get()->MarkAsTransferredNavigation(request_); |
| 77 | 71 |
| 78 GlobalRequestID global_id(info->GetChildID(), info->GetRequestID()); | 72 GlobalRequestID global_id(info->GetChildID(), info->GetRequestID()); |
| 79 content::BrowserThread::PostTask( | 73 content::BrowserThread::PostTask( |
| 80 content::BrowserThread::UI, | 74 content::BrowserThread::UI, |
| 81 FROM_HERE, | 75 FROM_HERE, |
| 82 base::Bind(&RequestTransferURLOnUIThread, | 76 base::Bind(&RequestTransferURLOnUIThread, |
| 83 render_process_id, | 77 render_process_id, |
| 84 render_view_id, | 78 render_view_id, |
| 85 new_url, | 79 new_url, |
| 86 Referrer(GURL(request_->referrer()), info->GetReferrerPolicy()), | 80 Referrer(GURL(request_->referrer()), info->GetReferrerPolicy()), |
| 87 CURRENT_TAB, | 81 CURRENT_TAB, |
| 88 info->GetFrameID(), | 82 info->GetFrameID(), |
| 89 global_id)); | 83 global_id)); |
| 90 | 84 |
| 91 *defer = true; | 85 *defer = true; |
| 92 } | 86 } |
| 93 } | 87 } |
| 94 } | 88 } |
| OLD | NEW |