From e87693c54ca97ed3a6ed25f9eaae8ab223fc18b1 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 29 Apr 2020 18:49:07 +0300 Subject: libwebengine Make src/webengine into a static library - Add some tests - Updated manpage - Remove WebProfileManager::id and WebProfileManager::instance - Add consumable semantics checks to WebProfileManager - Add WebProfileManager::walk Add ApplicationMenu class --- src/webengine/webprofile.h | 167 +++++++++++++++++++++++++++++++++------------ 1 file changed, 125 insertions(+), 42 deletions(-) (limited to 'src/webengine/webprofile.h') diff --git a/src/webengine/webprofile.h b/src/webengine/webprofile.h index 66154af..180cc9d 100644 --- a/src/webengine/webprofile.h +++ b/src/webengine/webprofile.h @@ -9,7 +9,6 @@ #ifndef SMOLBOTE_WEBENGINEPROFILE_H #define SMOLBOTE_WEBENGINEPROFILE_H -#include #include #include #include @@ -17,14 +16,17 @@ #include #include #include +#include +#include -class WebProfileManager; +class UrlRequestInterceptor; class WebProfile : public QWebEngineProfile { - friend class WebProfileManager; + friend class UrlRequestInterceptor; Q_OBJECT + Q_PROPERTY(QString id READ getId CONSTANT) Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(QString search READ search WRITE setSearch NOTIFY searchChanged) Q_PROPERTY(QUrl homepage READ homepage WRITE setHomepage NOTIFY homepageChanged) @@ -42,72 +44,153 @@ class WebProfile : public QWebEngineProfile Q_PROPERTY(bool spellCheckEnabled READ isSpellCheckEnabled WRITE setSpellCheckEnabled NOTIFY propertyChanged) +signals: + void nameChanged(const QString &name); + void searchChanged(const QString &url); + void homepageChanged(const QUrl &url); + void newtabChanged(const QUrl &url); + + void propertyChanged(const QString &name, const QVariant &value); + void attributeChanged(QWebEngineSettings::WebAttribute attribute, bool value); + void headerChanged(const QString &name, const QString &value); + void headerRemoved(const QString &name); + public: + [[nodiscard]] static QSettings *load(const QString &path, const QString &search = QString(), const QUrl &homepage = QUrl(), const QUrl &newtab = QUrl()); + [[nodiscard]] static WebProfile *load(const QString &id, QSettings *settings, bool isOffTheRecord = true); + + WebProfile(const WebProfile &) = delete; + WebProfile& operator=(const WebProfile &) = delete; + WebProfile(WebProfile &&) = delete; + WebProfile& operator=(WebProfile &&) = delete; + static WebProfile *defaultProfile(); static void setDefaultProfile(WebProfile *profile); - ~WebProfile() = default; + ~WebProfile() override = default; - const QString name() const; - void setName(const QString &name); - - const QVector cookies() const + [[nodiscard]] QString getId() const { - return qAsConst(m_cookies); + return m_id; + } + [[nodiscard]] QString name() const + { + return m_name; } - const QMap headers() const + void setName(const QString &name) { - return qAsConst(m_headers); + m_name = name; + emit nameChanged(name); } - // search url - QString search() const; - void setSearch(const QString &url); + [[nodiscard]] QVector cookies() const + { + return qAsConst(m_cookies); + } - // homepage url - QUrl homepage() const; - void setHomepage(const QUrl &url); + [[nodiscard]] QString search() const + { + return m_search; + } + void setSearch(const QString &url) + { + m_search = url; + emit searchChanged(m_search); + } - // new tab url - QUrl newtab() const; - void setNewtab(const QUrl &url); + [[nodiscard]] QUrl homepage() const + { + return m_homepage; + } + void setHomepage(const QUrl &url) + { + m_homepage = url; + emit homepageChanged(m_homepage); + } - void setCachePath(const QString &path); - void setPersistentStoragePath(const QString &path); - void setPersistentCookiesPolicy(int policy); + [[nodiscard]] QUrl newtab() const + { + return m_newtab; + } + void setNewtab(const QUrl &url) + { + m_newtab = url; + emit newtabChanged(m_newtab); + } - void setHttpAcceptLanguage(const QString &httpAcceptLanguage); - void setHttpCacheMaximumSize(int maxSize); - void setHttpCacheType(int type); - void setHttpUserAgent(const QString &userAgent); - void setHttpHeader(const QString &name, const QString &value); - void removeHttpHeader(const QString &name); + void setCachePath(const QString &path) + { + QWebEngineProfile::setCachePath(path); + emit propertyChanged("cachePath", path); + } + void setPersistentStoragePath(const QString &path) + { + QWebEngineProfile::setPersistentStoragePath(path); + emit propertyChanged("persistentStoragePath", path); + } + void setPersistentCookiesPolicy(int policy) + { + QWebEngineProfile::setPersistentCookiesPolicy(static_cast(policy)); + emit propertyChanged("persistentCookiesPolicy", policy); + } - void setSpellCheckEnabled(bool enable); + void setHttpAcceptLanguage(const QString &httpAcceptLanguage) + { + QWebEngineProfile::setHttpAcceptLanguage(httpAcceptLanguage); + emit propertyChanged("httpAcceptLanguage", httpAcceptLanguage); + } + void setHttpCacheMaximumSize(int maxSize) + { + QWebEngineProfile::setHttpCacheMaximumSize(maxSize); + emit propertyChanged("httpCacheMaximumSize", maxSize); + } + void setHttpCacheType(int type) + { + QWebEngineProfile::setHttpCacheType(static_cast(type)); + emit propertyChanged("httpCacheType", type); + } + void setHttpUserAgent(const QString &userAgent) + { + QWebEngineProfile::setHttpUserAgent(userAgent); + emit propertyChanged("httpUserAgent", userAgent); + } + void setHttpHeader(const QString &name, const QString &value) + { + m_headers[name.toLatin1()] = value.toLatin1(); + emit headerChanged(name, value); + } + void removeHttpHeader(const QString &name) + { + if(m_headers.contains(name.toLatin1())) { + m_headers.remove(name.toLatin1()); + emit headerRemoved(name); + } + } -signals: - void nameChanged(const QString &name); - void searchChanged(const QString &url); - void homepageChanged(const QUrl &url); - void newtabChanged(const QUrl &url); + void setSpellCheckEnabled(bool enable) + { + QWebEngineProfile::setSpellCheckEnabled(enable); + emit propertyChanged("spellCheckEnabed", enable); + } - void propertyChanged(const QString &name, const QVariant &value); - void attributeChanged(const QWebEngineSettings::WebAttribute attribute, const bool value); - void headerChanged(const QString &name, const QString &value); - void headerRemoved(const QString &name); + void setUrlRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor) + { + m_filters.append(interceptor); + } protected: // off-the-record constructor - explicit WebProfile(const QString &name, QObject *parent = nullptr); + explicit WebProfile(const QString &id, QObject *parent = nullptr); // default constructor - explicit WebProfile(const QString &storageName, const QString &name, QObject *parent = nullptr); + explicit WebProfile(const QString &id, const QString &storageName, QObject *parent = nullptr); -private: + const QString m_id; QString m_name; QString m_search = QString("about:blank"); QUrl m_homepage = QUrl("about:blank"); QUrl m_newtab = QUrl("about:blank"); + QVector m_filters; QVector m_cookies; QMap m_headers; }; -- cgit v1.2.1