Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 686842
Collapse All | Expand All

(-)a/messageviewer/src/viewer/webengine/mailwebenginepage.cpp (-10 lines)
Lines 1-81 Link Here
1
/*
1
/*
2
   Copyright (C) 2016-2018 Laurent Montel <montel@kde.org>
2
   Copyright (C) 2016-2018 Laurent Montel <montel@kde.org>
3
3
4
   This library is free software; you can redistribute it and/or
4
   This library is free software; you can redistribute it and/or
5
   modify it under the terms of the GNU Library General Public
5
   modify it under the terms of the GNU Library General Public
6
   License as published by the Free Software Foundation; either
6
   License as published by the Free Software Foundation; either
7
   version 2 of the License, or (at your option) any later version.
7
   version 2 of the License, or (at your option) any later version.
8
8
9
   This library is distributed in the hope that it will be useful,
9
   This library is distributed in the hope that it will be useful,
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
   Library General Public License for more details.
12
   Library General Public License for more details.
13
13
14
   You should have received a copy of the GNU Library General Public License
14
   You should have received a copy of the GNU Library General Public License
15
   along with this library; see the file COPYING.LIB.  If not, write to
15
   along with this library; see the file COPYING.LIB.  If not, write to
16
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
   Boston, MA 02110-1301, USA.
17
   Boston, MA 02110-1301, USA.
18
*/
18
*/
19
#include "mailwebenginepage.h"
19
#include "mailwebenginepage.h"
20
#include <QFontDatabase>
20
#include <QFontDatabase>
21
#include <QWebEngineSettings>
21
#include <QWebEngineSettings>
22
#include <QWebEngineProfile>
22
#include <QWebEngineProfile>
23
23
24
using namespace MessageViewer;
24
using namespace MessageViewer;
25
25
26
MailWebEnginePage::MailWebEnginePage(QObject *parent)
26
MailWebEnginePage::MailWebEnginePage(QObject *parent)
27
    : WebEngineViewer::WebEnginePage(parent)
27
    : WebEngineViewer::WebEnginePage(parent)
28
{
28
{
29
    initialize();
29
    initialize();
30
}
30
}
31
31
32
MailWebEnginePage::MailWebEnginePage(QWebEngineProfile *profile, QObject *parent)
33
    : WebEngineViewer::WebEnginePage(profile, parent)
34
{
35
    initialize();
36
}
37
38
MailWebEnginePage::~MailWebEnginePage()
39
{
40
}
41
42
void MailWebEnginePage::initialize()
32
void MailWebEnginePage::initialize()
43
{
33
{
44
    settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
34
    settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
45
    settings()->setAttribute(QWebEngineSettings::PluginsEnabled, false);
35
    settings()->setAttribute(QWebEngineSettings::PluginsEnabled, false);
46
    settings()->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, false);
36
    settings()->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, false);
47
    settings()->setAttribute(QWebEngineSettings::JavascriptCanAccessClipboard, false);
37
    settings()->setAttribute(QWebEngineSettings::JavascriptCanAccessClipboard, false);
48
    settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, false);
38
    settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, false);
49
    settings()->setAttribute(QWebEngineSettings::XSSAuditingEnabled, false);
39
    settings()->setAttribute(QWebEngineSettings::XSSAuditingEnabled, false);
50
    settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, false);
40
    settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, false);
51
    settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, false);
41
    settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, false);
52
    settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, false);
42
    settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, false);
53
    settings()->setAttribute(QWebEngineSettings::HyperlinkAuditingEnabled, false);
43
    settings()->setAttribute(QWebEngineSettings::HyperlinkAuditingEnabled, false);
54
    settings()->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, false);
44
    settings()->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, false);
55
    settings()->setAttribute(QWebEngineSettings::WebGLEnabled, false);
45
    settings()->setAttribute(QWebEngineSettings::WebGLEnabled, false);
56
    settings()->setAttribute(QWebEngineSettings::AutoLoadIconsForPage, false);
46
    settings()->setAttribute(QWebEngineSettings::AutoLoadIconsForPage, false);
57
    settings()->setAttribute(QWebEngineSettings::Accelerated2dCanvasEnabled, false);
47
    settings()->setAttribute(QWebEngineSettings::Accelerated2dCanvasEnabled, false);
58
    settings()->setAttribute(QWebEngineSettings::WebGLEnabled, false);
48
    settings()->setAttribute(QWebEngineSettings::WebGLEnabled, false);
59
49
60
    settings()->setAttribute(QWebEngineSettings::FocusOnNavigationEnabled, false);
50
    settings()->setAttribute(QWebEngineSettings::FocusOnNavigationEnabled, false);
61
    settings()->setAttribute(QWebEngineSettings::AllowRunningInsecureContent, false);
51
    settings()->setAttribute(QWebEngineSettings::AllowRunningInsecureContent, false);
62
    profile()->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);
52
    profile()->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);
63
    profile()->setHttpCacheType(QWebEngineProfile::MemoryHttpCache);
53
    profile()->setHttpCacheType(QWebEngineProfile::MemoryHttpCache);
64
54
65
    const QFontInfo font(QFontDatabase().systemFont(QFontDatabase::GeneralFont));
55
    const QFontInfo font(QFontDatabase().systemFont(QFontDatabase::GeneralFont));
66
    settings()->setFontFamily(QWebEngineSettings::StandardFont, font.family());
56
    settings()->setFontFamily(QWebEngineSettings::StandardFont, font.family());
67
    settings()->setFontSize(QWebEngineSettings::DefaultFontSize, font.pixelSize());
57
    settings()->setFontSize(QWebEngineSettings::DefaultFontSize, font.pixelSize());
68
    connect(this, &QWebEnginePage::featurePermissionRequested,
58
    connect(this, &QWebEnginePage::featurePermissionRequested,
69
            this, &MailWebEnginePage::slotFeaturePermissionRequested);
59
            this, &MailWebEnginePage::slotFeaturePermissionRequested);
70
}
60
}
71
61
72
void MailWebEnginePage::setPrintElementBackground(bool printElementBackground)
62
void MailWebEnginePage::setPrintElementBackground(bool printElementBackground)
73
{
63
{
74
    settings()->setAttribute(QWebEngineSettings::PrintElementBackgrounds, printElementBackground);
64
    settings()->setAttribute(QWebEngineSettings::PrintElementBackgrounds, printElementBackground);
75
}
65
}
76
66
77
void MailWebEnginePage::slotFeaturePermissionRequested(const QUrl &url, QWebEnginePage::Feature feature)
67
void MailWebEnginePage::slotFeaturePermissionRequested(const QUrl &url, QWebEnginePage::Feature feature)
78
{
68
{
79
    //Denied all permissions.
69
    //Denied all permissions.
80
    setFeaturePermission(url, feature, QWebEnginePage::PermissionDeniedByUser);
70
    setFeaturePermission(url, feature, QWebEnginePage::PermissionDeniedByUser);
81
}
71
}
(-)a/messageviewer/src/viewer/webengine/mailwebenginepage.h (-2 / +1 lines)
Lines 1-41 Link Here
1
/*
1
/*
2
   Copyright (C) 2016-2018 Laurent Montel <montel@kde.org>
2
   Copyright (C) 2016-2018 Laurent Montel <montel@kde.org>
3
3
4
   This library is free software; you can redistribute it and/or
4
   This library is free software; you can redistribute it and/or
5
   modify it under the terms of the GNU Library General Public
5
   modify it under the terms of the GNU Library General Public
6
   License as published by the Free Software Foundation; either
6
   License as published by the Free Software Foundation; either
7
   version 2 of the License, or (at your option) any later version.
7
   version 2 of the License, or (at your option) any later version.
8
8
9
   This library is distributed in the hope that it will be useful,
9
   This library is distributed in the hope that it will be useful,
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
   Library General Public License for more details.
12
   Library General Public License for more details.
13
13
14
   You should have received a copy of the GNU Library General Public License
14
   You should have received a copy of the GNU Library General Public License
15
   along with this library; see the file COPYING.LIB.  If not, write to
15
   along with this library; see the file COPYING.LIB.  If not, write to
16
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
   Boston, MA 02110-1301, USA.
17
   Boston, MA 02110-1301, USA.
18
*/
18
*/
19
#ifndef MAILWEBENGINEPAGE_H
19
#ifndef MAILWEBENGINEPAGE_H
20
#define MAILWEBENGINEPAGE_H
20
#define MAILWEBENGINEPAGE_H
21
21
22
#include "messageviewer_export.h"
22
#include "messageviewer_export.h"
23
#include <WebEngineViewer/WebEnginePage>
23
#include <WebEngineViewer/WebEnginePage>
24
24
25
namespace MessageViewer {
25
namespace MessageViewer {
26
class MESSAGEVIEWER_EXPORT MailWebEnginePage : public WebEngineViewer::WebEnginePage
26
class MESSAGEVIEWER_EXPORT MailWebEnginePage : public WebEngineViewer::WebEnginePage
27
{
27
{
28
    Q_OBJECT
28
    Q_OBJECT
29
public:
29
public:
30
    explicit MailWebEnginePage(QObject *parent = nullptr);
30
    explicit MailWebEnginePage(QObject *parent = nullptr);
31
    explicit MailWebEnginePage(QWebEngineProfile *profile, QObject *parent = nullptr);
31
    virtual ~MailWebEnginePage() = default;
32
    ~MailWebEnginePage();
33
32
34
    void setPrintElementBackground(bool printElementBackground);
33
    void setPrintElementBackground(bool printElementBackground);
35
34
36
private:
35
private:
37
    void slotFeaturePermissionRequested(const QUrl &url, QWebEnginePage::Feature feature);
36
    void slotFeaturePermissionRequested(const QUrl &url, QWebEnginePage::Feature feature);
38
    void initialize();
37
    void initialize();
39
};
38
};
40
}
39
}
41
#endif // MAILWEBENGINEPAGE_H
40
#endif // MAILWEBENGINEPAGE_H
(-)a/messageviewer/src/viewer/webengine/mailwebengineview.cpp (-2 / +1 lines)
Lines 1-391 Link Here
1
/*
1
/*
2
   Copyright (C) 2016-2018 Laurent Montel <montel@kde.org>
2
   Copyright (C) 2016-2018 Laurent Montel <montel@kde.org>
3
3
4
   This library is free software; you can redistribute it and/or
4
   This library is free software; you can redistribute it and/or
5
   modify it under the terms of the GNU Library General Public
5
   modify it under the terms of the GNU Library General Public
6
   License as published by the Free Software Foundation; either
6
   License as published by the Free Software Foundation; either
7
   version 2 of the License, or (at your option) any later version.
7
   version 2 of the License, or (at your option) any later version.
8
8
9
   This library is distributed in the hope that it will be useful,
9
   This library is distributed in the hope that it will be useful,
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
   Library General Public License for more details.
12
   Library General Public License for more details.
13
13
14
   You should have received a copy of the GNU Library General Public License
14
   You should have received a copy of the GNU Library General Public License
15
   along with this library; see the file COPYING.LIB.  If not, write to
15
   along with this library; see the file COPYING.LIB.  If not, write to
16
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
   Boston, MA 02110-1301, USA.
17
   Boston, MA 02110-1301, USA.
18
*/
18
*/
19
#include "mailwebengineview.h"
19
#include "mailwebengineview.h"
20
#include "mailwebenginepage.h"
20
#include "mailwebenginepage.h"
21
#include "webengineviewer/webengineaccesskey.h"
21
#include "webengineviewer/webengineaccesskey.h"
22
#include "webengineviewer/webenginescript.h"
22
#include "webengineviewer/webenginescript.h"
23
#include "messageviewer/messageviewersettings.h"
23
#include "messageviewer/messageviewersettings.h"
24
#include "../urlhandlermanager.h"
24
#include "../urlhandlermanager.h"
25
#include "loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.h"
25
#include "loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.h"
26
#include "blockexternalresourcesurlinterceptor/blockexternalresourcesurlinterceptor.h"
26
#include "blockexternalresourcesurlinterceptor/blockexternalresourcesurlinterceptor.h"
27
#include "blockmailtrackingurlinterceptor/blockmailtrackingurlinterceptor.h"
27
#include "blockmailtrackingurlinterceptor/blockmailtrackingurlinterceptor.h"
28
#include "cidreferencesurlinterceptor/cidreferencesurlinterceptor.h"
28
#include "cidreferencesurlinterceptor/cidreferencesurlinterceptor.h"
29
#include <WebEngineViewer/InterceptorManager>
29
#include <WebEngineViewer/InterceptorManager>
30
#include <WebEngineViewer/WebEngineManageScript>
30
#include <WebEngineViewer/WebEngineManageScript>
31
31
32
#include "scamdetection/scamdetectionwebengine.h"
32
#include "scamdetection/scamdetectionwebengine.h"
33
#include "scamdetection/scamcheckshorturl.h"
33
#include "scamdetection/scamcheckshorturl.h"
34
#include <QContextMenuEvent>
34
#include <QContextMenuEvent>
35
#include <WebEngineViewer/WebHitTest>
35
#include <WebEngineViewer/WebHitTest>
36
36
37
#include <QWebEngineProfile>
38
#include <QPrinter>
37
#include <QPrinter>
39
38
40
#include <WebEngineViewer/WebHitTestResult>
39
#include <WebEngineViewer/WebHitTestResult>
41
40
42
using namespace MessageViewer;
41
using namespace MessageViewer;
43
template<typename Arg, typename R, typename C>
42
template<typename Arg, typename R, typename C>
44
struct InvokeWrapper {
43
struct InvokeWrapper {
45
    R *receiver;
44
    R *receiver;
46
    void (C::*memberFunction)(Arg);
45
    void (C::*memberFunction)(Arg);
47
    void operator()(Arg result)
46
    void operator()(Arg result)
48
    {
47
    {
49
        (receiver->*memberFunction)(result);
48
        (receiver->*memberFunction)(result);
50
    }
49
    }
51
};
50
};
52
51
53
template<typename Arg, typename R, typename C>
52
template<typename Arg, typename R, typename C>
54
53
55
InvokeWrapper<Arg, R, C> invoke(R *receiver, void (C::*memberFunction)(Arg))
54
InvokeWrapper<Arg, R, C> invoke(R *receiver, void (C::*memberFunction)(Arg))
56
{
55
{
57
    InvokeWrapper<Arg, R, C> wrapper = {receiver, memberFunction};
56
    InvokeWrapper<Arg, R, C> wrapper = {receiver, memberFunction};
58
    return wrapper;
57
    return wrapper;
59
}
58
}
60
59
61
class MessageViewer::MailWebEngineViewPrivate
60
class MessageViewer::MailWebEngineViewPrivate
62
{
61
{
63
public:
62
public:
64
    MailWebEngineViewPrivate()
63
    MailWebEngineViewPrivate()
65
    {
64
    {
66
    }
65
    }
67
66
68
    QUrl mHoveredUrl;
67
    QUrl mHoveredUrl;
69
    QPoint mLastClickPosition;
68
    QPoint mLastClickPosition;
70
    ScamDetectionWebEngine *mScamDetection = nullptr;
69
    ScamDetectionWebEngine *mScamDetection = nullptr;
71
    WebEngineViewer::WebEngineAccessKey *mWebViewAccessKey = nullptr;
70
    WebEngineViewer::WebEngineAccessKey *mWebViewAccessKey = nullptr;
72
    MessageViewer::LoadExternalReferencesUrlInterceptor *mExternalReference = nullptr;
71
    MessageViewer::LoadExternalReferencesUrlInterceptor *mExternalReference = nullptr;
73
    MailWebEnginePage *mPageEngine = nullptr;
72
    MailWebEnginePage *mPageEngine = nullptr;
74
    WebEngineViewer::InterceptorManager *mNetworkAccessManager = nullptr;
73
    WebEngineViewer::InterceptorManager *mNetworkAccessManager = nullptr;
75
    MessageViewer::ViewerPrivate *mViewer = nullptr;
74
    MessageViewer::ViewerPrivate *mViewer = nullptr;
76
    MessageViewer::BlockMailTrackingUrlInterceptor *mBlockMailTrackingUrl = nullptr;
75
    MessageViewer::BlockMailTrackingUrlInterceptor *mBlockMailTrackingUrl = nullptr;
77
    bool mCanStartDrag = false;
76
    bool mCanStartDrag = false;
78
};
77
};
79
78
80
MailWebEngineView::MailWebEngineView(KActionCollection *ac, QWidget *parent)
79
MailWebEngineView::MailWebEngineView(KActionCollection *ac, QWidget *parent)
81
    : WebEngineViewer::WebEngineView(parent)
80
    : WebEngineViewer::WebEngineView(parent)
82
    , d(new MessageViewer::MailWebEngineViewPrivate)
81
    , d(new MessageViewer::MailWebEngineViewPrivate)
83
{
82
{
84
    d->mPageEngine = new MailWebEnginePage(new QWebEngineProfile(this), this);
83
    d->mPageEngine = new MailWebEnginePage(this);
85
    setPage(d->mPageEngine);
84
    setPage(d->mPageEngine);
86
    d->mWebViewAccessKey = new WebEngineViewer::WebEngineAccessKey(this, this);
85
    d->mWebViewAccessKey = new WebEngineViewer::WebEngineAccessKey(this, this);
87
    d->mWebViewAccessKey->setActionCollection(ac);
86
    d->mWebViewAccessKey->setActionCollection(ac);
88
    d->mScamDetection = new ScamDetectionWebEngine(this);
87
    d->mScamDetection = new ScamDetectionWebEngine(this);
89
    connect(d->mScamDetection, &ScamDetectionWebEngine::messageMayBeAScam, this,
88
    connect(d->mScamDetection, &ScamDetectionWebEngine::messageMayBeAScam, this,
90
            &MailWebEngineView::messageMayBeAScam);
89
            &MailWebEngineView::messageMayBeAScam);
91
    connect(d->mWebViewAccessKey, &WebEngineViewer::WebEngineAccessKey::openUrl, this,
90
    connect(d->mWebViewAccessKey, &WebEngineViewer::WebEngineAccessKey::openUrl, this,
92
            &MailWebEngineView::openUrl);
91
            &MailWebEngineView::openUrl);
93
    connect(this, &MailWebEngineView::loadFinished, this, &MailWebEngineView::slotLoadFinished);
92
    connect(this, &MailWebEngineView::loadFinished, this, &MailWebEngineView::slotLoadFinished);
94
93
95
    d->mNetworkAccessManager = new WebEngineViewer::InterceptorManager(this, ac, this);
94
    d->mNetworkAccessManager = new WebEngineViewer::InterceptorManager(this, ac, this);
96
    d->mExternalReference = new MessageViewer::LoadExternalReferencesUrlInterceptor(this);
95
    d->mExternalReference = new MessageViewer::LoadExternalReferencesUrlInterceptor(this);
97
    d->mNetworkAccessManager->addInterceptor(d->mExternalReference);
96
    d->mNetworkAccessManager->addInterceptor(d->mExternalReference);
98
    MessageViewer::CidReferencesUrlInterceptor *cidReference
97
    MessageViewer::CidReferencesUrlInterceptor *cidReference
99
        = new MessageViewer::CidReferencesUrlInterceptor(this);
98
        = new MessageViewer::CidReferencesUrlInterceptor(this);
100
    d->mNetworkAccessManager->addInterceptor(cidReference);
99
    d->mNetworkAccessManager->addInterceptor(cidReference);
101
    MessageViewer::BlockExternalResourcesUrlInterceptor *blockExternalUrl
100
    MessageViewer::BlockExternalResourcesUrlInterceptor *blockExternalUrl
102
        = new MessageViewer::BlockExternalResourcesUrlInterceptor(this);
101
        = new MessageViewer::BlockExternalResourcesUrlInterceptor(this);
103
    connect(blockExternalUrl, &BlockExternalResourcesUrlInterceptor::formSubmittedForbidden, this,
102
    connect(blockExternalUrl, &BlockExternalResourcesUrlInterceptor::formSubmittedForbidden, this,
104
            &MailWebEngineView::formSubmittedForbidden);
103
            &MailWebEngineView::formSubmittedForbidden);
105
    d->mNetworkAccessManager->addInterceptor(blockExternalUrl);
104
    d->mNetworkAccessManager->addInterceptor(blockExternalUrl);
106
105
107
    d->mBlockMailTrackingUrl
106
    d->mBlockMailTrackingUrl
108
        = new MessageViewer::BlockMailTrackingUrlInterceptor(this);
107
        = new MessageViewer::BlockMailTrackingUrlInterceptor(this);
109
    connect(d->mBlockMailTrackingUrl, &BlockMailTrackingUrlInterceptor::mailTrackingFound, this,
108
    connect(d->mBlockMailTrackingUrl, &BlockMailTrackingUrlInterceptor::mailTrackingFound, this,
110
            &MailWebEngineView::mailTrackingFound);
109
            &MailWebEngineView::mailTrackingFound);
111
110
112
    setFocusPolicy(Qt::WheelFocus);
111
    setFocusPolicy(Qt::WheelFocus);
113
    connect(d->mPageEngine, &MailWebEnginePage::urlClicked, this, &MailWebEngineView::openUrl);
112
    connect(d->mPageEngine, &MailWebEnginePage::urlClicked, this, &MailWebEngineView::openUrl);
114
    connect(
113
    connect(
115
        page(), &QWebEnginePage::scrollPositionChanged, d->mWebViewAccessKey,
114
        page(), &QWebEnginePage::scrollPositionChanged, d->mWebViewAccessKey,
116
        &WebEngineViewer::WebEngineAccessKey::hideAccessKeys);
115
        &WebEngineViewer::WebEngineAccessKey::hideAccessKeys);
117
    initializeScripts();
116
    initializeScripts();
118
}
117
}
119
118
120
MailWebEngineView::~MailWebEngineView()
119
MailWebEngineView::~MailWebEngineView()
121
{
120
{
122
    delete d;
121
    delete d;
123
}
122
}
124
123
125
void MailWebEngineView::readConfig()
124
void MailWebEngineView::readConfig()
126
{
125
{
127
    if (MessageViewer::MessageViewerSettings::self()->mailTrackingUrlEnabled()) {
126
    if (MessageViewer::MessageViewerSettings::self()->mailTrackingUrlEnabled()) {
128
        d->mNetworkAccessManager->addInterceptor(d->mBlockMailTrackingUrl);
127
        d->mNetworkAccessManager->addInterceptor(d->mBlockMailTrackingUrl);
129
    } else {
128
    } else {
130
        d->mNetworkAccessManager->removeInterceptor(d->mBlockMailTrackingUrl);
129
        d->mNetworkAccessManager->removeInterceptor(d->mBlockMailTrackingUrl);
131
    }
130
    }
132
}
131
}
133
132
134
void MailWebEngineView::setLinkHovered(const QUrl &url)
133
void MailWebEngineView::setLinkHovered(const QUrl &url)
135
{
134
{
136
    //TODO we need to detect image url too.
135
    //TODO we need to detect image url too.
137
    d->mHoveredUrl = url;
136
    d->mHoveredUrl = url;
138
}
137
}
139
138
140
void MailWebEngineView::runJavaScriptInWordId(const QString &script)
139
void MailWebEngineView::runJavaScriptInWordId(const QString &script)
141
{
140
{
142
    page()->runJavaScript(script, WebEngineViewer::WebEngineManageScript::scriptWordId());
141
    page()->runJavaScript(script, WebEngineViewer::WebEngineManageScript::scriptWordId());
143
}
142
}
144
143
145
void MailWebEngineView::setViewer(MessageViewer::ViewerPrivate *viewer)
144
void MailWebEngineView::setViewer(MessageViewer::ViewerPrivate *viewer)
146
{
145
{
147
    d->mViewer = viewer;
146
    d->mViewer = viewer;
148
}
147
}
149
148
150
void MailWebEngineView::initializeScripts()
149
void MailWebEngineView::initializeScripts()
151
{
150
{
152
    initializeJQueryScript();
151
    initializeJQueryScript();
153
}
152
}
154
153
155
void MailWebEngineView::contextMenuEvent(QContextMenuEvent *e)
154
void MailWebEngineView::contextMenuEvent(QContextMenuEvent *e)
156
{
155
{
157
    WebEngineViewer::WebHitTest *webHit = d->mPageEngine->hitTestContent(e->pos());
156
    WebEngineViewer::WebHitTest *webHit = d->mPageEngine->hitTestContent(e->pos());
158
    connect(webHit, &WebEngineViewer::WebHitTest::finished, this,
157
    connect(webHit, &WebEngineViewer::WebHitTest::finished, this,
159
            &MailWebEngineView::slotWebHitFinished);
158
            &MailWebEngineView::slotWebHitFinished);
160
}
159
}
161
160
162
void MailWebEngineView::slotWebHitFinished(const WebEngineViewer::WebHitTestResult &result)
161
void MailWebEngineView::slotWebHitFinished(const WebEngineViewer::WebHitTestResult &result)
163
{
162
{
164
    Q_EMIT popupMenu(result);
163
    Q_EMIT popupMenu(result);
165
}
164
}
166
165
167
void MailWebEngineView::scrollUp(int pixels)
166
void MailWebEngineView::scrollUp(int pixels)
168
{
167
{
169
    runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollUp(pixels));
168
    runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollUp(pixels));
170
}
169
}
171
170
172
void MailWebEngineView::scrollDown(int pixels)
171
void MailWebEngineView::scrollDown(int pixels)
173
{
172
{
174
    runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollDown(pixels));
173
    runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollDown(pixels));
175
}
174
}
176
175
177
void MailWebEngineView::selectAll()
176
void MailWebEngineView::selectAll()
178
{
177
{
179
    page()->triggerAction(QWebEnginePage::SelectAll);
178
    page()->triggerAction(QWebEnginePage::SelectAll);
180
}
179
}
181
180
182
void MailWebEngineView::slotZoomChanged(qreal zoom)
181
void MailWebEngineView::slotZoomChanged(qreal zoom)
183
{
182
{
184
    setZoomFactor(zoom);
183
    setZoomFactor(zoom);
185
}
184
}
186
185
187
void MailWebEngineView::scamCheck()
186
void MailWebEngineView::scamCheck()
188
{
187
{
189
    d->mScamDetection->scanPage(page());
188
    d->mScamDetection->scanPage(page());
190
}
189
}
191
190
192
void MailWebEngineView::slotShowDetails()
191
void MailWebEngineView::slotShowDetails()
193
{
192
{
194
    d->mScamDetection->showDetails();
193
    d->mScamDetection->showDetails();
195
}
194
}
196
195
197
void MailWebEngineView::forwardKeyReleaseEvent(QKeyEvent *e)
196
void MailWebEngineView::forwardKeyReleaseEvent(QKeyEvent *e)
198
{
197
{
199
    if (MessageViewer::MessageViewerSettings::self()->accessKeyEnabled()) {
198
    if (MessageViewer::MessageViewerSettings::self()->accessKeyEnabled()) {
200
        d->mWebViewAccessKey->keyReleaseEvent(e);
199
        d->mWebViewAccessKey->keyReleaseEvent(e);
201
    }
200
    }
202
}
201
}
203
202
204
void MailWebEngineView::forwardMousePressEvent(QMouseEvent *event)
203
void MailWebEngineView::forwardMousePressEvent(QMouseEvent *event)
205
{
204
{
206
    if (d->mViewer && !d->mHoveredUrl.isEmpty()) {
205
    if (d->mViewer && !d->mHoveredUrl.isEmpty()) {
207
        if (event->button() == Qt::LeftButton && (event->modifiers() & Qt::ShiftModifier)) {
206
        if (event->button() == Qt::LeftButton && (event->modifiers() & Qt::ShiftModifier)) {
208
            // special processing for shift+click
207
            // special processing for shift+click
209
            if (URLHandlerManager::instance()->handleShiftClick(d->mHoveredUrl, d->mViewer)) {
208
            if (URLHandlerManager::instance()->handleShiftClick(d->mHoveredUrl, d->mViewer)) {
210
                event->accept();
209
                event->accept();
211
                return;
210
                return;
212
            }
211
            }
213
        }
212
        }
214
        if (event->button() == Qt::LeftButton) {
213
        if (event->button() == Qt::LeftButton) {
215
            d->mCanStartDrag = URLHandlerManager::instance()->willHandleDrag(d->mHoveredUrl,
214
            d->mCanStartDrag = URLHandlerManager::instance()->willHandleDrag(d->mHoveredUrl,
216
                                                                             d->mViewer);
215
                                                                             d->mViewer);
217
            d->mLastClickPosition = event->pos();
216
            d->mLastClickPosition = event->pos();
218
        }
217
        }
219
    }
218
    }
220
}
219
}
221
220
222
void MailWebEngineView::forwardMouseMoveEvent(QMouseEvent *event)
221
void MailWebEngineView::forwardMouseMoveEvent(QMouseEvent *event)
223
{
222
{
224
    if (d->mViewer && !d->mHoveredUrl.isEmpty()) {
223
    if (d->mViewer && !d->mHoveredUrl.isEmpty()) {
225
        // If we are potentially handling a drag, deal with that.
224
        // If we are potentially handling a drag, deal with that.
226
        if (d->mCanStartDrag && (event->buttons() & Qt::LeftButton)) {
225
        if (d->mCanStartDrag && (event->buttons() & Qt::LeftButton)) {
227
            if ((d->mLastClickPosition - event->pos()).manhattanLength()
226
            if ((d->mLastClickPosition - event->pos()).manhattanLength()
228
                > QApplication::startDragDistance()) {
227
                > QApplication::startDragDistance()) {
229
                if (URLHandlerManager::instance()->handleDrag(d->mHoveredUrl, d->mViewer)) {
228
                if (URLHandlerManager::instance()->handleDrag(d->mHoveredUrl, d->mViewer)) {
230
                    // If the URL handler manager started a drag, don't handle this in the future
229
                    // If the URL handler manager started a drag, don't handle this in the future
231
                    d->mCanStartDrag = false;
230
                    d->mCanStartDrag = false;
232
                }
231
                }
233
            }
232
            }
234
            event->accept();
233
            event->accept();
235
        }
234
        }
236
    }
235
    }
237
}
236
}
238
237
239
void MailWebEngineView::forwardMouseReleaseEvent(QMouseEvent *event)
238
void MailWebEngineView::forwardMouseReleaseEvent(QMouseEvent *event)
240
{
239
{
241
    Q_UNUSED(event);
240
    Q_UNUSED(event);
242
    d->mCanStartDrag = false;
241
    d->mCanStartDrag = false;
243
}
242
}
244
243
245
void MailWebEngineView::forwardKeyPressEvent(QKeyEvent *e)
244
void MailWebEngineView::forwardKeyPressEvent(QKeyEvent *e)
246
{
245
{
247
    if (e && hasFocus()) {
246
    if (e && hasFocus()) {
248
        if (MessageViewer::MessageViewerSettings::self()->accessKeyEnabled()) {
247
        if (MessageViewer::MessageViewerSettings::self()->accessKeyEnabled()) {
249
            d->mWebViewAccessKey->keyPressEvent(e);
248
            d->mWebViewAccessKey->keyPressEvent(e);
250
        }
249
        }
251
    }
250
    }
252
}
251
}
253
252
254
void MailWebEngineView::forwardWheelEvent(QWheelEvent *e)
253
void MailWebEngineView::forwardWheelEvent(QWheelEvent *e)
255
{
254
{
256
    if (MessageViewer::MessageViewerSettings::self()->accessKeyEnabled()) {
255
    if (MessageViewer::MessageViewerSettings::self()->accessKeyEnabled()) {
257
        d->mWebViewAccessKey->wheelEvent(e);
256
        d->mWebViewAccessKey->wheelEvent(e);
258
    }
257
    }
259
    if (QApplication::keyboardModifiers() & Qt::ControlModifier) {
258
    if (QApplication::keyboardModifiers() & Qt::ControlModifier) {
260
        const int numDegrees = e->delta() / 8;
259
        const int numDegrees = e->delta() / 8;
261
        const int numSteps = numDegrees / 15;
260
        const int numSteps = numDegrees / 15;
262
        Q_EMIT wheelZoomChanged(numSteps);
261
        Q_EMIT wheelZoomChanged(numSteps);
263
        e->accept();
262
        e->accept();
264
    }
263
    }
265
}
264
}
266
265
267
void MailWebEngineView::resizeEvent(QResizeEvent *e)
266
void MailWebEngineView::resizeEvent(QResizeEvent *e)
268
{
267
{
269
    if (MessageViewer::MessageViewerSettings::self()->accessKeyEnabled()) {
268
    if (MessageViewer::MessageViewerSettings::self()->accessKeyEnabled()) {
270
        d->mWebViewAccessKey->resizeEvent(e);
269
        d->mWebViewAccessKey->resizeEvent(e);
271
    }
270
    }
272
    QWebEngineView::resizeEvent(e);
271
    QWebEngineView::resizeEvent(e);
273
}
272
}
274
273
275
void MailWebEngineView::saveMainFrameScreenshotInFile(const QString &filename)
274
void MailWebEngineView::saveMainFrameScreenshotInFile(const QString &filename)
276
{
275
{
277
    //TODO need to verify it
276
    //TODO need to verify it
278
    QImage image(size(), QImage::Format_ARGB32_Premultiplied);
277
    QImage image(size(), QImage::Format_ARGB32_Premultiplied);
279
    image.fill(Qt::transparent);
278
    image.fill(Qt::transparent);
280
279
281
    QPainter painter(&image);
280
    QPainter painter(&image);
282
    painter.setRenderHint(QPainter::Antialiasing, true);
281
    painter.setRenderHint(QPainter::Antialiasing, true);
283
    painter.setRenderHint(QPainter::TextAntialiasing, true);
282
    painter.setRenderHint(QPainter::TextAntialiasing, true);
284
    painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
283
    painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
285
    render(&painter);
284
    render(&painter);
286
    painter.end();
285
    painter.end();
287
    image.save(filename);
286
    image.save(filename);
288
}
287
}
289
288
290
void MailWebEngineView::showAccessKeys()
289
void MailWebEngineView::showAccessKeys()
291
{
290
{
292
    d->mWebViewAccessKey->showAccessKeys();
291
    d->mWebViewAccessKey->showAccessKeys();
293
}
292
}
294
293
295
void MailWebEngineView::hideAccessKeys()
294
void MailWebEngineView::hideAccessKeys()
296
{
295
{
297
    d->mWebViewAccessKey->hideAccessKeys();
296
    d->mWebViewAccessKey->hideAccessKeys();
298
}
297
}
299
298
300
void MailWebEngineView::isScrolledToBottom()
299
void MailWebEngineView::isScrolledToBottom()
301
{
300
{
302
    page()->runJavaScript(WebEngineViewer::WebEngineScript::isScrolledToBottom(),
301
    page()->runJavaScript(WebEngineViewer::WebEngineScript::isScrolledToBottom(),
303
                          WebEngineViewer::WebEngineManageScript::scriptWordId(),
302
                          WebEngineViewer::WebEngineManageScript::scriptWordId(),
304
                          invoke(this, &MailWebEngineView::handleIsScrolledToBottom));
303
                          invoke(this, &MailWebEngineView::handleIsScrolledToBottom));
305
}
304
}
306
305
307
void MailWebEngineView::setElementByIdVisible(const QString &id, bool visible)
306
void MailWebEngineView::setElementByIdVisible(const QString &id, bool visible)
308
{
307
{
309
    runJavaScriptInWordId(WebEngineViewer::WebEngineScript::setElementByIdVisible(id, visible));
308
    runJavaScriptInWordId(WebEngineViewer::WebEngineScript::setElementByIdVisible(id, visible));
310
}
309
}
311
310
312
void MailWebEngineView::removeAttachmentMarking(const QString &id)
311
void MailWebEngineView::removeAttachmentMarking(const QString &id)
313
{
312
{
314
    runJavaScriptInWordId(WebEngineViewer::WebEngineScript::removeStyleToElement(id));
313
    runJavaScriptInWordId(WebEngineViewer::WebEngineScript::removeStyleToElement(id));
315
}
314
}
316
315
317
void MailWebEngineView::markAttachment(const QString &id, const QString &style)
316
void MailWebEngineView::markAttachment(const QString &id, const QString &style)
318
{
317
{
319
    runJavaScriptInWordId(WebEngineViewer::WebEngineScript::setStyleToElement(id, style));
318
    runJavaScriptInWordId(WebEngineViewer::WebEngineScript::setStyleToElement(id, style));
320
}
319
}
321
320
322
void MailWebEngineView::scrollToAnchor(const QString &anchor)
321
void MailWebEngineView::scrollToAnchor(const QString &anchor)
323
{
322
{
324
    page()->runJavaScript(WebEngineViewer::WebEngineScript::searchElementPosition(anchor),
323
    page()->runJavaScript(WebEngineViewer::WebEngineScript::searchElementPosition(anchor),
325
                          WebEngineViewer::WebEngineManageScript::scriptWordId(),
324
                          WebEngineViewer::WebEngineManageScript::scriptWordId(),
326
                          invoke(this, &MailWebEngineView::handleScrollToAnchor));
325
                          invoke(this, &MailWebEngineView::handleScrollToAnchor));
327
}
326
}
328
327
329
void MailWebEngineView::handleIsScrolledToBottom(const QVariant &result)
328
void MailWebEngineView::handleIsScrolledToBottom(const QVariant &result)
330
{
329
{
331
    bool scrolledToBottomResult = false;
330
    bool scrolledToBottomResult = false;
332
    if (result.isValid()) {
331
    if (result.isValid()) {
333
        scrolledToBottomResult = result.toBool();
332
        scrolledToBottomResult = result.toBool();
334
    }
333
    }
335
    Q_EMIT pageIsScrolledToBottom(scrolledToBottomResult);
334
    Q_EMIT pageIsScrolledToBottom(scrolledToBottomResult);
336
}
335
}
337
336
338
void MailWebEngineView::handleScrollToAnchor(const QVariant &result)
337
void MailWebEngineView::handleScrollToAnchor(const QVariant &result)
339
{
338
{
340
    if (result.isValid()) {
339
    if (result.isValid()) {
341
        const QList<QVariant> lst = result.toList();
340
        const QList<QVariant> lst = result.toList();
342
        if (lst.count() == 2) {
341
        if (lst.count() == 2) {
343
            const QPoint pos(lst.at(0).toInt(), lst.at(1).toInt());
342
            const QPoint pos(lst.at(0).toInt(), lst.at(1).toInt());
344
            runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollToPosition(pos));
343
            runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollToPosition(pos));
345
        }
344
        }
346
    }
345
    }
347
}
346
}
348
347
349
void MailWebEngineView::scrollPageDown(int percent)
348
void MailWebEngineView::scrollPageDown(int percent)
350
{
349
{
351
    runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollPercentage(percent));
350
    runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollPercentage(percent));
352
}
351
}
353
352
354
void MailWebEngineView::scrollPageUp(int percent)
353
void MailWebEngineView::scrollPageUp(int percent)
355
{
354
{
356
    scrollPageDown(-percent);
355
    scrollPageDown(-percent);
357
}
356
}
358
357
359
void MailWebEngineView::scrollToRelativePosition(qreal pos)
358
void MailWebEngineView::scrollToRelativePosition(qreal pos)
360
{
359
{
361
    runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollToRelativePosition(pos));
360
    runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollToRelativePosition(pos));
362
}
361
}
363
362
364
void MailWebEngineView::setAllowExternalContent(bool b)
363
void MailWebEngineView::setAllowExternalContent(bool b)
365
{
364
{
366
    if (d->mExternalReference->allowExternalContent() != b) {
365
    if (d->mExternalReference->allowExternalContent() != b) {
367
        d->mExternalReference->setAllowExternalContent(b);
366
        d->mExternalReference->setAllowExternalContent(b);
368
        reload();
367
        reload();
369
    }
368
    }
370
}
369
}
371
370
372
QList<QAction *> MailWebEngineView::interceptorUrlActions(
371
QList<QAction *> MailWebEngineView::interceptorUrlActions(
373
    const WebEngineViewer::WebHitTestResult &result) const
372
    const WebEngineViewer::WebHitTestResult &result) const
374
{
373
{
375
    return d->mNetworkAccessManager->interceptorUrlActions(result);
374
    return d->mNetworkAccessManager->interceptorUrlActions(result);
376
}
375
}
377
376
378
void MailWebEngineView::slotLoadFinished()
377
void MailWebEngineView::slotLoadFinished()
379
{
378
{
380
    scamCheck();
379
    scamCheck();
381
}
380
}
382
381
383
void MailWebEngineView::setPrintElementBackground(bool printElementBackground)
382
void MailWebEngineView::setPrintElementBackground(bool printElementBackground)
384
{
383
{
385
    d->mPageEngine->setPrintElementBackground(printElementBackground);
384
    d->mPageEngine->setPrintElementBackground(printElementBackground);
386
}
385
}
387
386
388
bool MailWebEngineView::execPrintPreviewPage(QPrinter *printer, int timeout)
387
bool MailWebEngineView::execPrintPreviewPage(QPrinter *printer, int timeout)
389
{
388
{
390
    return d->mPageEngine->execPrintPreviewPage(printer, timeout);
389
    return d->mPageEngine->execPrintPreviewPage(printer, timeout);
391
}
390
}
(-)a/webengineviewer/src/webenginepage.cpp (-5 / +17 lines)
Lines 1-106 Link Here
1
/*
1
/*
2
   Copyright (C) 2016-2018 Laurent Montel <montel@kde.org>
2
   Copyright (C) 2016-2018 Laurent Montel <montel@kde.org>
3
3
4
   This library is free software; you can redistribute it and/or
4
   This library is free software; you can redistribute it and/or
5
   modify it under the terms of the GNU Library General Public
5
   modify it under the terms of the GNU Library General Public
6
   License as published by the Free Software Foundation; either
6
   License as published by the Free Software Foundation; either
7
   version 2 of the License, or (at your option) any later version.
7
   version 2 of the License, or (at your option) any later version.
8
8
9
   This library is distributed in the hope that it will be useful,
9
   This library is distributed in the hope that it will be useful,
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
   Library General Public License for more details.
12
   Library General Public License for more details.
13
13
14
   You should have received a copy of the GNU Library General Public License
14
   You should have received a copy of the GNU Library General Public License
15
   along with this library; see the file COPYING.LIB.  If not, write to
15
   along with this library; see the file COPYING.LIB.  If not, write to
16
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
   Boston, MA 02110-1301, USA.
17
   Boston, MA 02110-1301, USA.
18
*/
18
*/
19
19
20
#include "webenginepage.h"
20
#include "webenginepage.h"
21
#include "webhittest.h"
21
#include "webhittest.h"
22
#include "webhittestresult.h"
22
#include "webhittestresult.h"
23
23
24
#include <KLocalizedString>
24
#include <KLocalizedString>
25
25
26
#include <QEventLoop>
26
#include <QEventLoop>
27
#include <QWebEngineDownloadItem>
27
#include <QWebEngineDownloadItem>
28
#include <QPointer>
28
#include <QPointer>
29
#include <QTimer>
29
#include <QTimer>
30
#include <QFileDialog>
30
#include <QFileDialog>
31
#include <QWebEngineProfile>
31
#include <QWebEngineProfile>
32
#include <QPrinter>
32
#include <QPrinter>
33
using namespace WebEngineViewer;
33
using namespace WebEngineViewer;
34
34
35
WebEnginePage::WebEnginePage(QObject *parent)
35
WebEnginePage::WebEnginePage(QObject *parent)
36
    : QWebEnginePage(parent)
36
    : QWebEnginePage(new QWebEngineProfile, parent)
37
{
37
{
38
    // Create a private (off the record) QWebEngineProfile here to isolate the
39
    // browsing settings, and adopt it as a child so that it will be deleted
40
    // when we are destroyed.  The profile must remain active for as long as
41
    // any QWebEnginePage's belonging to it exist, see the API documentation
42
    // of QWebEnginePage::QWebEnginePage(QWebEngineProfile *, QObject *).
43
    // Deleting it as our child on destruction is safe.
44
    //
45
    // Do not try to save a line of code by setting the parent on construction:
46
    //
47
    //    WebEnginePage::WebEnginePage(QObject *parent)
48
    //      : QWebEnginePage(new QWebEngineProfile(this), parent)
49
    //
50
    // because the QWebEngineProfile constructor will call out to the QWebEnginePage
51
    // and crash because the QWebEnginePage is not fully constructed yet.
52
    profile()->setParent(this);
53
38
    init();
54
    init();
39
}
55
}
40
56
41
WebEnginePage::WebEnginePage(QWebEngineProfile *profile, QObject *parent)
57
WebEnginePage::WebEnginePage(QWebEngineProfile *profile, QObject *parent)
42
    : QWebEnginePage(profile, parent)
58
    : QWebEnginePage(profile, parent)
43
{
59
{
44
    init();
60
    init();
45
}
61
}
46
62
47
WebEnginePage::~WebEnginePage()
48
{
49
}
50
51
void WebEnginePage::init()
63
void WebEnginePage::init()
52
{
64
{
53
    connect(profile(), &QWebEngineProfile::downloadRequested, this, &WebEnginePage::saveHtml);
65
    connect(profile(), &QWebEngineProfile::downloadRequested, this, &WebEnginePage::saveHtml);
54
}
66
}
55
67
56
WebEngineViewer::WebHitTest *WebEnginePage::hitTestContent(const QPoint &pos)
68
WebEngineViewer::WebHitTest *WebEnginePage::hitTestContent(const QPoint &pos)
57
{
69
{
58
    return new WebHitTest(this, pos);
70
    return new WebHitTest(this, pos);
59
}
71
}
60
72
61
void WebEnginePage::saveHtml(QWebEngineDownloadItem *download)
73
void WebEnginePage::saveHtml(QWebEngineDownloadItem *download)
62
{
74
{
63
    const QString fileName = QFileDialog::getSaveFileName(view(), i18n("Save HTML Page"));
75
    const QString fileName = QFileDialog::getSaveFileName(view(), i18n("Save HTML Page"));
64
    if (!fileName.isEmpty()) {
76
    if (!fileName.isEmpty()) {
65
        download->setSavePageFormat(QWebEngineDownloadItem::SingleHtmlSaveFormat);
77
        download->setSavePageFormat(QWebEngineDownloadItem::SingleHtmlSaveFormat);
66
        download->setPath(fileName);
78
        download->setPath(fileName);
67
        download->accept();
79
        download->accept();
68
    }
80
    }
69
}
81
}
70
82
71
bool WebEnginePage::acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame)
83
bool WebEnginePage::acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame)
72
{
84
{
73
    if (isMainFrame && type == NavigationTypeLinkClicked) {
85
    if (isMainFrame && type == NavigationTypeLinkClicked) {
74
        Q_EMIT urlClicked(url);
86
        Q_EMIT urlClicked(url);
75
        return false;
87
        return false;
76
    }
88
    }
77
    return true;
89
    return true;
78
}
90
}
79
91
80
void WebEnginePage::javaScriptConsoleMessage(QWebEnginePage::JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID)
92
void WebEnginePage::javaScriptConsoleMessage(QWebEnginePage::JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID)
81
{
93
{
82
    Q_UNUSED(level);
94
    Q_UNUSED(level);
83
    Q_UNUSED(sourceID);
95
    Q_UNUSED(sourceID);
84
    //Don't convert to debug categories
96
    //Don't convert to debug categories
85
    qDebug() << "WebEnginePage::javaScriptConsoleMessage lineNumber: " << lineNumber << " message: " << message;
97
    qDebug() << "WebEnginePage::javaScriptConsoleMessage lineNumber: " << lineNumber << " message: " << message;
86
    Q_EMIT showConsoleMessage(message);
98
    Q_EMIT showConsoleMessage(message);
87
}
99
}
88
100
89
bool WebEnginePage::execPrintPreviewPage(QPrinter *printer, int timeout)
101
bool WebEnginePage::execPrintPreviewPage(QPrinter *printer, int timeout)
90
{
102
{
91
    QPointer<QEventLoop> loop = new QEventLoop;
103
    QPointer<QEventLoop> loop = new QEventLoop;
92
    bool result = false;
104
    bool result = false;
93
    QTimer::singleShot(timeout, loop.data(), &QEventLoop::quit);
105
    QTimer::singleShot(timeout, loop.data(), &QEventLoop::quit);
94
106
95
    print(printer, [loop, &result](bool res) {
107
    print(printer, [loop, &result](bool res) {
96
        if (loop && loop->isRunning()) {
108
        if (loop && loop->isRunning()) {
97
            result = res;
109
            result = res;
98
            loop->quit();
110
            loop->quit();
99
        }
111
        }
100
    });
112
    });
101
113
102
    loop->exec();
114
    loop->exec();
103
    delete loop;
115
    delete loop;
104
116
105
    return result;
117
    return result;
106
}
118
}
(-)a/webengineviewer/src/webenginepage.h (-2 / +33 lines)
Lines 1-56 Link Here
1
/*
1
/*
2
   Copyright (C) 2016-2018 Laurent Montel <montel@kde.org>
2
   Copyright (C) 2016-2018 Laurent Montel <montel@kde.org>
3
3
4
   This library is free software; you can redistribute it and/or
4
   This library is free software; you can redistribute it and/or
5
   modify it under the terms of the GNU Library General Public
5
   modify it under the terms of the GNU Library General Public
6
   License as published by the Free Software Foundation; either
6
   License as published by the Free Software Foundation; either
7
   version 2 of the License, or (at your option) any later version.
7
   version 2 of the License, or (at your option) any later version.
8
8
9
   This library is distributed in the hope that it will be useful,
9
   This library is distributed in the hope that it will be useful,
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
   Library General Public License for more details.
12
   Library General Public License for more details.
13
13
14
   You should have received a copy of the GNU Library General Public License
14
   You should have received a copy of the GNU Library General Public License
15
   along with this library; see the file COPYING.LIB.  If not, write to
15
   along with this library; see the file COPYING.LIB.  If not, write to
16
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
   Boston, MA 02110-1301, USA.
17
   Boston, MA 02110-1301, USA.
18
*/
18
*/
19
19
20
#ifndef WEBENGINEPAGE_H
20
#ifndef WEBENGINEPAGE_H
21
#define WEBENGINEPAGE_H
21
#define WEBENGINEPAGE_H
22
22
23
#include <QWebEnginePage>
23
#include <QWebEnginePage>
24
#include "webengineviewer_export.h"
24
#include "webengineviewer_export.h"
25
class QWebEngineProfile;
25
class QWebEngineProfile;
26
class QWebEngineDownloadItem;
26
class QWebEngineDownloadItem;
27
class QPrinter;
27
class QPrinter;
28
namespace WebEngineViewer {
28
namespace WebEngineViewer {
29
class WebHitTest;
29
class WebHitTest;
30
class WEBENGINEVIEWER_EXPORT WebEnginePage : public QWebEnginePage
30
class WEBENGINEVIEWER_EXPORT WebEnginePage : public QWebEnginePage
31
{
31
{
32
    Q_OBJECT
32
    Q_OBJECT
33
public:
33
public:
34
    /**
35
     * Constructor.
36
     *
37
     * A private QWebEngineProfile, only applying to this QWebEnginePage,
38
     * will be created to implement browser settings.  It can be accessed via
39
     * @c profile(), but it should not be shared or reused unless care is
40
     * taken that the profile is not deleted until all of the QWebEnginePage's
41
     * belonging to it are deleted first.
42
     *
43
     * @param parent The parent object
44
     **/
34
    explicit WebEnginePage(QObject *parent = nullptr);
45
    explicit WebEnginePage(QObject *parent = nullptr);
35
    explicit WebEnginePage(QWebEngineProfile *profile, QObject *parent = nullptr);
36
46
37
    ~WebEnginePage() override;
47
    /**
48
     * Constructor.
49
     *
50
     * The specified QWebEngineProfile will be used.  See the description of
51
     * @c WebEnginePage(QObject *) and the API documentation of QWebEnginePage
52
     * for caution regarding the lifetime of the profile.
53
     *
54
     * @param profile The profile to be used
55
     * @param parent The parent object
56
     * @deprecated Use the single argument constructor, which creates and uses
57
     * a private profile.
58
     **/
59
#ifndef WEBENGINEVIEWER_NO_DEPRECATED
60
    explicit WEBENGINEVIEWER_DEPRECATED WebEnginePage(QWebEngineProfile *profile, QObject *parent = nullptr);
61
#endif
62
63
    /**
64
     * Destructor.  If there is a private QWebEngineProfile then it will also
65
     * be destroyed.
66
     **/
67
    virtual ~WebEnginePage() override = default;
68
38
    WebEngineViewer::WebHitTest *hitTestContent(const QPoint &pos);
69
    WebEngineViewer::WebHitTest *hitTestContent(const QPoint &pos);
39
70
40
    void saveHtml(QWebEngineDownloadItem *download);
71
    void saveHtml(QWebEngineDownloadItem *download);
41
    Q_REQUIRED_RESULT bool execPrintPreviewPage(QPrinter *printer, int timeout);
72
    Q_REQUIRED_RESULT bool execPrintPreviewPage(QPrinter *printer, int timeout);
42
73
43
Q_SIGNALS:
74
Q_SIGNALS:
44
    void urlClicked(const QUrl &url);
75
    void urlClicked(const QUrl &url);
45
    void showConsoleMessage(const QString &message);
76
    void showConsoleMessage(const QString &message);
46
77
47
protected:
78
protected:
48
    bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) override;
79
    bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) override;
49
    void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID) override;
80
    void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID) override;
50
81
51
private:
82
private:
52
    void init();
83
    void init();
53
};
84
};
54
}
85
}
55
86
56
#endif // WEBENGINEPAGE_H
87
#endif // WEBENGINEPAGE_H

Return to bug 686842