1 // Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4
5 #include "libcef/browser/download_item_impl.h"
6
7 #include "libcef/common/time_util.h"
8
9 #include "components/download/public/common/download_item.h"
10 #include "url/gurl.h"
11
CefDownloadItemImpl(download::DownloadItem * value)12 CefDownloadItemImpl::CefDownloadItemImpl(download::DownloadItem* value)
13 : CefValueBase<CefDownloadItem, download::DownloadItem>(
14 value,
15 nullptr,
16 kOwnerNoDelete,
17 true,
18 new CefValueControllerNonThreadSafe()) {
19 // Indicate that this object owns the controller.
20 SetOwnsController();
21 }
22
IsValid()23 bool CefDownloadItemImpl::IsValid() {
24 return !detached();
25 }
26
IsInProgress()27 bool CefDownloadItemImpl::IsInProgress() {
28 CEF_VALUE_VERIFY_RETURN(false, false);
29 return const_value().GetState() == download::DownloadItem::IN_PROGRESS;
30 }
31
IsComplete()32 bool CefDownloadItemImpl::IsComplete() {
33 CEF_VALUE_VERIFY_RETURN(false, false);
34 return const_value().GetState() == download::DownloadItem::COMPLETE;
35 }
36
IsCanceled()37 bool CefDownloadItemImpl::IsCanceled() {
38 CEF_VALUE_VERIFY_RETURN(false, false);
39 return const_value().GetState() == download::DownloadItem::CANCELLED;
40 }
41
GetCurrentSpeed()42 int64 CefDownloadItemImpl::GetCurrentSpeed() {
43 CEF_VALUE_VERIFY_RETURN(false, 0);
44 return const_value().CurrentSpeed();
45 }
46
GetPercentComplete()47 int CefDownloadItemImpl::GetPercentComplete() {
48 CEF_VALUE_VERIFY_RETURN(false, -1);
49 return const_value().PercentComplete();
50 }
51
GetTotalBytes()52 int64 CefDownloadItemImpl::GetTotalBytes() {
53 CEF_VALUE_VERIFY_RETURN(false, 0);
54 return const_value().GetTotalBytes();
55 }
56
GetReceivedBytes()57 int64 CefDownloadItemImpl::GetReceivedBytes() {
58 CEF_VALUE_VERIFY_RETURN(false, 0);
59 return const_value().GetReceivedBytes();
60 }
61
GetStartTime()62 CefTime CefDownloadItemImpl::GetStartTime() {
63 CefTime time;
64 CEF_VALUE_VERIFY_RETURN(false, time);
65 cef_time_from_basetime(const_value().GetStartTime(), time);
66 return time;
67 }
68
GetEndTime()69 CefTime CefDownloadItemImpl::GetEndTime() {
70 CefTime time;
71 CEF_VALUE_VERIFY_RETURN(false, time);
72 cef_time_from_basetime(const_value().GetEndTime(), time);
73 return time;
74 }
75
GetFullPath()76 CefString CefDownloadItemImpl::GetFullPath() {
77 CEF_VALUE_VERIFY_RETURN(false, CefString());
78 return const_value().GetFullPath().value();
79 }
80
GetId()81 uint32 CefDownloadItemImpl::GetId() {
82 CEF_VALUE_VERIFY_RETURN(false, 0);
83 return const_value().GetId();
84 }
85
GetURL()86 CefString CefDownloadItemImpl::GetURL() {
87 CEF_VALUE_VERIFY_RETURN(false, CefString());
88 return const_value().GetURL().spec();
89 }
90
GetOriginalUrl()91 CefString CefDownloadItemImpl::GetOriginalUrl() {
92 CEF_VALUE_VERIFY_RETURN(false, CefString());
93 return const_value().GetOriginalUrl().spec();
94 }
95
GetSuggestedFileName()96 CefString CefDownloadItemImpl::GetSuggestedFileName() {
97 CEF_VALUE_VERIFY_RETURN(false, CefString());
98 return const_value().GetSuggestedFilename();
99 }
100
GetContentDisposition()101 CefString CefDownloadItemImpl::GetContentDisposition() {
102 CEF_VALUE_VERIFY_RETURN(false, CefString());
103 return const_value().GetContentDisposition();
104 }
105
GetMimeType()106 CefString CefDownloadItemImpl::GetMimeType() {
107 CEF_VALUE_VERIFY_RETURN(false, CefString());
108 return const_value().GetMimeType();
109 }
110