From e6a74159cebdbfec575f40469c216c90ee8651c1 Mon Sep 17 00:00:00 2001 From: Andras Becsi Date: Thu, 11 Dec 2014 19:57:58 +0100 Subject: Add QML download API This patch exposes downloadStarted and downloadFinished signals on the WebEngineProfile to notify about downloads. The WebEngineDownloadItem exposes a subset of Chromium's content::DownloadItem functionality. For now we expose minimal requirements to be able to control downloads in QML but this can be extended in the future. This patch also adds a DownloadView to quicktestbrowser to demonstrate the usage of the new API. [ChangeLog][QtWebEngineQML] Add QtQuick download API Change-Id: I8d8f0daf02c4e0151000427fc2a4b37d28b9db52 Reviewed-by: Jocelyn Turcotte --- src/core/browser_context_adapter.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/core/browser_context_adapter.cpp') diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp index 637003f96..95ddc4d87 100644 --- a/src/core/browser_context_adapter.cpp +++ b/src/core/browser_context_adapter.cpp @@ -36,8 +36,10 @@ #include "browser_context_adapter.h" +#include "content/public/browser/browser_thread.h" #include "browser_context_qt.h" #include "content_client_qt.h" +#include "download_manager_delegate_qt.h" #include "web_engine_context.h" #include "web_engine_visited_links_manager.h" #include "url_request_context_getter_qt.h" @@ -67,6 +69,7 @@ BrowserContextAdapter::BrowserContextAdapter(bool offTheRecord) , m_httpCacheType(DiskHttpCache) , m_persistentCookiesPolicy(AllowPersistentCookies) , m_visitedLinksPolicy(TrackVisitedLinksOnDisk) + , m_client(0) , m_httpCacheMaxSize(0) { } @@ -84,6 +87,8 @@ BrowserContextAdapter::BrowserContextAdapter(const QString &storageName) BrowserContextAdapter::~BrowserContextAdapter() { + if (m_downloadManagerDelegate) + content::BrowserThread::DeleteSoon(content::BrowserThread::UI, FROM_HERE, m_downloadManagerDelegate.take()); } void BrowserContextAdapter::setStorageName(const QString &storageName) @@ -118,6 +123,23 @@ WebEngineVisitedLinksManager *BrowserContextAdapter::visitedLinksManager() return m_visitedLinksManager.data(); } +DownloadManagerDelegateQt *BrowserContextAdapter::downloadManagerDelegate() +{ + if (!m_downloadManagerDelegate) + m_downloadManagerDelegate.reset(new DownloadManagerDelegateQt(this)); + return m_downloadManagerDelegate.data(); +} + +void BrowserContextAdapter::setClient(BrowserContextAdapterClient *adapterClient) +{ + m_client = adapterClient; +} + +void BrowserContextAdapter::cancelDownload(quint32 downloadId) +{ + downloadManagerDelegate()->cancelDownload(downloadId); +} + BrowserContextAdapter* BrowserContextAdapter::defaultContext() { return WebEngineContext::current()->defaultBrowserContext(); -- cgit v1.2.3