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. | |
| 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 frame_tree_node->current_frame_host() | |
| 53 ->delegate() | |
| 54 ->GetAsWebContents(); | |
|
nasko
2015/04/27 14:24:11
This method isn't very good and we should avoid us
clamy
2015/04/27 16:19:12
I created a WebContentsImpl::FromFrameTreeNode met
| |
| 55 } | |
| 56 } | |
| 57 | |
|
clamy
2015/04/27 14:34:44
If we use the FTN id, we still have to rely on the
| |
| 38 RenderViewHostImpl* render_view_host = | 58 RenderViewHostImpl* render_view_host = |
| 39 RenderViewHostImpl::FromID(child_id_, render_view_id_); | 59 RenderViewHostImpl::FromID(child_id_, render_view_id_); |
| 40 if (!render_view_host) | 60 if (!render_view_host) |
| 41 return NULL; | 61 return NULL; |
| 42 | 62 |
| 43 return render_view_host->GetDelegate()->GetAsWebContents(); | 63 return render_view_host->GetDelegate()->GetAsWebContents(); |
| 44 } | 64 } |
| 45 | 65 |
| 46 DownloadManager* DownloadRequestHandle::GetDownloadManager() const { | 66 DownloadManager* DownloadRequestHandle::GetDownloadManager() const { |
| 67 // PlzNavigate: if a FrameTreeNodeID was provided, use it to return the | |
| 68 // DownloadManager. | |
| 69 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 70 switches::kEnableBrowserSideNavigation)) { | |
| 71 FrameTreeNode* frame_tree_node = | |
| 72 FrameTreeNode::GloballyFindByID(frame_tree_node_id_); | |
| 73 if (frame_tree_node) { | |
| 74 BrowserContext* context = | |
| 75 frame_tree_node->navigator()->GetController()->GetBrowserContext(); | |
| 76 if (context) | |
| 77 return BrowserContext::GetDownloadManager(context); | |
| 78 } | |
| 79 } | |
| 80 | |
| 47 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID( | 81 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID( |
| 48 child_id_, render_view_id_); | 82 child_id_, render_view_id_); |
| 49 if (rvh == NULL) | 83 if (rvh == NULL) |
| 50 return NULL; | 84 return NULL; |
| 51 RenderProcessHost* rph = rvh->GetProcess(); | 85 RenderProcessHost* rph = rvh->GetProcess(); |
| 52 if (rph == NULL) | 86 if (rph == NULL) |
| 53 return NULL; | 87 return NULL; |
| 54 BrowserContext* context = rph->GetBrowserContext(); | 88 BrowserContext* context = rph->GetBrowserContext(); |
| 55 if (context == NULL) | 89 if (context == NULL) |
| 56 return NULL; | 90 return NULL; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 80 " child_id = %d" | 114 " child_id = %d" |
| 81 " render_view_id = %d" | 115 " render_view_id = %d" |
| 82 " request_id = %d" | 116 " request_id = %d" |
| 83 "}", | 117 "}", |
| 84 child_id_, | 118 child_id_, |
| 85 render_view_id_, | 119 render_view_id_, |
| 86 request_id_); | 120 request_id_); |
| 87 } | 121 } |
| 88 | 122 |
| 89 } // namespace content | 123 } // namespace content |
| OLD | NEW |