Index: content/browser/loader/resource_request_info_impl.cc |
diff --git a/content/browser/loader/resource_request_info_impl.cc b/content/browser/loader/resource_request_info_impl.cc |
index 26f99f962d81854780ef20d550cacf4ea594b216..162d6488948583cb76d3c6ce50ab3894b47ef812 100644 |
--- a/content/browser/loader/resource_request_info_impl.cc |
+++ b/content/browser/loader/resource_request_info_impl.cc |
@@ -4,15 +4,45 @@ |
#include "content/browser/loader/resource_request_info_impl.h" |
+#include "base/command_line.h" |
+#include "content/browser/frame_host/frame_tree_node.h" |
#include "content/browser/loader/global_routing_id.h" |
#include "content/browser/loader/resource_message_filter.h" |
+#include "content/browser/web_contents/web_contents_impl.h" |
#include "content/common/net/url_request_user_data.h" |
+#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/global_request_id.h" |
+#include "content/public/common/content_switches.h" |
#include "content/public/common/process_type.h" |
#include "net/url_request/url_request.h" |
namespace content { |
+namespace { |
+ |
+WebContents* GetWebContentsFromFTNID(int frame_tree_node_id) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ FrameTreeNode* frame_tree_node = |
+ FrameTreeNode::GloballyFindByID(frame_tree_node_id); |
+ if (!frame_tree_node) |
+ return nullptr; |
+ |
+ return WebContentsImpl::FromFrameTreeNode(frame_tree_node); |
+} |
+ |
+WebContents* GetWebContentsFromRFHID(int render_process_id, |
+ int render_frame_id) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ RenderFrameHost* render_frame_host = |
+ RenderFrameHost::FromID(render_process_id, render_frame_id); |
+ if (!render_frame_host) |
+ return nullptr; |
+ |
+ return WebContents::FromRenderFrameHost(render_frame_host); |
+} |
+ |
+} // namespace |
+ |
// ---------------------------------------------------------------------------- |
// ResourceRequestInfo |
@@ -168,6 +198,27 @@ ResourceRequestInfoImpl::ResourceRequestInfoImpl( |
ResourceRequestInfoImpl::~ResourceRequestInfoImpl() { |
} |
+base::Callback<WebContents*(void)> |
+ResourceRequestInfoImpl::GetWebContentsForRequest() { |
+ // PlzNavigate: navigation requests are created with a valid FrameTreeNode ID |
+ // and invalid RenderProcessHost and RenderFrameHost IDs. The FTN ID should |
+ // be used to access the WebContents. |
+ if (frame_tree_node_id_ != -1) { |
+ DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kEnableBrowserSideNavigation)); |
+ return base::Bind(&GetWebContentsFromFTNID, frame_tree_node_id_); |
+ } |
+ |
+ // In other cases, use the RPH ID + RFH ID to get the WebContents. |
davidben
2015/11/20 22:19:53
Nit: This comments and above switch between using
clamy
2015/11/23 16:44:09
Done.
|
+ int render_process_host_id = -1; |
+ int render_frame_host_id = -1; |
+ if (!GetAssociatedRenderFrame(&render_process_host_id, &render_frame_host_id)) |
+ NOTREACHED(); |
+ |
+ return base::Bind(&GetWebContentsFromRFHID, render_process_host_id, |
+ render_frame_host_id); |
+} |
+ |
ResourceContext* ResourceRequestInfoImpl::GetContext() const { |
return context_; |
} |