summaryrefslogtreecommitdiffstats
path: root/src/core/download_manager_delegate_qt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/download_manager_delegate_qt.cpp')
-rw-r--r--src/core/download_manager_delegate_qt.cpp122
1 files changed, 70 insertions, 52 deletions
diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp
index 487a831e4..9fe233577 100644
--- a/src/core/download_manager_delegate_qt.cpp
+++ b/src/core/download_manager_delegate_qt.cpp
@@ -39,10 +39,11 @@
#include "download_manager_delegate_qt.h"
+#include "content/public/browser/download_item_utils.h"
#include "content/public/browser/download_manager.h"
-#include "content/public/browser/download_item.h"
#include "content/public/browser/save_page_type.h"
#include "content/public/browser/web_contents.h"
+#include "net/base/net_string_util.h"
#include "net/http/http_content_disposition.h"
#include <QDir>
@@ -52,22 +53,22 @@
#include <QMimeDatabase>
#include <QStandardPaths>
-#include "browser_context_adapter.h"
-#include "browser_context_adapter_client.h"
-#include "browser_context_qt.h"
+#include "profile_adapter_client.h"
+#include "profile_adapter.h"
+#include "profile_qt.h"
+#include "qtwebenginecoreglobal.h"
#include "type_conversion.h"
#include "web_contents_delegate_qt.h"
-#include "qtwebenginecoreglobal.h"
namespace QtWebEngineCore {
-DownloadManagerDelegateQt::DownloadManagerDelegateQt(BrowserContextAdapter *contextAdapter)
- : m_contextAdapter(contextAdapter)
+DownloadManagerDelegateQt::DownloadManagerDelegateQt(ProfileAdapter *profileAdapter)
+ : m_profileAdapter(profileAdapter)
, m_currentId(0)
, m_weakPtrFactory(this)
, m_nextDownloadIsUserRequested(false)
{
- Q_ASSERT(m_contextAdapter);
+ Q_ASSERT(m_profileAdapter);
}
DownloadManagerDelegateQt::~DownloadManagerDelegateQt()
@@ -81,42 +82,42 @@ void DownloadManagerDelegateQt::GetNextId(const content::DownloadIdCallback& cal
void DownloadManagerDelegateQt::cancelDownload(const content::DownloadTargetCallback& callback)
{
- callback.Run(base::FilePath(), content::DownloadItem::TARGET_DISPOSITION_PROMPT, content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, base::FilePath(), content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED);
+ callback.Run(base::FilePath(), download::DownloadItem::TARGET_DISPOSITION_PROMPT, download::DownloadDangerType::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, base::FilePath(), download::DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED);
}
void DownloadManagerDelegateQt::cancelDownload(quint32 downloadId)
{
- content::DownloadManager* dlm = content::BrowserContext::GetDownloadManager(m_contextAdapter->browserContext());
- content::DownloadItem *download = dlm->GetDownload(downloadId);
+ content::DownloadManager* dlm = content::BrowserContext::GetDownloadManager(m_profileAdapter->profile());
+ download::DownloadItem *download = dlm->GetDownload(downloadId);
if (download)
download->Cancel(/* user_cancel */ true);
}
void DownloadManagerDelegateQt::pauseDownload(quint32 downloadId)
{
- content::DownloadManager* dlm = content::BrowserContext::GetDownloadManager(m_contextAdapter->browserContext());
- content::DownloadItem *download = dlm->GetDownload(downloadId);
+ content::DownloadManager* dlm = content::BrowserContext::GetDownloadManager(m_profileAdapter->profile());
+ download::DownloadItem *download = dlm->GetDownload(downloadId);
if (download)
download->Pause();
}
void DownloadManagerDelegateQt::resumeDownload(quint32 downloadId)
{
- content::DownloadManager* dlm = content::BrowserContext::GetDownloadManager(m_contextAdapter->browserContext());
- content::DownloadItem *download = dlm->GetDownload(downloadId);
+ content::DownloadManager* dlm = content::BrowserContext::GetDownloadManager(m_profileAdapter->profile());
+ download::DownloadItem *download = dlm->GetDownload(downloadId);
if (download)
download->Resume();
}
-bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* item,
+bool DownloadManagerDelegateQt::DetermineDownloadTarget(download::DownloadItem* item,
const content::DownloadTargetCallback& callback)
{
// Keep the forced file path if set, also as the temporary file, so the check for existence
// will already return that the file exists. Forced file paths seem to be only used for
// store downloads and other special downloads, so they might never end up here anyway.
if (!item->GetForcedFilePath().empty()) {
- callback.Run(item->GetForcedFilePath(), content::DownloadItem::TARGET_DISPOSITION_PROMPT,
- content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, item->GetForcedFilePath(), content::DOWNLOAD_INTERRUPT_REASON_NONE);
+ callback.Run(item->GetForcedFilePath(), download::DownloadItem::TARGET_DISPOSITION_PROMPT,
+ download::DownloadDangerType::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, item->GetForcedFilePath(), download::DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE);
return true;
}
@@ -125,18 +126,18 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i
int downloadType = 0;
if (m_nextDownloadIsUserRequested) {
- downloadType = BrowserContextAdapterClient::UserRequested;
+ downloadType = ProfileAdapterClient::UserRequested;
m_nextDownloadIsUserRequested = false;
} else {
bool isAttachment = net::HttpContentDisposition(item->GetContentDisposition(), std::string()).is_attachment();
if (isAttachment)
- downloadType = BrowserContextAdapterClient::Attachment;
+ downloadType = ProfileAdapterClient::Attachment;
else
- downloadType = BrowserContextAdapterClient::DownloadAttribute;
+ downloadType = ProfileAdapterClient::DownloadAttribute;
}
if (suggestedFilename.isEmpty())
- suggestedFilename = toQt(net::HttpContentDisposition(item->GetContentDisposition(), std::string()).filename());
+ suggestedFilename = toQt(net::HttpContentDisposition(item->GetContentDisposition(), net::kCharsetLatin1).filename());
if (suggestedFilename.isEmpty())
suggestedFilename = toQt(item->GetTargetFilePath().AsUTF8Unsafe());
@@ -166,9 +167,14 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i
}
item->AddObserver(this);
- QList<BrowserContextAdapterClient*> clients = m_contextAdapter->clients();
+ QList<ProfileAdapterClient*> clients = m_profileAdapter->clients();
if (!clients.isEmpty()) {
- BrowserContextAdapterClient::DownloadItemInfo info = {
+ content::WebContents *webContents = content::DownloadItemUtils::GetWebContents(item);
+ WebContentsAdapterClient *adapterClient = nullptr;
+ if (webContents)
+ adapterClient = static_cast<WebContentsDelegateQt *>(webContents->GetDelegate())->adapterClient();
+
+ ProfileAdapterClient::DownloadItemInfo info = {
item->GetId(),
toQt(item->GetURL()),
item->GetState(),
@@ -176,15 +182,16 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i
item->GetReceivedBytes(),
mimeTypeString,
suggestedFilePath,
- BrowserContextAdapterClient::UnknownSavePageFormat,
+ ProfileAdapterClient::UnknownSavePageFormat,
false /* accepted */,
false /* paused */,
false /* done */,
downloadType,
- item->GetLastReason()
+ item->GetLastReason(),
+ adapterClient
};
- Q_FOREACH (BrowserContextAdapterClient *client, clients) {
+ for (ProfileAdapterClient *client : qAsConst(clients)) {
client->downloadRequested(info);
if (info.accepted)
break;
@@ -204,10 +211,10 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i
base::FilePath filePathForCallback(toFilePathString(suggestedFile.absoluteFilePath()));
callback.Run(filePathForCallback,
- content::DownloadItem::TARGET_DISPOSITION_OVERWRITE,
- content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT,
+ download::DownloadItem::TARGET_DISPOSITION_OVERWRITE,
+ download::DownloadDangerType::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT,
filePathForCallback.AddExtension(toFilePathString("download")),
- content::DOWNLOAD_INTERRUPT_REASON_NONE);
+ download::DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE);
} else
cancelDownload(callback);
@@ -234,7 +241,7 @@ void DownloadManagerDelegateQt::ChooseSavePath(content::WebContents *web_content
Q_UNUSED(default_extension);
Q_UNUSED(can_save_as_complete);
- QList<BrowserContextAdapterClient*> clients = m_contextAdapter->clients();
+ QList<ProfileAdapterClient*> clients = m_profileAdapter->clients();
if (clients.isEmpty())
return;
@@ -255,18 +262,22 @@ void DownloadManagerDelegateQt::ChooseSavePath(content::WebContents *web_content
suggestedFilePath = downloadDir.absoluteFilePath(suggestedFilePath);
}
- BrowserContextAdapterClient::SavePageFormat suggestedSaveFormat
- = static_cast<BrowserContextAdapterClient::SavePageFormat>(spi.requestedFormat);
- if (suggestedSaveFormat == BrowserContextAdapterClient::UnknownSavePageFormat)
- suggestedSaveFormat = BrowserContextAdapterClient::MimeHtmlSaveFormat;
+ ProfileAdapterClient::SavePageFormat suggestedSaveFormat
+ = static_cast<ProfileAdapterClient::SavePageFormat>(spi.requestedFormat);
+ if (suggestedSaveFormat == ProfileAdapterClient::UnknownSavePageFormat)
+ suggestedSaveFormat = ProfileAdapterClient::MimeHtmlSaveFormat;
// Clear the delegate's SavePageInfo. It's only valid for the page currently being saved.
contentsDelegate->setSavePageInfo(SavePageInfo());
- BrowserContextAdapterClient::DownloadItemInfo info = {
+ WebContentsAdapterClient *adapterClient = nullptr;
+ if (web_contents)
+ adapterClient = static_cast<WebContentsDelegateQt *>(web_contents->GetDelegate())->adapterClient();
+
+ ProfileAdapterClient::DownloadItemInfo info = {
m_currentId + 1,
toQt(web_contents->GetURL()),
- content::DownloadItem::IN_PROGRESS,
+ download::DownloadItem::IN_PROGRESS,
0, /* totalBytes */
0, /* receivedBytes */
QStringLiteral("application/x-mimearchive"),
@@ -275,11 +286,12 @@ void DownloadManagerDelegateQt::ChooseSavePath(content::WebContents *web_content
acceptedByDefault,
false, /* paused */
false, /* done */
- BrowserContextAdapterClient::SavePage,
- BrowserContextAdapterClient::NoReason
+ ProfileAdapterClient::SavePage,
+ ProfileAdapterClient::NoReason,
+ adapterClient
};
- Q_FOREACH (BrowserContextAdapterClient *client, clients) {
+ for (ProfileAdapterClient *client : qAsConst(clients)) {
client->downloadRequested(info);
if (info.accepted)
break;
@@ -293,10 +305,10 @@ void DownloadManagerDelegateQt::ChooseSavePath(content::WebContents *web_content
m_weakPtrFactory.GetWeakPtr()));
}
-bool DownloadManagerDelegateQt::IsMostRecentDownloadItemAtFilePath(content::DownloadItem *download)
+bool DownloadManagerDelegateQt::IsMostRecentDownloadItemAtFilePath(download::DownloadItem *download)
{
- content::BrowserContext *context = download->GetBrowserContext();
- std::vector<content::DownloadItem*> all_downloads;
+ content::BrowserContext *context = content::DownloadItemUtils::GetBrowserContext(download);
+ std::vector<download::DownloadItem*> all_downloads;
content::DownloadManager* manager =
content::BrowserContext::GetDownloadManager(context);
@@ -307,23 +319,28 @@ bool DownloadManagerDelegateQt::IsMostRecentDownloadItemAtFilePath(content::Down
if (item->GetGuid() == download->GetGuid() ||
item->GetTargetFilePath() != download->GetTargetFilePath())
continue;
- if (item->GetState() == content::DownloadItem::IN_PROGRESS)
+ if (item->GetState() == download::DownloadItem::IN_PROGRESS)
return false;
}
return true;
}
-void DownloadManagerDelegateQt::savePackageDownloadCreated(content::DownloadItem *item)
+void DownloadManagerDelegateQt::savePackageDownloadCreated(download::DownloadItem *item)
{
OnDownloadUpdated(item);
item->AddObserver(this);
}
-void DownloadManagerDelegateQt::OnDownloadUpdated(content::DownloadItem *download)
+void DownloadManagerDelegateQt::OnDownloadUpdated(download::DownloadItem *download)
{
- QList<BrowserContextAdapterClient*> clients = m_contextAdapter->clients();
+ QList<ProfileAdapterClient*> clients = m_profileAdapter->clients();
if (!clients.isEmpty()) {
- BrowserContextAdapterClient::DownloadItemInfo info = {
+ WebContentsAdapterClient *adapterClient = nullptr;
+ content::WebContents *webContents = content::DownloadItemUtils::GetWebContents(download);
+ if (webContents)
+ adapterClient = static_cast<WebContentsDelegateQt *>(webContents->GetDelegate())->adapterClient();
+
+ ProfileAdapterClient::DownloadItemInfo info = {
download->GetId(),
toQt(download->GetURL()),
download->GetState(),
@@ -331,21 +348,22 @@ void DownloadManagerDelegateQt::OnDownloadUpdated(content::DownloadItem *downloa
download->GetReceivedBytes(),
toQt(download->GetMimeType()),
QString(),
- BrowserContextAdapterClient::UnknownSavePageFormat,
+ ProfileAdapterClient::UnknownSavePageFormat,
true /* accepted */,
download->IsPaused(),
download->IsDone(),
0 /* downloadType (unused) */,
- download->GetLastReason()
+ download->GetLastReason(),
+ adapterClient
};
- Q_FOREACH (BrowserContextAdapterClient *client, clients) {
+ for (ProfileAdapterClient *client : qAsConst(clients)) {
client->downloadUpdated(info);
}
}
}
-void DownloadManagerDelegateQt::OnDownloadDestroyed(content::DownloadItem *download)
+void DownloadManagerDelegateQt::OnDownloadDestroyed(download::DownloadItem *download)
{
download->RemoveObserver(this);
download->Cancel(/* user_cancel */ false);