1 /*
2    SPDX-FileCopyrightText: 2015-2021 Laurent Montel <montel@kde.org>
3 
4    SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include <MessageViewer/ViewerPluginInterface>
10 #include <WebEngineViewer/CheckPhishingUrlJob>
11 #include <WebEngineViewer/WebEngineView>
12 #include <openurlrequest.h>
13 #include <shareserviceurlmanager.h>
14 
15 class KActionCollection;
16 namespace WebEngineViewer
17 {
18 class WebHitTestResult;
19 class WebEngineAccessKey;
20 class InterceptorManager;
21 class LoadExternalReferencesUrlInterceptor;
22 class BlockExternalResourcesUrlInterceptor;
23 }
24 namespace MessageViewer
25 {
26 class ViewerPluginToolManager;
27 class ViewerPluginInterface;
28 }
29 namespace PimCommon
30 {
31 class ShareServiceUrlManager;
32 }
33 namespace KIO
34 {
35 class KUriFilterSearchProviderActions;
36 }
37 namespace Akregator
38 {
39 class ArticleViewerWebEnginePage;
40 class AKREGATOR_EXPORT ArticleViewerWebEngine : public WebEngineViewer::WebEngineView
41 {
42     Q_OBJECT
43 public:
44     enum ArticleAction {
45         DeleteAction = 0,
46         MarkAsRead,
47         MarkAsUnRead,
48         MarkAsImportant,
49         SendUrlArticle,
50         SendFileArticle,
51         OpenInExternalBrowser,
52         OpenInBackgroundTab
53     };
54     explicit ArticleViewerWebEngine(KActionCollection *ac, QWidget *parent);
55     ~ArticleViewerWebEngine() override;
56 
57     void showAboutPage();
58 
59     void disableIntroduction();
60     void setArticleAction(ArticleViewerWebEngine::ArticleAction type, const QString &articleId, const QString &feed);
61     void restoreCurrentPosition();
62 
63     void createViewerPluginToolManager(KActionCollection *ac, QWidget *parent);
64 
65     void execPrintPreviewPage(QPrinter *printer, int timeout);
66 
67     virtual void updateSecurity();
68 
69 protected:
70     QUrl mCurrentUrl;
71     KActionCollection *const mActionCollection;
72     PimCommon::ShareServiceUrlManager *mShareServiceManager = nullptr;
73     KIO::KUriFilterSearchProviderActions *mWebShortcutMenuManager = nullptr;
74 
75 private:
76     enum MousePressedButtonType {
77         RightButton = 0,
78         LeftButton,
79         MiddleButton,
80     };
81 
82     void paintAboutScreen(const QString &templateName, const QVariantHash &data);
83     QVariantHash introductionData() const;
84 
85 public Q_SLOTS:
86     void slotCopy();
87     void slotSaveLinkAs();
88     void slotCopyLinkAddress();
89     void slotSaveImageOnDiskInFrame();
90     void slotCopyImageLocationInFrame();
91     void slotMute(bool mute);
92 Q_SIGNALS:
93     void signalOpenUrlRequest(Akregator::OpenUrlRequest &);
94     void showStatusBarMessage(const QString &link);
95     void showContextMenu(const QPoint &pos);
96     void articleAction(Akregator::ArticleViewerWebEngine::ArticleAction type, const QString &articleId, const QString &feed);
97     void findTextInHtml();
98     void textToSpeech();
99     void webPageMutedOrAudibleChanged(bool isAudioMuted, bool wasRecentlyAudible);
100     void trackingFound(const WebEngineViewer::BlockTrackingUrlInterceptor::TrackerBlackList &);
101 
102 protected:
103     void resizeEvent(QResizeEvent *e) override;
104 
105     virtual void displayContextMenu(const QPoint &pos);
106     void forwardKeyReleaseEvent(QKeyEvent *e) override;
107     void forwardKeyPressEvent(QKeyEvent *e) override;
108     void forwardWheelEvent(QWheelEvent *e) override;
109     void forwardMouseReleaseEvent(QMouseEvent *event) override;
110     void contextMenuEvent(QContextMenuEvent *e) override;
111 
112 private Q_SLOTS:
113     void slotServiceUrlSelected(PimCommon::ShareServiceUrlManager::ServiceType type);
114     void slotLinkHovered(const QString &link);
115     void slotLoadStarted();
116     void slotLoadFinished();
117     void slotLinkClicked(const QUrl &url);
118     void slotShowContextMenu(const QPoint &pos);
119     void slotWebHitFinished(const WebEngineViewer::WebHitTestResult &result);
120     void slotActivatePlugin(MessageViewer::ViewerPluginInterface *interface);
121     void slotWebPageMutedOrAudibleChanged();
122     void slotCheckedUrlFinished(const QUrl &url, WebEngineViewer::CheckPhishingUrlUtil::UrlStatus status);
123 
124 protected:
125     void slotOpenLinkInBrowser();
126     void slotOpenLinkInForegroundTab();
127     void slotOpenLinkInBackgroundTab();
128     ArticleViewerWebEnginePage *mPageEngine = nullptr;
129     QList<QAction *> viewerPluginActionList(MessageViewer::ViewerPluginInterface::SpecificFeatureTypes features);
130     WebEngineViewer::InterceptorManager *mNetworkAccessManager = nullptr;
131     WebEngineViewer::LoadExternalReferencesUrlInterceptor *mExternalReference = nullptr;
132     WebEngineViewer::BlockExternalResourcesUrlInterceptor *mBlockExternalReference = nullptr;
133 
134 private:
135     void openSafeUrl(const QUrl &url);
136     bool urlIsAMalwareButContinue();
137     MousePressedButtonType mLastButtonClicked = LeftButton;
138     MessageViewer::ViewerPluginToolManager *mViewerPluginToolManager = nullptr;
139     WebEngineViewer::WebEngineAccessKey *mWebEngineViewAccessKey = nullptr;
140 };
141 }
142 
143