aboutsummaryrefslogtreecommitdiff
path: root/src/webengine/webprofile.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/webengine/webprofile.h')
-rw-r--r--src/webengine/webprofile.h62
1 files changed, 53 insertions, 9 deletions
diff --git a/src/webengine/webprofile.h b/src/webengine/webprofile.h
index 180cc9d..0747638 100644
--- a/src/webengine/webprofile.h
+++ b/src/webengine/webprofile.h
@@ -11,13 +11,14 @@
#include <QMap>
#include <QNetworkCookie>
+#include <QSettings>
#include <QString>
#include <QUrl>
+#include <QVariant>
#include <QVector>
+#include <QWebEngineCookieStore>
#include <QWebEngineProfile>
#include <QWebEngineSettings>
-#include <QVariant>
-#include <QSettings>
class UrlRequestInterceptor;
class WebProfile : public QWebEngineProfile
@@ -44,6 +45,10 @@ class WebProfile : public QWebEngineProfile
Q_PROPERTY(bool spellCheckEnabled READ isSpellCheckEnabled WRITE setSpellCheckEnabled NOTIFY propertyChanged)
+ // more custom properties
+ Q_PROPERTY(QList<QVariant> cookies READ cookies WRITE setCookies NOTIFY cookiesChanged)
+ Q_PROPERTY(QMap<QString, QVariant> headers READ headers WRITE setHeaders NOTIFY headersChanged)
+
signals:
void nameChanged(const QString &name);
void searchChanged(const QString &url);
@@ -52,6 +57,9 @@ signals:
void propertyChanged(const QString &name, const QVariant &value);
void attributeChanged(QWebEngineSettings::WebAttribute attribute, bool value);
+
+ void cookiesChanged();
+ void headersChanged();
void headerChanged(const QString &name, const QString &value);
void headerRemoved(const QString &name);
@@ -60,9 +68,9 @@ public:
[[nodiscard]] static WebProfile *load(const QString &id, QSettings *settings, bool isOffTheRecord = true);
WebProfile(const WebProfile &) = delete;
- WebProfile& operator=(const WebProfile &) = delete;
+ WebProfile &operator=(const WebProfile &) = delete;
WebProfile(WebProfile &&) = delete;
- WebProfile& operator=(WebProfile &&) = delete;
+ WebProfile &operator=(WebProfile &&) = delete;
static WebProfile *defaultProfile();
static void setDefaultProfile(WebProfile *profile);
@@ -83,9 +91,13 @@ public:
emit nameChanged(name);
}
- [[nodiscard]] QVector<QNetworkCookie> cookies() const
+ [[nodiscard]] QList<QVariant> cookies() const
{
- return qAsConst(m_cookies);
+ QList<QVariant> r;
+ for(const auto &cookie : m_cookies) {
+ r.append(cookie.toRawForm());
+ }
+ return r;
}
[[nodiscard]] QString search() const
@@ -166,7 +178,16 @@ public:
emit headerRemoved(name);
}
}
-
+ [[nodiscard]] QMap<QString, QVariant> headers() const
+ {
+ QMap<QString, QVariant> r;
+ auto it = m_headers.constBegin();
+ while(it != m_headers.constEnd()) {
+ r.insert(QString(it.key()), QVariant(it.value()));
+ ++it;
+ }
+ return r;
+ }
void setSpellCheckEnabled(bool enable)
{
QWebEngineProfile::setSpellCheckEnabled(enable);
@@ -178,6 +199,29 @@ public:
m_filters.append(interceptor);
}
+public slots:
+ void setCookies(const QList<QVariant> &cookies)
+ {
+ auto *store = cookieStore();
+ store->deleteAllCookies();
+ for(const auto &data : cookies) {
+ for(const auto &cookie : QNetworkCookie::parseCookies(data.toByteArray())) {
+ store->setCookie(cookie);
+ }
+ }
+ emit cookiesChanged();
+ }
+ void setHeaders(const QMap<QString, QVariant> &headers)
+ {
+ m_headers.clear();
+ auto it = headers.constBegin();
+ while(it != headers.constEnd()) {
+ m_headers.insert(it.key().toLatin1(), it.value().toByteArray());
+ ++it;
+ }
+ emit headersChanged();
+ }
+
protected:
// off-the-record constructor
explicit WebProfile(const QString &id, QObject *parent = nullptr);
@@ -190,8 +234,8 @@ protected:
QUrl m_homepage = QUrl("about:blank");
QUrl m_newtab = QUrl("about:blank");
- QVector<QWebEngineUrlRequestInterceptor*> m_filters;
- QVector<QNetworkCookie> m_cookies;
+ QVector<QWebEngineUrlRequestInterceptor *> m_filters;
+ QList<QNetworkCookie> m_cookies;
QMap<QByteArray, QByteArray> m_headers;
};