[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: KIO and cookies
From:       Allan Sandfeld Jensen <kde () carewolf ! com>
Date:       2017-10-31 21:33:24
Message-ID: 3041814.UYzHKCJzIc () twilight
[Download RAW message or body]

On Dienstag, 31. Oktober 2017 21:17:35 CET Stefano Crocco wrote:
> On marted́ 31 ottobre 2017 01:47:37 CET Allan Sandfeld Jensen wrote:
> > On Sonntag, 29. Oktober 2017 09:47:24 CET Stefano Crocco wrote:
> > > Hello to everyone,
> > > I'm working on making QWebEngine work correctly in Konqueror when
> > > downloading files (although I didn't have much time to spend on this in
> > > the
> > > last months).
> > > 
> > > The problem is that instead of downloading the correct files, in some
> > > cases
> > > Konqueror download html files. This only happens from sites requiring
> > > authentication (I first noticed when trying to download a file from my
> > > bank's web page); besides, it only happens if I try to use KIO for the
> > > download, for example calling KIO::copy from a slot connected with
> > > QWebEngineProfile::downloadRequested. The file downloads correctly if
> > > Konqueror downloads it using the mechanism provided by QWebEngine, that
> > > is
> > > calling QWebEngineDownloaditem::accept.
> > > 
> > > I believe that the issue is caused by cookies, and in particular by the
> > > fact that QWebEngine doesn't share its cookies with KIO so that, when
> > > KIO
> > > attempts to download the file, it doesn't have the cookie(s) associated
> > > with the session opened in the browser and the web page refuses to let
> > > it
> > > download the file (indeed, one of the sites where this happens returned
> > > a
> > > login page instead of the PDF I wanted to download).
> > > 
> > > 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?
> > 
> > KIO has its own cookie-store separate from QNAMs cookie store. So there
> > are three cookie stores. QtNetwork's, KIOs, and QtWebEngine's. Of course
> > the easiest solution would be to let QtWebEngine handle the downloading,
> > but that wouldn't integrate into normal KDE download mechanisms. So you
> > need to bridge QtWebEngine's cookies into KIOs cookie store and ignore
> > QtNetwork's.
> > 
> > 'Allan
> 
> The problem is that I can't find any documentation on how to interact with
> KIO's cookie store. On KIO::AccessManager, it is stated: "IMPORTANT This
> class is not a replacement for the standard KDE API. It should ONLY be used
> to provide KDE integration in applications that cannot use the standard KDE
> API directly". Unfortunately, it doesn't mention which is the standard KDE
> API. Looking at accessmanager.cpp, I see (in the code for
> KIO::Integration::CookieJar) DBUS calls to the "org.kde.cookiejar5"
> interface. Is this the "standard KDE API"? If so, is there a place where
> it's documented? I think I already tried to use it to solve this problem,
> but without success. However, tomorrow I'll give it another try.
> 
I am not sure how well it is documented, but yes, it is essentially a DBUS api 
in background, because the cookie-jar runs in a separate process. Perhaps you 
can find some help by looking into the kdewebkit code that bridged KIO with 
QNAM (since QtWebKit used QNAM).

See for instance https://api.kde.org/frameworks/kio/html/
classKIO_1_1CookieJar.html
It seems to be a QtNetwork compatible inferface for the KIO cookie jar. Though 
the native API here might work too:
https://api.kde.org/4.x-api/kdelibs-apidocs/kio/html/
classKIO_1_1Integration_1_1CookieJar.html

I just noticed Google is still picking up the KDE 4 documentation. We had 
similar problems with Qt4 vs Qt5. Where are the kf documenation hosted?

'Allan

'Allan


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic