File indexing completed on 2024-05-05 05:12:59

0001 /*
0002    SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "openurlrequest.h"
0010 #include <MessageViewer/ViewerPluginInterface>
0011 #include <PimCommon/ShareServiceUrlManager>
0012 #include <WebEngineViewer/CheckPhishingUrlJob>
0013 #include <WebEngineViewer/WebEngineView>
0014 
0015 class KActionCollection;
0016 namespace WebEngineViewer
0017 {
0018 class WebHitTestResult;
0019 class WebEngineAccessKey;
0020 class InterceptorManager;
0021 class LoadExternalReferencesUrlInterceptor;
0022 class BlockExternalResourcesUrlInterceptor;
0023 }
0024 namespace MessageViewer
0025 {
0026 class ViewerPluginToolManager;
0027 class ViewerPluginInterface;
0028 }
0029 namespace PimCommon
0030 {
0031 class ShareServiceUrlManager;
0032 }
0033 namespace KIO
0034 {
0035 class KUriFilterSearchProviderActions;
0036 }
0037 namespace Akregator
0038 {
0039 class ArticleViewerWebEnginePage;
0040 class AKREGATOR_EXPORT ArticleViewerWebEngine : public WebEngineViewer::WebEngineView
0041 {
0042     Q_OBJECT
0043 public:
0044     enum ArticleAction {
0045         DeleteAction = 0,
0046         MarkAsRead,
0047         MarkAsUnRead,
0048         MarkAsImportant,
0049         SendUrlArticle,
0050         SendFileArticle,
0051         OpenInExternalBrowser,
0052         OpenInBackgroundTab
0053     };
0054     explicit ArticleViewerWebEngine(KActionCollection *ac, QWidget *parent);
0055     ~ArticleViewerWebEngine() override;
0056 
0057     void showAboutPage();
0058 
0059     void disableIntroduction();
0060     void setArticleAction(ArticleViewerWebEngine::ArticleAction type, const QString &articleId, const QString &feed);
0061     void restoreCurrentPosition();
0062 
0063     void createViewerPluginToolManager(KActionCollection *ac, QWidget *parent);
0064 
0065     virtual void updateSecurity();
0066 
0067     void printPreviewPage(QPrinter *printer);
0068 
0069 protected:
0070     QUrl mCurrentUrl;
0071     KActionCollection *const mActionCollection;
0072     PimCommon::ShareServiceUrlManager *mShareServiceManager = nullptr;
0073     KIO::KUriFilterSearchProviderActions *mWebShortcutMenuManager = nullptr;
0074 
0075 private:
0076     enum MousePressedButtonType {
0077         RightButton = 0,
0078         LeftButton,
0079         MiddleButton,
0080     };
0081 
0082     void paintAboutScreen(const QString &templateName, const QVariantHash &data);
0083     QVariantHash introductionData() const;
0084 
0085 public Q_SLOTS:
0086     void slotCopy();
0087     void slotSaveLinkAs();
0088     void slotCopyLinkAddress();
0089     void slotSaveImageOnDiskInFrame();
0090     void slotCopyImageLocationInFrame();
0091     void slotMute(bool mute);
0092 Q_SIGNALS:
0093     void signalOpenUrlRequest(Akregator::OpenUrlRequest &);
0094     void showStatusBarMessage(const QString &link);
0095     void showContextMenu(const QPoint &pos);
0096     void articleAction(Akregator::ArticleViewerWebEngine::ArticleAction type, const QString &articleId, const QString &feed);
0097     void findTextInHtml();
0098     void textToSpeech();
0099     void webPageMutedOrAudibleChanged(bool isAudioMuted, bool wasRecentlyAudible);
0100     void trackingFound(const WebEngineViewer::BlockTrackingUrlInterceptor::TrackerBlackList &);
0101 
0102 protected:
0103     void resizeEvent(QResizeEvent *e) override;
0104 
0105     virtual void displayContextMenu(const QPoint &pos);
0106     void forwardKeyReleaseEvent(QKeyEvent *e) override;
0107     void forwardKeyPressEvent(QKeyEvent *e) override;
0108     void forwardWheelEvent(QWheelEvent *e) override;
0109     void forwardMouseReleaseEvent(QMouseEvent *event) override;
0110     void contextMenuEvent(QContextMenuEvent *e) override;
0111 
0112 private Q_SLOTS:
0113     void slotServiceUrlSelected(PimCommon::ShareServiceUrlManager::ServiceType type);
0114     void slotLinkHovered(const QString &link);
0115     void slotLoadStarted();
0116     void slotLoadFinished();
0117     void slotLinkClicked(const QUrl &url);
0118     void slotShowContextMenu(const QPoint &pos);
0119     void slotWebHitFinished(const WebEngineViewer::WebHitTestResult &result);
0120     void slotActivatePlugin(MessageViewer::ViewerPluginInterface *interface);
0121     void slotWebPageMutedOrAudibleChanged();
0122     void slotCheckedUrlFinished(const QUrl &url, WebEngineViewer::CheckPhishingUrlUtil::UrlStatus status);
0123 
0124 protected:
0125     void slotOpenLinkInBrowser();
0126     void slotOpenLinkInForegroundTab();
0127     void slotOpenLinkInBackgroundTab();
0128     ArticleViewerWebEnginePage *mPageEngine = nullptr;
0129     QList<QAction *> viewerPluginActionList(MessageViewer::ViewerPluginInterface::SpecificFeatureTypes features);
0130     WebEngineViewer::InterceptorManager *mNetworkAccessManager = nullptr;
0131     WebEngineViewer::LoadExternalReferencesUrlInterceptor *mExternalReference = nullptr;
0132     WebEngineViewer::BlockExternalResourcesUrlInterceptor *mBlockExternalReference = nullptr;
0133 
0134 private:
0135     void openSafeUrl(const QUrl &url);
0136     bool urlIsAMalwareButContinue();
0137     MousePressedButtonType mLastButtonClicked = LeftButton;
0138     MessageViewer::ViewerPluginToolManager *mViewerPluginToolManager = nullptr;
0139     WebEngineViewer::WebEngineAccessKey *mWebEngineViewAccessKey = nullptr;
0140 };
0141 }