2012-06-28 19:21:18 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/browser/download_item_impl.h"
|
|
|
|
|
|
|
|
#include "libcef/common/time_util.h"
|
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
#include "components/download/public/common/download_item.h"
|
2013-07-24 22:15:18 +02:00
|
|
|
#include "url/gurl.h"
|
2012-06-28 19:21:18 +02:00
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
CefDownloadItemImpl::CefDownloadItemImpl(download::DownloadItem* value)
|
|
|
|
: CefValueBase<CefDownloadItem, download::DownloadItem>(
|
2017-05-17 11:29:28 +02:00
|
|
|
value,
|
2020-01-15 14:36:24 +01:00
|
|
|
nullptr,
|
2017-05-17 11:29:28 +02:00
|
|
|
kOwnerNoDelete,
|
|
|
|
true,
|
|
|
|
new CefValueControllerNonThreadSafe()) {
|
2012-06-28 19:21:18 +02:00
|
|
|
// Indicate that this object owns the controller.
|
|
|
|
SetOwnsController();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDownloadItemImpl::IsValid() {
|
|
|
|
return !detached();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDownloadItemImpl::IsInProgress() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
2018-03-20 21:15:08 +01:00
|
|
|
return const_value().GetState() == download::DownloadItem::IN_PROGRESS;
|
2012-06-28 19:21:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDownloadItemImpl::IsComplete() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
2018-03-20 21:15:08 +01:00
|
|
|
return const_value().GetState() == download::DownloadItem::COMPLETE;
|
2012-06-28 19:21:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDownloadItemImpl::IsCanceled() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
2018-03-20 21:15:08 +01:00
|
|
|
return const_value().GetState() == download::DownloadItem::CANCELLED;
|
2012-06-28 19:21:18 +02:00
|
|
|
}
|
|
|
|
|
2023-04-21 06:15:08 +02:00
|
|
|
bool CefDownloadItemImpl::IsInterrupted() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
|
|
|
return const_value().GetState() == download::DownloadItem::INTERRUPTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
cef_download_interrupt_reason_t CefDownloadItemImpl::GetInterruptReason() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, CEF_DOWNLOAD_INTERRUPT_REASON_NONE);
|
|
|
|
return static_cast<cef_download_interrupt_reason_t>(
|
|
|
|
const_value().GetLastReason());
|
|
|
|
}
|
|
|
|
|
2023-06-01 16:06:15 +02:00
|
|
|
int64_t CefDownloadItemImpl::GetCurrentSpeed() {
|
2012-06-28 19:21:18 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, 0);
|
|
|
|
return const_value().CurrentSpeed();
|
|
|
|
}
|
|
|
|
|
|
|
|
int CefDownloadItemImpl::GetPercentComplete() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, -1);
|
|
|
|
return const_value().PercentComplete();
|
|
|
|
}
|
|
|
|
|
2023-06-01 16:06:15 +02:00
|
|
|
int64_t CefDownloadItemImpl::GetTotalBytes() {
|
2012-06-28 19:21:18 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, 0);
|
|
|
|
return const_value().GetTotalBytes();
|
|
|
|
}
|
|
|
|
|
2023-06-01 16:06:15 +02:00
|
|
|
int64_t CefDownloadItemImpl::GetReceivedBytes() {
|
2012-06-28 19:21:18 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, 0);
|
|
|
|
return const_value().GetReceivedBytes();
|
|
|
|
}
|
|
|
|
|
2022-05-31 22:28:43 +02:00
|
|
|
CefBaseTime CefDownloadItemImpl::GetStartTime() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, CefBaseTime());
|
|
|
|
return const_value().GetStartTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefBaseTime CefDownloadItemImpl::GetEndTime() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, CefBaseTime());
|
|
|
|
return const_value().GetEndTime();
|
2012-06-28 19:21:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefDownloadItemImpl::GetFullPath() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, CefString());
|
|
|
|
return const_value().GetFullPath().value();
|
|
|
|
}
|
|
|
|
|
2023-06-01 16:06:15 +02:00
|
|
|
uint32_t CefDownloadItemImpl::GetId() {
|
2012-06-28 19:21:18 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, 0);
|
|
|
|
return const_value().GetId();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefDownloadItemImpl::GetURL() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, CefString());
|
|
|
|
return const_value().GetURL().spec();
|
|
|
|
}
|
|
|
|
|
2015-01-20 23:48:32 +01:00
|
|
|
CefString CefDownloadItemImpl::GetOriginalUrl() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, CefString());
|
|
|
|
return const_value().GetOriginalUrl().spec();
|
|
|
|
}
|
|
|
|
|
2012-06-28 19:21:18 +02:00
|
|
|
CefString CefDownloadItemImpl::GetSuggestedFileName() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, CefString());
|
|
|
|
return const_value().GetSuggestedFilename();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefDownloadItemImpl::GetContentDisposition() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, CefString());
|
|
|
|
return const_value().GetContentDisposition();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefDownloadItemImpl::GetMimeType() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, CefString());
|
|
|
|
return const_value().GetMimeType();
|
|
|
|
}
|