Chromium Code Reviews| 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 "content/browser/download/download_request_handle.h" | 5 #include "content/browser/download/download_request_handle.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | |
| 8 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "content/browser/frame_host/navigator.h" | |
| 11 #include "content/browser/frame_host/render_frame_host_impl.h" | |
| 9 #include "content/browser/renderer_host/render_view_host_impl.h" | 12 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 10 #include "content/browser/web_contents/web_contents_impl.h" | 13 #include "content/browser/web_contents/web_contents_impl.h" |
| 11 #include "content/public/browser/browser_context.h" | 14 #include "content/public/browser/browser_context.h" |
| 12 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/common/content_switches.h" | |
| 13 | 17 |
| 14 namespace content { | 18 namespace content { |
| 15 | 19 |
| 16 DownloadRequestHandle::~DownloadRequestHandle() { | 20 DownloadRequestHandle::~DownloadRequestHandle() { |
| 17 } | 21 } |
| 18 | 22 |
| 19 DownloadRequestHandle::DownloadRequestHandle() | 23 DownloadRequestHandle::DownloadRequestHandle() |
| 20 : child_id_(-1), | 24 : child_id_(-1), |
| 21 render_view_id_(-1), | 25 render_view_id_(-1), |
| 22 request_id_(-1) { | 26 request_id_(-1), |
| 27 frame_tree_node_id_(-1) { | |
| 23 } | 28 } |
| 24 | 29 |
| 25 DownloadRequestHandle::DownloadRequestHandle( | 30 DownloadRequestHandle::DownloadRequestHandle( |
| 26 const base::WeakPtr<DownloadResourceHandler>& handler, | 31 const base::WeakPtr<DownloadResourceHandler>& handler, |
| 27 int child_id, | 32 int child_id, |
| 28 int render_view_id, | 33 int render_view_id, |
| 29 int request_id) | 34 int request_id, |
| 35 int64 frame_tree_node_id) | |
| 30 : handler_(handler), | 36 : handler_(handler), |
| 31 child_id_(child_id), | 37 child_id_(child_id), |
| 32 render_view_id_(render_view_id), | 38 render_view_id_(render_view_id), |
| 33 request_id_(request_id) { | 39 request_id_(request_id), |
| 40 frame_tree_node_id_(frame_tree_node_id) { | |
| 34 DCHECK(handler_.get()); | 41 DCHECK(handler_.get()); |
| 35 } | 42 } |
| 36 | 43 |
| 37 WebContents* DownloadRequestHandle::GetWebContents() const { | 44 WebContents* DownloadRequestHandle::GetWebContents() const { |
| 45 // PlzNavigate: if a FrameTreeNodeID was provided, use it to return the | |
| 46 // WebContents. | |
|
davidben
2015/05/20 21:45:38
Could you add a
// TODO(davidben): This logic sho
clamy
2015/05/22 16:01:29
Done.
| |
| 47 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 48 switches::kEnableBrowserSideNavigation)) { | |
| 49 FrameTreeNode* frame_tree_node = | |
| 50 FrameTreeNode::GloballyFindByID(frame_tree_node_id_); | |
| 51 if (frame_tree_node) { | |
| 52 return WebContentsImpl::FromFrameTreeNode(frame_tree_node); | |
| 53 } | |
| 54 } | |
| 55 | |
| 38 RenderViewHostImpl* render_view_host = | 56 RenderViewHostImpl* render_view_host = |
| 39 RenderViewHostImpl::FromID(child_id_, render_view_id_); | 57 RenderViewHostImpl::FromID(child_id_, render_view_id_); |
| 40 if (!render_view_host) | 58 if (!render_view_host) |
| 41 return NULL; | 59 return NULL; |
| 42 | 60 |
| 43 return render_view_host->GetDelegate()->GetAsWebContents(); | 61 return render_view_host->GetDelegate()->GetAsWebContents(); |
| 44 } | 62 } |
| 45 | 63 |
| 46 DownloadManager* DownloadRequestHandle::GetDownloadManager() const { | 64 DownloadManager* DownloadRequestHandle::GetDownloadManager() const { |
| 65 // PlzNavigate: if a FrameTreeNodeID was provided, use it to return the | |
| 66 // DownloadManager. | |
|
davidben
2015/05/20 21:45:38
Ditto with the TODO.
clamy
2015/05/22 16:01:28
Done.
| |
| 67 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 68 switches::kEnableBrowserSideNavigation)) { | |
| 69 FrameTreeNode* frame_tree_node = | |
| 70 FrameTreeNode::GloballyFindByID(frame_tree_node_id_); | |
| 71 if (frame_tree_node) { | |
| 72 BrowserContext* context = | |
| 73 frame_tree_node->navigator()->GetController()->GetBrowserContext(); | |
| 74 if (context) | |
| 75 return BrowserContext::GetDownloadManager(context); | |
| 76 } | |
| 77 } | |
| 78 | |
| 47 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID( | 79 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID( |
| 48 child_id_, render_view_id_); | 80 child_id_, render_view_id_); |
| 49 if (rvh == NULL) | 81 if (rvh == NULL) |
| 50 return NULL; | 82 return NULL; |
| 51 RenderProcessHost* rph = rvh->GetProcess(); | 83 RenderProcessHost* rph = rvh->GetProcess(); |
| 52 if (rph == NULL) | 84 if (rph == NULL) |
| 53 return NULL; | 85 return NULL; |
| 54 BrowserContext* context = rph->GetBrowserContext(); | 86 BrowserContext* context = rph->GetBrowserContext(); |
| 55 if (context == NULL) | 87 if (context == NULL) |
| 56 return NULL; | 88 return NULL; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 80 " child_id = %d" | 112 " child_id = %d" |
| 81 " render_view_id = %d" | 113 " render_view_id = %d" |
| 82 " request_id = %d" | 114 " request_id = %d" |
| 83 "}", | 115 "}", |
| 84 child_id_, | 116 child_id_, |
| 85 render_view_id_, | 117 render_view_id_, |
| 86 request_id_); | 118 request_id_); |
| 87 } | 119 } |
| 88 | 120 |
| 89 } // namespace content | 121 } // namespace content |
| OLD | NEW |