| Index: content/browser/download/download_request_handle.cc
|
| diff --git a/content/browser/download/download_request_handle.cc b/content/browser/download/download_request_handle.cc
|
| index 32c5b987799d510d79fb6e12c4327784498fdd86..6e319d3abee213eac6300b25abaf661bea3b4a53 100644
|
| --- a/content/browser/download/download_request_handle.cc
|
| +++ b/content/browser/download/download_request_handle.cc
|
| @@ -5,11 +5,15 @@
|
| #include "content/browser/download/download_request_handle.h"
|
|
|
| #include "base/bind.h"
|
| +#include "base/command_line.h"
|
| #include "base/strings/stringprintf.h"
|
| +#include "content/browser/frame_host/navigator.h"
|
| +#include "content/browser/frame_host/render_frame_host_impl.h"
|
| #include "content/browser/renderer_host/render_view_host_impl.h"
|
| #include "content/browser/web_contents/web_contents_impl.h"
|
| #include "content/public/browser/browser_context.h"
|
| #include "content/public/browser/browser_thread.h"
|
| +#include "content/public/common/content_switches.h"
|
|
|
| namespace content {
|
|
|
| @@ -19,31 +23,63 @@ DownloadRequestHandle::~DownloadRequestHandle() {
|
| DownloadRequestHandle::DownloadRequestHandle()
|
| : child_id_(-1),
|
| render_view_id_(-1),
|
| - request_id_(-1) {
|
| + request_id_(-1),
|
| + frame_tree_node_id_(-1) {
|
| }
|
|
|
| DownloadRequestHandle::DownloadRequestHandle(
|
| const base::WeakPtr<DownloadResourceHandler>& handler,
|
| int child_id,
|
| int render_view_id,
|
| - int request_id)
|
| + int request_id,
|
| + int frame_tree_node_id)
|
| : handler_(handler),
|
| child_id_(child_id),
|
| render_view_id_(render_view_id),
|
| - request_id_(request_id) {
|
| + request_id_(request_id),
|
| + frame_tree_node_id_(frame_tree_node_id) {
|
| DCHECK(handler_.get());
|
| }
|
|
|
| WebContents* DownloadRequestHandle::GetWebContents() const {
|
| + // PlzNavigate: if a FrameTreeNodeID was provided, use it to return the
|
| + // WebContents.
|
| + // TODO(davidben): This logic should be abstracted within the ResourceLoader
|
| + // stack. https://crbug.com/376003
|
| + if (base::CommandLine::ForCurrentProcess()->HasSwitch(
|
| + switches::kEnableBrowserSideNavigation)) {
|
| + FrameTreeNode* frame_tree_node =
|
| + FrameTreeNode::GloballyFindByID(frame_tree_node_id_);
|
| + if (frame_tree_node) {
|
| + return WebContentsImpl::FromFrameTreeNode(frame_tree_node);
|
| + }
|
| + }
|
| +
|
| RenderViewHostImpl* render_view_host =
|
| RenderViewHostImpl::FromID(child_id_, render_view_id_);
|
| if (!render_view_host)
|
| - return NULL;
|
| + return nullptr;
|
|
|
| return render_view_host->GetDelegate()->GetAsWebContents();
|
| }
|
|
|
| DownloadManager* DownloadRequestHandle::GetDownloadManager() const {
|
| + // PlzNavigate: if a FrameTreeNodeID was provided, use it to return the
|
| + // DownloadManager.
|
| + // TODO(davidben): This logic should be abstracted within the ResourceLoader
|
| + // stack. https://crbug.com/376003
|
| + if (base::CommandLine::ForCurrentProcess()->HasSwitch(
|
| + switches::kEnableBrowserSideNavigation)) {
|
| + FrameTreeNode* frame_tree_node =
|
| + FrameTreeNode::GloballyFindByID(frame_tree_node_id_);
|
| + if (frame_tree_node) {
|
| + BrowserContext* context =
|
| + frame_tree_node->navigator()->GetController()->GetBrowserContext();
|
| + if (context)
|
| + return BrowserContext::GetDownloadManager(context);
|
| + }
|
| + }
|
| +
|
| RenderViewHostImpl* rvh = RenderViewHostImpl::FromID(
|
| child_id_, render_view_id_);
|
| if (rvh == NULL)
|
|
|