1 /************************************************************************** 2 * Otter Browser: Web browser controlled by the user, not vice-versa. 3 * Copyright (C) 2015 - 2021 Michal Dutkiewicz aka Emdek <michal@emdek.pl> 4 * Copyright (C) 2016 - 2017 Jan Bajer aka bajasoft <jbajer@gmail.com> 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 * 19 **************************************************************************/ 20 21 #ifndef OTTER_QTWEBENGINEPAGE_H 22 #define OTTER_QTWEBENGINEPAGE_H 23 24 #include "../../../../core/SessionsManager.h" 25 26 #include <QtWebEngineWidgets/QWebEnginePage> 27 28 namespace Otter 29 { 30 31 class QtWebEngineWebWidget; 32 class WebWidget; 33 34 class QtWebEnginePage final : public QWebEnginePage 35 { 36 Q_OBJECT 37 38 public: 39 struct HistoryEntryInformation 40 { 41 QIcon icon; 42 QDateTime timeVisited; 43 QPoint position; 44 quint64 identifier = 0; 45 int zoom = -1; 46 bool isValid = false; 47 }; 48 49 explicit QtWebEnginePage(bool isPrivate, QtWebEngineWebWidget *parent); 50 51 void setHistory(const WindowHistoryInformation &history); 52 QtWebEngineWebWidget* getWebWidget() const; 53 QString createScriptSource(const QString &path, const QStringList ¶meters = {}) const; 54 QVariant runScriptSource(const QString &script); 55 QVariant runScriptFile(const QString &path, const QStringList ¶meters = {}); 56 WindowHistoryInformation getHistory() const; 57 bool isPopup() const; 58 bool isViewingMedia() const; 59 60 protected: 61 void markAsPopup(); 62 void javaScriptAlert(const QUrl &url, const QString &message) override; 63 void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString ¬e, int line, const QString &source) override; 64 QWebEnginePage* createWindow(WebWindowType type) override; 65 QtWebEngineWebWidget* createWidget(SessionsManager::OpenHints hints); 66 QString createJavaScriptList(QStringList rules) const; 67 QStringList chooseFiles(FileSelectionMode mode, const QStringList &oldFiles, const QStringList &acceptedMimeTypes) override; 68 bool acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame) override; 69 bool javaScriptConfirm(const QUrl &url, const QString &message) override; 70 bool javaScriptPrompt(const QUrl &url, const QString &message, const QString &defaultValue, QString *result) override; 71 72 protected slots: 73 void validatePopup(const QUrl &url); 74 void handleLoadFinished(); 75 76 private: 77 QtWebEngineWebWidget *m_widget; 78 QVector<QtWebEnginePage*> m_popups; 79 QVector<HistoryEntryInformation> m_history; 80 QWebEnginePage::NavigationType m_previousNavigationType; 81 bool m_isIgnoringJavaScriptPopups; 82 bool m_isViewingMedia; 83 bool m_isPopup; 84 85 signals: 86 void requestedNewWindow(WebWidget *widget, SessionsManager::OpenHints hints, const QVariantMap ¶meters); 87 void requestedPopupWindow(const QUrl &parentUrl, const QUrl &popupUrl); 88 void aboutToNavigate(const QUrl &url, QWebEnginePage::NavigationType navigationType); 89 void viewingMediaChanged(bool isViewingMedia); 90 }; 91 92 } 93 94 #endif 95