summaryrefslogtreecommitdiffstats
path: root/framework/src/webengineprofile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/webengineprofile.cpp')
-rw-r--r--framework/src/webengineprofile.cpp52
1 files changed, 52 insertions, 0 deletions
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 @@
1
2/*
3 Copyright (c) 2017 Christian Mollekopf <mollekopf@kolabsys.com>
4
5 This library is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Library General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or (at your
8 option) any later version.
9
10 This library is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301, USA.
19*/
20
21#include "webengineprofile.h"
22
23#include <QWebEngineUrlRequestInterceptor>
24#include <QDebug>
25#include <QDesktopServices>
26
27class WebUrlRequestInterceptor : public QWebEngineUrlRequestInterceptor
28{
29 Q_OBJECT
30public:
31 WebUrlRequestInterceptor(QObject *p = Q_NULLPTR) : QWebEngineUrlRequestInterceptor{p}
32 {}
33
34 void interceptRequest(QWebEngineUrlRequestInfo &info) Q_DECL_OVERRIDE
35 {
36 qDebug() << info.requestMethod() << info.requestUrl() << info.resourceType() << info.navigationType();
37 const bool isNavigationRequest = info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame;
38 if (isNavigationRequest) {
39 QDesktopServices::openUrl(info.requestUrl());
40 info.block(true);
41 }
42 //TODO handle mailto to open a composer
43 }
44};
45
46WebEngineProfile::WebEngineProfile(QObject *parent)
47 : QQuickWebEngineProfile(parent)
48{
49 setRequestInterceptor(new WebUrlRequestInterceptor(this));
50}
51
52#include "webengineprofile.moc"