From 26e2926d5424f0c248892b4755c699541d46e856 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 15 Feb 2020 14:53:56 +0200 Subject: Remove ProfileInterface Plugins should define their own specific interfaces rather than subclassing from ProfileInterface: - add Filter for QWebEngineUrlRequestInterceptor filters - add FilterPlugin for Filter loading Remove deprecated Browser::profileList() --- include/filterinterface.h | 36 +++++++++++++++++++ include/meson.build | 6 ++++ include/plugininterface.h | 2 +- include/profileinterface.h | 84 -------------------------------------------- meson.build | 18 +++++----- src/browser.cpp | 9 ----- src/browser.h | 5 ++- src/meson.build | 2 +- src/webengine/webprofile.cpp | 4 +-- src/webengine/webprofile.h | 31 ++++++++++++++-- 10 files changed, 87 insertions(+), 110 deletions(-) create mode 100644 include/filterinterface.h create mode 100644 include/meson.build delete mode 100644 include/profileinterface.h diff --git a/include/filterinterface.h b/include/filterinterface.h new file mode 100644 index 0000000..fb04e25 --- /dev/null +++ b/include/filterinterface.h @@ -0,0 +1,36 @@ +/* + * This file is part of smolbote. It's copyrighted by the contributors recorded + * in the version control history of the file, available from its original + * location: https://library.iserlohn-fortress.net/aqua/smolbote.git + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include +#include + +class Filter +{ +public: + virtual ~Filter() = default; + + virtual void filter(QWebEngineUrlRequestInfo &info) const = 0; + + virtual bool isUpToDate() const = 0; +}; + +// A class to provide filter interfaces +class QIODevice; +class FilterPlugin +{ +public: + virtual ~FilterPlugin() = default; + + virtual Filter* load(QIODevice* from) const = 0; +}; + +#define FilterPluginIid "net.iserlohn-fortress.smolbote.FilterPlugin" +Q_DECLARE_INTERFACE(FilterPlugin, FilterPluginIid) + diff --git a/include/meson.build b/include/meson.build new file mode 100644 index 0000000..c2bf758 --- /dev/null +++ b/include/meson.build @@ -0,0 +1,6 @@ +dep_plugininterface = declare_dependency( + include_directories: include_directories('.') +) + +plugininterface_include = include_directories('.') + diff --git a/include/plugininterface.h b/include/plugininterface.h index 6da417c..4c36d8a 100644 --- a/include/plugininterface.h +++ b/include/plugininterface.h @@ -1,7 +1,7 @@ /* * This file is part of smolbote. It's copyrighted by the contributors recorded * in the version control history of the file, available from its original - * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote + * location: https://library.iserlohn-fortress.net/aqua/smolbote.git * * SPDX-License-Identifier: MIT */ diff --git a/include/profileinterface.h b/include/profileinterface.h deleted file mode 100644 index e25b085..0000000 --- a/include/profileinterface.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * This file is part of smolbote. It's copyrighted by the contributors recorded - * in the version control history of the file, available from its original - * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote - * - * SPDX-License-Identifier: MIT - */ - -#pragma once - -#include -#include -#include -#include -#include - -class Profile : public QWebEngineProfile -{ - Q_OBJECT - - 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) - Q_PROPERTY(QUrl newtab READ newtab WRITE setNewtab NOTIFY newtabChanged) - - // QWebEngineProfile should-be properties - Q_PROPERTY(QString cachePath READ cachePath WRITE setCachePath NOTIFY propertyChanged) - Q_PROPERTY(QString persistentStoragePath READ persistentStoragePath WRITE setPersistentStoragePath NOTIFY propertyChanged) - Q_PROPERTY(int persistentCookiesPolicy READ persistentCookiesPolicy WRITE setPersistentCookiesPolicy NOTIFY propertyChanged) - - Q_PROPERTY(QString httpAcceptLanguage READ httpAcceptLanguage WRITE setHttpAcceptLanguage NOTIFY propertyChanged) - Q_PROPERTY(int httpCacheMaximumSize READ httpCacheMaximumSize WRITE setHttpCacheMaximumSize NOTIFY propertyChanged) - Q_PROPERTY(int httpCacheType READ httpCacheType WRITE setHttpCacheType NOTIFY propertyChanged) - Q_PROPERTY(QString httpUserAgent READ httpUserAgent WRITE setHttpUserAgent NOTIFY propertyChanged) - - Q_PROPERTY(bool spellCheckEnabled READ isSpellCheckEnabled WRITE setSpellCheckEnabled NOTIFY propertyChanged) - -protected: - explicit Profile(QObject *parent = nullptr) : QWebEngineProfile(parent) {} - explicit Profile(const QString &storageName, QObject *parent = nullptr) : QWebEngineProfile(storageName, parent) {} - -public: - virtual const QString name() const = 0; - virtual void setName(const QString &name) = 0; - - virtual const QVector cookies() const = 0; - virtual const QMap headers() const = 0; - - // search url - virtual QString search() const = 0; - virtual void setSearch(const QString &url) = 0; - - // homepage url - virtual QUrl homepage() const = 0; - virtual void setHomepage(const QUrl &url) = 0; - - // new tab url - virtual QUrl newtab() const = 0; - virtual void setNewtab(const QUrl &url) = 0; - - virtual void setCachePath(const QString &path) = 0; - virtual void setPersistentStoragePath(const QString &path) = 0; - virtual void setPersistentCookiesPolicy(int policy) = 0; - - virtual void setHttpAcceptLanguage(const QString &httpAcceptLanguage) = 0; - virtual void setHttpCacheMaximumSize(int maxSize) = 0; - virtual void setHttpCacheType(int type) = 0; - virtual void setHttpUserAgent(const QString &userAgent) = 0; - virtual void setHttpHeader(const QString &name, const QString &value) = 0; - virtual void removeHttpHeader(const QString &name) = 0; - - virtual void setSpellCheckEnabled(bool enable) = 0; - -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(const QWebEngineSettings::WebAttribute attribute, const bool value); - void headerChanged(const QString &name, const QString &value); - void headerRemoved(const QString &name); -}; diff --git a/meson.build b/meson.build index 5e10db7..3424554 100644 --- a/meson.build +++ b/meson.build @@ -31,7 +31,6 @@ add_project_arguments(cxx.get_supported_arguments([ '-ffunction-sections', # Place each function into its own section, better ASLR but larger executables '-fstack-protector-all', # Emit code to check for buffer overflows on all functions '-fstack-clash-protection', # Emit code to check for stack clash attacks - '-flto=4', '-mspeculative-load-hardening', # Spectre v1 mitigation @@ -41,9 +40,15 @@ add_project_arguments(cxx.get_supported_arguments([ '-Wold-style-cast' ]), language: 'cpp') +if get_option('buildtype') == 'release' + add_project_arguments(cxx.get_supported_arguments([ + '-flto=4', + ]), language: 'cpp') +endif + mod_qt5 = import('qt5') dep_qt5 = dependency('qt5', - modules: ['Core', 'Network', 'Widgets', 'WebEngineWidgets', 'Concurrent'], + modules: ['Core', 'Network', 'Widgets', 'WebEngineWidgets', 'Concurrent', 'Test'], include_type: 'system' ) @@ -63,13 +68,10 @@ dep_gtest = dependency('gtest', required: false, disabler: true) # Generate config header include = include_directories('include') -interfaces_moc = mod_qt5.preprocess( - moc_headers: 'include/profileinterface.h', - dependencies: dep_qt5 -) - poi_sourceset = sourceset.source_set() +subdir('include') # plugin interaces + subdir('lib/about') subdir('lib/bookmarks') subdir('lib/configuration') @@ -97,7 +99,7 @@ poi_exe = executable(get_option('poi'), cpp_args: ['-DQAPPLICATION_CLASS=QApplication', poi_cpp_args], sources: [ssconfig.sources()], include_directories: [include, include_directories('src')], - dependencies: [dep_qt5, dep_spdlog, dep_SingleApplication, dep_args, optional_deps, dep_about, dep_bookmarks, dep_configuration, dep_downloads, dep_pluginloader, dep_urlfilter, ssconfig.dependencies()], + dependencies: [ dep_qt5, dep_spdlog, dep_SingleApplication, dep_args, optional_deps, dep_about, dep_bookmarks, dep_configuration, dep_downloads, dep_pluginloader, dep_urlfilter, dep_plugininterface, ssconfig.dependencies() ], install: true, ) diff --git a/src/browser.cpp b/src/browser.cpp index 3b47048..02d5bc9 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -89,15 +89,6 @@ void Browser::about() dlg->exec(); } -const QList> Browser::profileList() const -{ - QList> profiles; - for(const QString &id : m_profileManager->idList()) { - profiles.append(qMakePair(id, m_profileManager->profile(id))); - } - return profiles; -} - void Browser::loadProfiles(const QStringList &profilePaths) { Configuration conf; diff --git a/src/browser.h b/src/browser.h index ec6bb57..646d57e 100644 --- a/src/browser.h +++ b/src/browser.h @@ -23,9 +23,9 @@ class Configuration; class BookmarksWidget; class DownloadsWidget; class MainWindow; -class Profile; +class WebProfile; class WebProfileManager; -class Browser : public SingleApplication +class Browser final : public SingleApplication { Q_OBJECT @@ -38,7 +38,6 @@ public slots: public: // interface - [[deprecated]] const QList> profileList() const; void loadProfiles(const QStringList &profilePaths); void loadPlugins( const QStringList &paths, diff --git a/src/meson.build b/src/meson.build index 12c41c8..edc9db4 100644 --- a/src/meson.build +++ b/src/meson.build @@ -57,7 +57,7 @@ poi_sourceset.add(files( 'wallet/wallet.cpp', 'wallet/wallet.h' ), - interfaces_moc, version_h, poi_settings_h + version_h, poi_settings_h ) poi_sourceset.add(when: [dep_breakpad, dep_threads], diff --git a/src/webengine/webprofile.cpp b/src/webengine/webprofile.cpp index 2cea409..5224189 100644 --- a/src/webengine/webprofile.cpp +++ b/src/webengine/webprofile.cpp @@ -26,7 +26,7 @@ WebProfile *WebProfile::defaultProfile() } WebProfile::WebProfile(const QString &name, QObject *parent) - : Profile(parent) + : QWebEngineProfile(parent) { m_name = name; @@ -39,7 +39,7 @@ WebProfile::WebProfile(const QString &name, QObject *parent) } WebProfile::WebProfile(const QString &storageName, const QString &name, QObject *parent) - : Profile(storageName, parent) + : QWebEngineProfile(storageName, parent) { m_name = name; diff --git a/src/webengine/webprofile.h b/src/webengine/webprofile.h index 1ec2b88..66154af 100644 --- a/src/webengine/webprofile.h +++ b/src/webengine/webprofile.h @@ -17,15 +17,31 @@ #include #include #include -#include class WebProfileManager; -class WebProfile : public Profile +class WebProfile : public QWebEngineProfile { friend class WebProfileManager; Q_OBJECT + 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) + Q_PROPERTY(QUrl newtab READ newtab WRITE setNewtab NOTIFY newtabChanged) + + // QWebEngineProfile should-be properties + Q_PROPERTY(QString cachePath READ cachePath WRITE setCachePath NOTIFY propertyChanged) + Q_PROPERTY(QString persistentStoragePath READ persistentStoragePath WRITE setPersistentStoragePath NOTIFY propertyChanged) + Q_PROPERTY(int persistentCookiesPolicy READ persistentCookiesPolicy WRITE setPersistentCookiesPolicy NOTIFY propertyChanged) + + Q_PROPERTY(QString httpAcceptLanguage READ httpAcceptLanguage WRITE setHttpAcceptLanguage NOTIFY propertyChanged) + Q_PROPERTY(int httpCacheMaximumSize READ httpCacheMaximumSize WRITE setHttpCacheMaximumSize NOTIFY propertyChanged) + Q_PROPERTY(int httpCacheType READ httpCacheType WRITE setHttpCacheType NOTIFY propertyChanged) + Q_PROPERTY(QString httpUserAgent READ httpUserAgent WRITE setHttpUserAgent NOTIFY propertyChanged) + + Q_PROPERTY(bool spellCheckEnabled READ isSpellCheckEnabled WRITE setSpellCheckEnabled NOTIFY propertyChanged) + public: static WebProfile *defaultProfile(); static void setDefaultProfile(WebProfile *profile); @@ -69,6 +85,17 @@ public: void setSpellCheckEnabled(bool enable); +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(const QWebEngineSettings::WebAttribute attribute, const bool value); + void headerChanged(const QString &name, const QString &value); + void headerRemoved(const QString &name); + protected: // off-the-record constructor explicit WebProfile(const QString &name, QObject *parent = nullptr); -- cgit v1.2.1