File indexing completed on 2025-01-26 04:57:25
0001 /* 0002 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "webengineviewer_export.h" 0010 #include <QWebEnginePage> 0011 class QWebEngineProfile; 0012 class QWebEngineDownloadRequest; 0013 class QPrinter; 0014 namespace WebEngineViewer 0015 { 0016 class WebHitTest; 0017 /** 0018 * @brief The WebEnginePage class 0019 * @author Laurent Montel <montel@kde.org> 0020 */ 0021 class WEBENGINEVIEWER_EXPORT WebEnginePage : public QWebEnginePage 0022 { 0023 Q_OBJECT 0024 public: 0025 /** 0026 * Constructor. 0027 * 0028 * A private QWebEngineProfile, only applying to this QWebEnginePage, 0029 * will be created to implement browser settings. It can be accessed via 0030 * @c profile(), but it should not be shared or reused unless care is 0031 * taken that the profile is not deleted until all of the QWebEnginePage's 0032 * belonging to it are deleted first. 0033 * 0034 * @param parent The parent object 0035 **/ 0036 explicit WebEnginePage(QObject *parent = nullptr); 0037 0038 /** 0039 * Constructor. 0040 * 0041 * The specified QWebEngineProfile will be used. See the description of 0042 * @c WebEnginePage(QObject *) and the API documentation of QWebEnginePage 0043 * for caution regarding the lifetime of the profile. 0044 * 0045 * @param profile The profile to be used 0046 * @param parent The parent object 0047 * @deprecated Use the single argument constructor, which creates and uses 0048 * a private profile. 0049 **/ 0050 #ifndef WEBENGINEVIEWER_NO_DEPRECATED 0051 explicit WEBENGINEVIEWER_DEPRECATED WebEnginePage(QWebEngineProfile *profile, QObject *parent = nullptr); 0052 #endif 0053 0054 /** 0055 * Destructor. If there is a private QWebEngineProfile then it will also 0056 * be destroyed. 0057 **/ 0058 ~WebEnginePage() override = default; 0059 0060 WebEngineViewer::WebHitTest *hitTestContent(const QPoint &pos); 0061 0062 void saveHtml(QWebEngineDownloadRequest *download); 0063 0064 [[nodiscard]] QPoint mapToViewport(const QPoint &pos) const; 0065 Q_SIGNALS: 0066 void urlClicked(const QUrl &url); 0067 void showConsoleMessage(const QString &message); 0068 0069 protected: 0070 bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) override; 0071 void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID) override; 0072 0073 private: 0074 WEBENGINEVIEWER_NO_EXPORT void init(); 0075 }; 0076 }