Commit e6ee46cd authored by Stefano Crocco's avatar Stefano Crocco
Browse files

Mark the file downloaded from a blob as temporary

When emitting the BrowserExtension::openUrlRequest for the file a blob
URL was downloaded to, add an entry to
KParts::OpenArgumentRequest::metaData. This entry is taken into account
by KonqMainWindow::openUrlRequestHelper which will set the tempFile flag
of the KonqOpenUrlRequest it creates to true.

This way, if the file is opened in Konqueror, it's deleted when the
corresponding tab does. It doesn't have any effect if the file is opened
in an external application.
parent affaab82
......@@ -1023,6 +1023,9 @@ void KonqMainWindow::openUrlRequestHelper(KonqView *childView, const QUrl &url,
//qCDebug(KONQUEROR_LOG) << "url=" << url;
KonqOpenURLRequest req;
req.args = args;
if (args.metaData().value("konq-temp-file") == "1") {
req.tempFile = true;
}
req.browserArgs = browserArgs;
openUrl(childView, url, args.mimeType(), req, browserArgs.trustedSource);
}
......
......@@ -156,6 +156,16 @@ void WebEnginePage::download(const QUrl& url, bool newWindow)
emit part()->browserExtension()->openUrlRequest(url, KParts::OpenUrlArguments(), bArgs);
}
void WebEnginePage::requestOpenFileAsTemporary(const QUrl& url, const QString &mimeType, bool newWindow)
{
KParts::BrowserArguments bArgs;
bArgs.setForcesNewWindow(newWindow);
KParts::OpenUrlArguments oArgs;
oArgs.setMimeType(mimeType);
oArgs.metaData().insert("konq-temp-file", "1");
emit part()->browserExtension()->openUrlRequest(url, oArgs, bArgs);
}
QWebEnginePage *WebEnginePage::createWindow(WebWindowType type)
{
//qCDebug(WEBENGINEPART_LOG) << "window type:" << type;
......
......@@ -64,8 +64,10 @@ public:
void download(const QUrl &url, bool newWindow = false);
void requestOpenFileAsTemporary(const QUrl &url, const QString &mimeType = "", bool newWindow = false);
WebEngineWallet* wallet() const {return m_wallet;}
/**
* @brief Tells the page that the part has requested to load the given URL
*
......@@ -110,7 +112,7 @@ protected:
* @internal
*/
bool acceptNavigationRequest(const QUrl& request, NavigationType type, bool isMainFrame) override;
/**
* @brief Override of `QWebEnginePage::certificateError`
*
......@@ -154,7 +156,7 @@ private:
QScopedPointer<KPasswdServerClient> m_passwdServerClient;
WebEngineWallet *m_wallet;
/**
* @brief The last URL that the part requested to be loaded
*
......
......@@ -196,7 +196,7 @@ void WebEnginePartDownloadManager::blobDownloadedToFile(QWebEngineDownloadItem *
{
QString file = QDir(it->downloadDirectory()).filePath(it->downloadFileName());
if (page) {
page->download(QUrl::fromLocalFile(file), false);
page->requestOpenFileAsTemporary(QUrl::fromLocalFile(file), it->mimeType());
} else {
KIO::OpenUrlJob *j = new KIO::OpenUrlJob(QUrl::fromLocalFile(file), it->mimeType(), this);
j->start();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment