help using KIO to download files in Konqueror

Stefano Crocco stefano.crocco at alice.it
Sun Oct 22 16:02:13 BST 2017


On martedì 22 agosto 2017 17:21:31 CEST Stefano Crocco wrote:
> Hello to everyone,
> I'd need a bit of help to solve an issue I run into while attempting to fix
> Konqueror so that downloads work correctly using QWebEngine.
> 
> The issue regards a situation when you try to download a file which is
> created by a server-side script. It doesn't happen for all such downloads;
> actually, I only found one site causing this behaviour: unfortunately, it's
> the web site of my bank so, of course I can't give you the password to try
> my code.
> 
> The issue is the following: I use KParts::BrowserOpenOrSaveQuestion to ask
> the user whether he wants to save or open the file, then use either
> KIO::copy or KRun, according to the user choice, to download or open the
> file. In both cases, the code is mostly copied from the KDEWebKit framework
> (in particular, from kwebpage.cpp, lines ...). In both cases, however, what
> is downloaded is not the file produced by the script on the server (in this
> case, a PDF) but the script itself. What I can't understand is that using
> KWebKitPart (which means the KDEWebKit framework, whose code I almost
> copied) produces the correct result, downloading or opening the PDF file.
> 
> I tried looking at differences between my code and KWebPage and reading all
> related documentation, but I couldn't find anything which could explain the
> different behaviours. Can someone point me in the right direction?

I've been a bit busy the last couple of months, so I didn't have much time to 
investigate this issue. I tried looking at the requests sent by konqueror when 
using KWebKitPart and when using QWebEngine using mitmproxy, and they look 
very similar. The only differences that I could spot were cookies. It was at 
this point that I realized that QWebEngine doesn't share its cookies with KIO. 
I started looking at the documentation both for QWebEngine and for KIO 
regarding cookies. I found out two classes:
* on QWebEngine's side, there's QWebEngineCookieStore, which provides signals 
emitted whenever a cookie is added or removed and which, according to 
documentation [1], "can be used to synchronize cookies of Chromium and the 
QNetworkAccessManager"
* on KIO's side, there's KIO::Integration::AccessManager, which derives from 
QNetworkAccessManager and which should work along QWebEngineCookieStore.

The example in the documentation for KIO::Integration::AccessManager refers to 
QWebView and says to call QWebPage::setNetworkAccessManager to have the 
QWebView and KIO to use the same access manager. Unfortunately, QWebEngine 
can't be integrated with a QNetworkAccessManager: not only QWebEnginePage 
doesn't have a setNetworkAccessManager method, but the documentation for 
QWebEngine explicitly says that it doesn't use QNetworkAccess. Because of 
this, I thought to do things the other way round: I created a 
KIO::Integration::AccessManager and, used slots connected with 
QWebEngineCookieStore signals, to add cookies to it.

Unfortunately, this doesn't fix the issue. I believe this is because I haven't 
told KIO to use the new access manager. The problem is that I can see any way 
to do it. Does anyone have suggestions on how to do this?

Thanks 

Stefano

[1] http://doc.qt.io/qt-5/qwebenginecookiestore.html#details




More information about the kfm-devel mailing list