From dfa1c2dab99115a1ad97f4e2e93ac07e2d0705fd Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 22 Aug 2017 20:19:53 -0600 Subject: Install the webengineprofile as singleton This fixes the bug that the main process would hang on exit as long as we have a requestinterceptor installed. It's most likely a bug that this does not work, but the new solution anyways cleans up the code a bit, so that's a nice sideeffect. Fixes T5570 --- applications/kube/main.cpp | 42 +++++++++--------- components/mailviewer/contents/ui/HtmlContent.qml | 3 ++ framework/src/CMakeLists.txt | 4 +- framework/src/frameworkplugin.cpp | 9 ++++ framework/src/webengineprofile.cpp | 52 +++++++++++++++++++++++ framework/src/webengineprofile.h | 28 ++++++++++++ 6 files changed, 114 insertions(+), 24 deletions(-) create mode 100644 framework/src/webengineprofile.cpp create mode 100644 framework/src/webengineprofile.h diff --git a/applications/kube/main.cpp b/applications/kube/main.cpp index ad7bac88..115e7b0d 100644 --- a/applications/kube/main.cpp +++ b/applications/kube/main.cpp @@ -1,3 +1,22 @@ +/* + Copyright (c) 2017 Christian Mollekopf + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + #include #include @@ -6,7 +25,6 @@ #include #include #include -#include #include @@ -48,32 +66,11 @@ public: } }; -class WebUrlRequestInterceptor : public QWebEngineUrlRequestInterceptor -{ - Q_OBJECT -public: - WebUrlRequestInterceptor(QObject *p = Q_NULLPTR) : QWebEngineUrlRequestInterceptor{p} - {} - - void interceptRequest(QWebEngineUrlRequestInfo &info) - { - qDebug() << info.requestMethod() << info.requestUrl() << info.resourceType() << info.navigationType(); - const bool isNavigationRequest = info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame; - if (isNavigationRequest) { - QDesktopServices::openUrl(info.requestUrl()); - info.block(true); - } - //TODO handle mailto to open a composer - } -}; - int main(int argc, char *argv[]) { QApplication app(argc, argv); QtWebEngine::initialize(); - WebUrlRequestInterceptor *wuri = new WebUrlRequestInterceptor(); - QQuickWebEngineProfile::defaultProfile()->setRequestInterceptor(wuri); QIcon::setThemeName("kube"); auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.components.kube"); @@ -84,4 +81,3 @@ int main(int argc, char *argv[]) return app.exec(); } -#include "main.moc" diff --git a/components/mailviewer/contents/ui/HtmlContent.qml b/components/mailviewer/contents/ui/HtmlContent.qml index f864ad02..946bbe37 100644 --- a/components/mailviewer/contents/ui/HtmlContent.qml +++ b/components/mailviewer/contents/ui/HtmlContent.qml @@ -21,6 +21,8 @@ import QtQuick.Controls 1.3 //TODO import QtWebEngine 1.4 import QtWebEngine 1.3 +import org.kube.framework 1.0 as Kube + Item { id: root property string content @@ -66,6 +68,7 @@ Item { autoLoadIconsForPage: false accelerated2dCanvasEnabled: false } + profile: Kube.WebEngineProfile //TODO Disable the context menu (depends on webengine 1.4) // onContextMenuRequested: function(request) { // request.accepted = true diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt index 86145d5a..1ac9d3c2 100644 --- a/framework/src/CMakeLists.txt +++ b/framework/src/CMakeLists.txt @@ -1,5 +1,5 @@ -find_package(Qt5 COMPONENTS REQUIRED Core Concurrent Quick Qml WebEngineWidgets Test) +find_package(Qt5 COMPONENTS REQUIRED Core Concurrent Quick Qml WebEngineWidgets Test WebEngine) find_package(KF5Mime "4.87.0" CONFIG REQUIRED) find_package(Sink CONFIG REQUIRED) find_package(KAsync CONFIG REQUIRED) @@ -43,6 +43,7 @@ set(SRCS kubeimage.cpp clipboardproxy.cpp krecursivefilterproxymodel.cpp + webengineprofile.cpp ) add_library(frameworkplugin SHARED ${SRCS}) @@ -54,6 +55,7 @@ target_link_libraries(frameworkplugin Qt5::Qml Qt5::WebEngineWidgets Qt5::Test + Qt5::WebEngine KF5::Codecs KF5::Contacts KF5::Package diff --git a/framework/src/frameworkplugin.cpp b/framework/src/frameworkplugin.cpp index 33bc8cbc..f5cd2cf5 100644 --- a/framework/src/frameworkplugin.cpp +++ b/framework/src/frameworkplugin.cpp @@ -35,6 +35,7 @@ #include "fabric.h" #include "kubeimage.h" #include "clipboardproxy.h" +#include "webengineprofile.h" #include @@ -45,6 +46,13 @@ static QObject *fabric_singletontype_provider(QQmlEngine *engine, QJSEngine *scr return new Kube::Fabric::Fabric; } +static QObject *webengineprofile_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine) +{ + Q_UNUSED(engine) + Q_UNUSED(scriptEngine) + return new WebEngineProfile; +} + void FrameworkPlugin::registerTypes (const char *uri) { qmlRegisterType(uri, 1, 0, "FolderListModel"); @@ -67,4 +75,5 @@ void FrameworkPlugin::registerTypes (const char *uri) qmlRegisterType(uri, 1, 0, "KubeImage"); qmlRegisterType(uri, 1, 0, "Clipboard"); + qmlRegisterSingletonType(uri, 1, 0, "WebEngineProfile", webengineprofile_singletontype_provider); } diff --git a/framework/src/webengineprofile.cpp b/framework/src/webengineprofile.cpp new file mode 100644 index 00000000..d63bacb3 --- /dev/null +++ b/framework/src/webengineprofile.cpp @@ -0,0 +1,52 @@ + +/* + Copyright (c) 2017 Christian Mollekopf + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#include "webengineprofile.h" + +#include +#include +#include + +class WebUrlRequestInterceptor : public QWebEngineUrlRequestInterceptor +{ + Q_OBJECT +public: + WebUrlRequestInterceptor(QObject *p = Q_NULLPTR) : QWebEngineUrlRequestInterceptor{p} + {} + + void interceptRequest(QWebEngineUrlRequestInfo &info) Q_DECL_OVERRIDE + { + qDebug() << info.requestMethod() << info.requestUrl() << info.resourceType() << info.navigationType(); + const bool isNavigationRequest = info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame; + if (isNavigationRequest) { + QDesktopServices::openUrl(info.requestUrl()); + info.block(true); + } + //TODO handle mailto to open a composer + } +}; + +WebEngineProfile::WebEngineProfile(QObject *parent) + : QQuickWebEngineProfile(parent) +{ + setRequestInterceptor(new WebUrlRequestInterceptor(this)); +} + +#include "webengineprofile.moc" diff --git a/framework/src/webengineprofile.h b/framework/src/webengineprofile.h new file mode 100644 index 00000000..16cea88b --- /dev/null +++ b/framework/src/webengineprofile.h @@ -0,0 +1,28 @@ +/* + Copyright (c) 2017 Christian Mollekopf + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#include + +class WebEngineProfile : public QQuickWebEngineProfile +{ + Q_OBJECT +public: + WebEngineProfile(QObject *parent = nullptr); +}; + -- cgit v1.2.3