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/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "content/browser/frame_host/navigator.h" | |
| 10 #include "content/browser/frame_host/render_frame_host_impl.h" | |
| 11 #include "content/browser/renderer_host/render_view_host_impl.h" | |
| 12 #include "content/browser/web_contents/web_contents_impl.h" | 9 #include "content/browser/web_contents/web_contents_impl.h" |
| 13 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| 14 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/common/browser_side_navigation_policy.h" | |
| 16 | 12 |
| 17 namespace content { | 13 namespace content { |
| 18 | 14 |
| 19 DownloadRequestHandleInterface::~DownloadRequestHandleInterface() {} | 15 DownloadRequestHandleInterface::~DownloadRequestHandleInterface() {} |
| 20 | 16 |
| 21 DownloadRequestHandle::DownloadRequestHandle( | 17 DownloadRequestHandle::DownloadRequestHandle( |
| 22 const DownloadRequestHandle& other) = default; | 18 const DownloadRequestHandle& other) = default; |
| 23 | 19 |
| 24 DownloadRequestHandle::~DownloadRequestHandle() {} | 20 DownloadRequestHandle::~DownloadRequestHandle() {} |
| 25 | 21 |
| 26 DownloadRequestHandle::DownloadRequestHandle() | 22 DownloadRequestHandle::DownloadRequestHandle() |
| 27 : child_id_(-1), | 23 : web_contents_getter_(content::ResourceRequestInfo::WebContentsGetter()) {} |
|
asanka
2016/02/25 16:19:10
Nit: Don't explicitly initialize this. You want th
Charlie Harrison
2016/02/25 16:53:58
Done.
| |
| 28 render_view_id_(-1), | |
| 29 request_id_(-1), | |
| 30 frame_tree_node_id_(-1) { | |
| 31 } | |
| 32 | 24 |
| 33 DownloadRequestHandle::DownloadRequestHandle( | 25 DownloadRequestHandle::DownloadRequestHandle( |
| 34 const base::WeakPtr<DownloadResourceHandler>& handler, | 26 const base::WeakPtr<DownloadResourceHandler>& handler, |
| 35 int child_id, | 27 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter) |
| 36 int render_view_id, | 28 : handler_(handler), web_contents_getter_(web_contents_getter) { |
| 37 int request_id, | |
| 38 int frame_tree_node_id) | |
| 39 : handler_(handler), | |
| 40 child_id_(child_id), | |
| 41 render_view_id_(render_view_id), | |
| 42 request_id_(request_id), | |
| 43 frame_tree_node_id_(frame_tree_node_id) { | |
| 44 DCHECK(handler_.get()); | 29 DCHECK(handler_.get()); |
| 45 } | 30 } |
| 46 | 31 |
| 47 WebContents* DownloadRequestHandle::GetWebContents() const { | 32 WebContents* DownloadRequestHandle::GetWebContents() const { |
| 48 // PlzNavigate: if a FrameTreeNodeId was provided, use it to return the | 33 return web_contents_getter_.is_null() ? nullptr : web_contents_getter_.Run(); |
| 49 // WebContents. | |
| 50 // TODO(davidben): This logic should be abstracted within the ResourceLoader | |
| 51 // stack. https://crbug.com/376003 | |
| 52 if (IsBrowserSideNavigationEnabled()) { | |
| 53 FrameTreeNode* frame_tree_node = | |
| 54 FrameTreeNode::GloballyFindByID(frame_tree_node_id_); | |
| 55 if (frame_tree_node) { | |
| 56 return WebContentsImpl::FromFrameTreeNode(frame_tree_node); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 RenderViewHostImpl* render_view_host = | |
| 61 RenderViewHostImpl::FromID(child_id_, render_view_id_); | |
| 62 if (!render_view_host) | |
| 63 return nullptr; | |
| 64 | |
| 65 return render_view_host->GetDelegate()->GetAsWebContents(); | |
| 66 } | 34 } |
| 67 | 35 |
| 68 DownloadManager* DownloadRequestHandle::GetDownloadManager() const { | 36 DownloadManager* DownloadRequestHandle::GetDownloadManager() const { |
| 69 // PlzNavigate: if a FrameTreeNodeId was provided, use it to return the | 37 WebContents* web_contents = GetWebContents(); |
| 70 // DownloadManager. | 38 if (web_contents == nullptr) |
| 71 // TODO(davidben): This logic should be abstracted within the ResourceLoader | 39 return nullptr; |
| 72 // stack. https://crbug.com/376003 | 40 BrowserContext* context = web_contents->GetBrowserContext(); |
| 73 if (IsBrowserSideNavigationEnabled()) { | 41 if (context == nullptr) |
| 74 FrameTreeNode* frame_tree_node = | 42 return nullptr; |
| 75 FrameTreeNode::GloballyFindByID(frame_tree_node_id_); | |
| 76 if (frame_tree_node) { | |
| 77 BrowserContext* context = | |
| 78 frame_tree_node->navigator()->GetController()->GetBrowserContext(); | |
| 79 if (context) | |
| 80 return BrowserContext::GetDownloadManager(context); | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID( | |
| 85 child_id_, render_view_id_); | |
| 86 if (rvh == NULL) | |
| 87 return NULL; | |
| 88 RenderProcessHost* rph = rvh->GetProcess(); | |
| 89 if (rph == NULL) | |
| 90 return NULL; | |
| 91 BrowserContext* context = rph->GetBrowserContext(); | |
| 92 if (context == NULL) | |
| 93 return NULL; | |
| 94 return BrowserContext::GetDownloadManager(context); | 43 return BrowserContext::GetDownloadManager(context); |
| 95 } | 44 } |
| 96 | 45 |
| 97 void DownloadRequestHandle::PauseRequest() const { | 46 void DownloadRequestHandle::PauseRequest() const { |
| 98 BrowserThread::PostTask( | 47 BrowserThread::PostTask( |
| 99 BrowserThread::IO, FROM_HERE, | 48 BrowserThread::IO, FROM_HERE, |
| 100 base::Bind(&DownloadResourceHandler::PauseRequest, handler_)); | 49 base::Bind(&DownloadResourceHandler::PauseRequest, handler_)); |
| 101 } | 50 } |
| 102 | 51 |
| 103 void DownloadRequestHandle::ResumeRequest() const { | 52 void DownloadRequestHandle::ResumeRequest() const { |
| 104 BrowserThread::PostTask( | 53 BrowserThread::PostTask( |
| 105 BrowserThread::IO, FROM_HERE, | 54 BrowserThread::IO, FROM_HERE, |
| 106 base::Bind(&DownloadResourceHandler::ResumeRequest, handler_)); | 55 base::Bind(&DownloadResourceHandler::ResumeRequest, handler_)); |
| 107 } | 56 } |
| 108 | 57 |
| 109 void DownloadRequestHandle::CancelRequest() const { | 58 void DownloadRequestHandle::CancelRequest() const { |
| 110 BrowserThread::PostTask( | 59 BrowserThread::PostTask( |
| 111 BrowserThread::IO, FROM_HERE, | 60 BrowserThread::IO, FROM_HERE, |
| 112 base::Bind(&DownloadResourceHandler::CancelRequest, handler_)); | 61 base::Bind(&DownloadResourceHandler::CancelRequest, handler_)); |
| 113 } | 62 } |
| 114 | 63 |
| 115 std::string DownloadRequestHandle::DebugString() const { | |
| 116 return base::StringPrintf("{" | |
| 117 " child_id = %d" | |
| 118 " render_view_id = %d" | |
| 119 " request_id = %d" | |
| 120 "}", | |
| 121 child_id_, | |
| 122 render_view_id_, | |
| 123 request_id_); | |
| 124 } | |
| 125 | |
| 126 } // namespace content | 64 } // namespace content |
| OLD | NEW |