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 |
| 15 namespace { | |
| 16 | |
| 17 WebContents* NullContents() { | |
|
Charlie Harrison
2016/02/23 19:22:49
There may be a better way of doing this (base::Bin
asanka
2016/02/24 20:02:16
Or you could make GetWebContents() check for !web_
Charlie Harrison
2016/02/25 15:49:55
I went with using the null callback.
| |
| 18 return NULL; | |
|
asanka
2016/02/24 20:02:16
NULL -> nullptr here and elsewhere.
Charlie Harrison
2016/02/25 15:49:55
Done.
| |
| 19 } | |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 19 DownloadRequestHandleInterface::~DownloadRequestHandleInterface() {} | 23 DownloadRequestHandleInterface::~DownloadRequestHandleInterface() {} |
| 20 | 24 |
| 21 DownloadRequestHandle::~DownloadRequestHandle() {} | 25 DownloadRequestHandle::~DownloadRequestHandle() {} |
| 22 | 26 |
| 23 DownloadRequestHandle::DownloadRequestHandle() | 27 DownloadRequestHandle::DownloadRequestHandle() |
| 24 : child_id_(-1), | 28 : web_contents_getter_(base::Bind(&NullContents)) {} |
| 25 render_view_id_(-1), | |
| 26 request_id_(-1), | |
| 27 frame_tree_node_id_(-1) { | |
| 28 } | |
| 29 | 29 |
| 30 DownloadRequestHandle::DownloadRequestHandle( | 30 DownloadRequestHandle::DownloadRequestHandle( |
| 31 const base::WeakPtr<DownloadResourceHandler>& handler, | 31 const base::WeakPtr<DownloadResourceHandler>& handler, |
| 32 int child_id, | 32 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter) |
| 33 int render_view_id, | 33 : handler_(handler), web_contents_getter_(web_contents_getter) { |
| 34 int request_id, | |
| 35 int frame_tree_node_id) | |
| 36 : handler_(handler), | |
| 37 child_id_(child_id), | |
| 38 render_view_id_(render_view_id), | |
| 39 request_id_(request_id), | |
| 40 frame_tree_node_id_(frame_tree_node_id) { | |
| 41 DCHECK(handler_.get()); | 34 DCHECK(handler_.get()); |
| 42 } | 35 } |
| 43 | 36 |
| 44 WebContents* DownloadRequestHandle::GetWebContents() const { | 37 WebContents* DownloadRequestHandle::GetWebContents() const { |
| 45 // PlzNavigate: if a FrameTreeNodeId was provided, use it to return the | 38 return web_contents_getter_.Run(); |
| 46 // WebContents. | |
| 47 // TODO(davidben): This logic should be abstracted within the ResourceLoader | |
| 48 // stack. https://crbug.com/376003 | |
| 49 if (IsBrowserSideNavigationEnabled()) { | |
| 50 FrameTreeNode* frame_tree_node = | |
| 51 FrameTreeNode::GloballyFindByID(frame_tree_node_id_); | |
| 52 if (frame_tree_node) { | |
| 53 return WebContentsImpl::FromFrameTreeNode(frame_tree_node); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 RenderViewHostImpl* render_view_host = | |
| 58 RenderViewHostImpl::FromID(child_id_, render_view_id_); | |
| 59 if (!render_view_host) | |
| 60 return nullptr; | |
| 61 | |
| 62 return render_view_host->GetDelegate()->GetAsWebContents(); | |
| 63 } | 39 } |
| 64 | 40 |
| 65 DownloadManager* DownloadRequestHandle::GetDownloadManager() const { | 41 DownloadManager* DownloadRequestHandle::GetDownloadManager() const { |
| 66 // PlzNavigate: if a FrameTreeNodeId was provided, use it to return the | 42 WebContents* web_contents = GetWebContents(); |
| 67 // DownloadManager. | 43 if (web_contents == NULL) |
| 68 // TODO(davidben): This logic should be abstracted within the ResourceLoader | |
| 69 // stack. https://crbug.com/376003 | |
| 70 if (IsBrowserSideNavigationEnabled()) { | |
|
Charlie Harrison
2016/02/23 19:22:49
clamy@, this is all obsolete with the web contents
| |
| 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 | |
| 81 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID( | |
| 82 child_id_, render_view_id_); | |
| 83 if (rvh == NULL) | |
| 84 return NULL; | 44 return NULL; |
| 85 RenderProcessHost* rph = rvh->GetProcess(); | 45 BrowserContext* context = web_contents->GetBrowserContext(); |
| 86 if (rph == NULL) | |
| 87 return NULL; | |
| 88 BrowserContext* context = rph->GetBrowserContext(); | |
| 89 if (context == NULL) | 46 if (context == NULL) |
| 90 return NULL; | 47 return NULL; |
| 91 return BrowserContext::GetDownloadManager(context); | 48 return BrowserContext::GetDownloadManager(context); |
| 92 } | 49 } |
| 93 | 50 |
| 94 void DownloadRequestHandle::PauseRequest() const { | 51 void DownloadRequestHandle::PauseRequest() const { |
| 95 BrowserThread::PostTask( | 52 BrowserThread::PostTask( |
| 96 BrowserThread::IO, FROM_HERE, | 53 BrowserThread::IO, FROM_HERE, |
| 97 base::Bind(&DownloadResourceHandler::PauseRequest, handler_)); | 54 base::Bind(&DownloadResourceHandler::PauseRequest, handler_)); |
| 98 } | 55 } |
| 99 | 56 |
| 100 void DownloadRequestHandle::ResumeRequest() const { | 57 void DownloadRequestHandle::ResumeRequest() const { |
| 101 BrowserThread::PostTask( | 58 BrowserThread::PostTask( |
| 102 BrowserThread::IO, FROM_HERE, | 59 BrowserThread::IO, FROM_HERE, |
| 103 base::Bind(&DownloadResourceHandler::ResumeRequest, handler_)); | 60 base::Bind(&DownloadResourceHandler::ResumeRequest, handler_)); |
| 104 } | 61 } |
| 105 | 62 |
| 106 void DownloadRequestHandle::CancelRequest() const { | 63 void DownloadRequestHandle::CancelRequest() const { |
| 107 BrowserThread::PostTask( | 64 BrowserThread::PostTask( |
| 108 BrowserThread::IO, FROM_HERE, | 65 BrowserThread::IO, FROM_HERE, |
| 109 base::Bind(&DownloadResourceHandler::CancelRequest, handler_)); | 66 base::Bind(&DownloadResourceHandler::CancelRequest, handler_)); |
| 110 } | 67 } |
| 111 | 68 |
| 112 std::string DownloadRequestHandle::DebugString() const { | 69 std::string DownloadRequestHandle::DebugString() const { |
| 113 return base::StringPrintf("{" | 70 return "{}"; |
|
Charlie Harrison
2016/02/23 19:22:49
The request_id_ was only used for this DebugString
asanka
2016/02/24 20:02:16
Not necessary. Looks like this is only called from
Charlie Harrison
2016/02/25 15:49:55
Nice. Done.
| |
| 114 " child_id = %d" | |
| 115 " render_view_id = %d" | |
| 116 " request_id = %d" | |
| 117 "}", | |
| 118 child_id_, | |
| 119 render_view_id_, | |
| 120 request_id_); | |
| 121 } | 71 } |
| 122 | 72 |
| 123 } // namespace content | 73 } // namespace content |
| OLD | NEW |