Add ICU message format support
[chromium-blink-merge.git] / content / browser / download / download_request_handle.cc
blob6e319d3abee213eac6300b25abaf661bea3b4a53
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
3 // found in the LICENSE file.
5 #include "content/browser/download/download_request_handle.h"
7 #include "base/bind.h"
8 #include "base/command_line.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"
12 #include "content/browser/renderer_host/render_view_host_impl.h"
13 #include "content/browser/web_contents/web_contents_impl.h"
14 #include "content/public/browser/browser_context.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/common/content_switches.h"
18 namespace content {
20 DownloadRequestHandle::~DownloadRequestHandle() {
23 DownloadRequestHandle::DownloadRequestHandle()
24 : child_id_(-1),
25 render_view_id_(-1),
26 request_id_(-1),
27 frame_tree_node_id_(-1) {
30 DownloadRequestHandle::DownloadRequestHandle(
31 const base::WeakPtr<DownloadResourceHandler>& handler,
32 int child_id,
33 int render_view_id,
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());
44 WebContents* DownloadRequestHandle::GetWebContents() const {
45 // PlzNavigate: if a FrameTreeNodeID was provided, use it to return the
46 // WebContents.
47 // TODO(davidben): This logic should be abstracted within the ResourceLoader
48 // stack. https://crbug.com/376003
49 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
50 switches::kEnableBrowserSideNavigation)) {
51 FrameTreeNode* frame_tree_node =
52 FrameTreeNode::GloballyFindByID(frame_tree_node_id_);
53 if (frame_tree_node) {
54 return WebContentsImpl::FromFrameTreeNode(frame_tree_node);
58 RenderViewHostImpl* render_view_host =
59 RenderViewHostImpl::FromID(child_id_, render_view_id_);
60 if (!render_view_host)
61 return nullptr;
63 return render_view_host->GetDelegate()->GetAsWebContents();
66 DownloadManager* DownloadRequestHandle::GetDownloadManager() const {
67 // PlzNavigate: if a FrameTreeNodeID was provided, use it to return the
68 // DownloadManager.
69 // TODO(davidben): This logic should be abstracted within the ResourceLoader
70 // stack. https://crbug.com/376003
71 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
72 switches::kEnableBrowserSideNavigation)) {
73 FrameTreeNode* frame_tree_node =
74 FrameTreeNode::GloballyFindByID(frame_tree_node_id_);
75 if (frame_tree_node) {
76 BrowserContext* context =
77 frame_tree_node->navigator()->GetController()->GetBrowserContext();
78 if (context)
79 return BrowserContext::GetDownloadManager(context);
83 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID(
84 child_id_, render_view_id_);
85 if (rvh == NULL)
86 return NULL;
87 RenderProcessHost* rph = rvh->GetProcess();
88 if (rph == NULL)
89 return NULL;
90 BrowserContext* context = rph->GetBrowserContext();
91 if (context == NULL)
92 return NULL;
93 return BrowserContext::GetDownloadManager(context);
96 void DownloadRequestHandle::PauseRequest() const {
97 BrowserThread::PostTask(
98 BrowserThread::IO, FROM_HERE,
99 base::Bind(&DownloadResourceHandler::PauseRequest, handler_));
102 void DownloadRequestHandle::ResumeRequest() const {
103 BrowserThread::PostTask(
104 BrowserThread::IO, FROM_HERE,
105 base::Bind(&DownloadResourceHandler::ResumeRequest, handler_));
108 void DownloadRequestHandle::CancelRequest() const {
109 BrowserThread::PostTask(
110 BrowserThread::IO, FROM_HERE,
111 base::Bind(&DownloadResourceHandler::CancelRequest, handler_));
114 std::string DownloadRequestHandle::DebugString() const {
115 return base::StringPrintf("{"
116 " child_id = %d"
117 " render_view_id = %d"
118 " request_id = %d"
119 "}",
120 child_id_,
121 render_view_id_,
122 request_id_);
125 } // namespace content