1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 09:32:12 +01:00

Update to latest Qt 5.6 QtWebEngine

This commit is contained in:
David Rosca 2016-01-30 11:41:39 +01:00
parent 06b2414d80
commit 960a46daef
3 changed files with 34 additions and 19 deletions

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* QupZilla - WebKit based browser * QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com> * Copyright (C) 2010-2016 David Rosca <nowrep@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -34,13 +34,10 @@ CookieJar::CookieJar(QObject* parent)
, m_client(mApp->webProfile()->cookieStore()) , m_client(mApp->webProfile()->cookieStore())
{ {
loadSettings(); loadSettings();
m_client->loadAllCookies();
connect(m_client, &QWebEngineCookieStore::cookieAdded, this, &CookieJar::cookieAdded); connect(m_client, &QWebEngineCookieStore::cookieAdded, this, &CookieJar::slotCookieAdded);
connect(m_client, &QWebEngineCookieStore::cookieRemoved, this, &CookieJar::cookieRemoved); connect(m_client, &QWebEngineCookieStore::cookieRemoved, this, &CookieJar::slotCookieRemoved);
m_client->setCookieFilter([this](QWebEngineCookieStore::FilterRequest &req) {
req.accepted = acceptCookie(req.firstPartyUrl, req.cookieLine, req.cookieSource);
});
} }
void CookieJar::loadSettings() void CookieJar::loadSettings()
@ -60,9 +57,9 @@ void CookieJar::setAllowCookies(bool allow)
m_allowCookies = allow; m_allowCookies = allow;
} }
void CookieJar::getAllCookies(const QWebEngineCallback<const QByteArray &> callback) QVector<QNetworkCookie> CookieJar::getAllCookies() const
{ {
m_client->getAllCookies(callback); return m_cookies;
} }
void CookieJar::deleteAllCookies() void CookieJar::deleteAllCookies()
@ -97,6 +94,23 @@ bool CookieJar::listMatchesDomain(const QStringList &list, const QString &cookie
return false; return false;
} }
void CookieJar::slotCookieAdded(const QNetworkCookie &cookie)
{
if (rejectCookie(QString(), cookie, cookie.domain())) {
m_client->deleteCookie(cookie);
return;
}
m_cookies.append(cookie);
emit cookieAdded(cookie);
}
void CookieJar::slotCookieRemoved(const QNetworkCookie &cookie)
{
if (m_cookies.removeOne(cookie))
emit cookieRemoved(cookie);
}
bool CookieJar::acceptCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &cookieSource) const bool CookieJar::acceptCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &cookieSource) const
{ {
const QList<QNetworkCookie> cookies = QNetworkCookie::parseCookies(cookieLine); const QList<QNetworkCookie> cookies = QNetworkCookie::parseCookies(cookieLine);

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* QupZilla - WebKit based browser * QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com> * Copyright (C) 2010-2016 David Rosca <nowrep@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -18,7 +18,7 @@
#ifndef COOKIEJAR_H #ifndef COOKIEJAR_H
#define COOKIEJAR_H #define COOKIEJAR_H
#include <QFile> #include <QVector>
#include <QStringList> #include <QStringList>
#include <QWebEngineCookieStore> #include <QWebEngineCookieStore>
@ -37,7 +37,7 @@ public:
void setAllowCookies(bool allow); void setAllowCookies(bool allow);
void getAllCookies(const QWebEngineCallback<const QByteArray&> callback); QVector<QNetworkCookie> getAllCookies() const;
void deleteAllCookies(); void deleteAllCookies();
signals: signals:
@ -49,6 +49,9 @@ protected:
bool listMatchesDomain(const QStringList &list, const QString &cookieDomain) const; bool listMatchesDomain(const QStringList &list, const QString &cookieDomain) const;
private: private:
void slotCookieAdded(const QNetworkCookie &cookie);
void slotCookieRemoved(const QNetworkCookie &cookie);
bool acceptCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &cookieSource) const; bool acceptCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &cookieSource) const;
bool rejectCookie(const QString &domain, const QNetworkCookie &cookie, const QString &cookieDomain) const; bool rejectCookie(const QString &domain, const QNetworkCookie &cookie, const QString &cookieDomain) const;
@ -58,7 +61,9 @@ private:
QStringList m_whitelist; QStringList m_whitelist;
QStringList m_blacklist; QStringList m_blacklist;
QWebEngineCookieStore *m_client; QWebEngineCookieStore *m_client;
QVector<QNetworkCookie> m_cookies;
}; };
#endif // COOKIEJAR_H #endif // COOKIEJAR_H

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* QupZilla - WebKit based browser * QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com> * Copyright (C) 2010-2016 David Rosca <nowrep@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -88,12 +88,8 @@ CookieManager::CookieManager()
connect(mApp->cookieJar(), &CookieJar::cookieRemoved, this, &CookieManager::removeCookie); connect(mApp->cookieJar(), &CookieJar::cookieRemoved, this, &CookieManager::removeCookie);
// Load cookies // Load cookies
mApp->cookieJar()->getAllCookies([this](const QByteArray &res) { foreach (const QNetworkCookie &cookie, mApp->cookieJar()->getAllCookies())
const QList<QNetworkCookie> &allCookies = QNetworkCookie::parseCookies(res);
foreach (const QNetworkCookie &cookie, allCookies) {
addCookie(cookie); addCookie(cookie);
}
});
QzTools::setWmClass("Cookies", this); QzTools::setWmClass("Cookies", this);
} }