Falkon Develop
Cross-platform Qt-based web browser
webpage.h
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#ifndef WEBPAGE_H
19#define WEBPAGE_H
20
21#include <QWebEnginePage>
22#include <QWebEngineScript>
23#include <QWebEngineFullScreenRequest>
24#include <QPrinter>
25#include <QVector>
26#include <QElapsedTimer>
27
28#include "qzcommon.h"
29
30class QEventLoop;
31class QWebEngineDownloadItem;
32class QWebEngineRegisterProtocolHandlerRequest;
33
34class WebView;
37
38class FALKON_EXPORT WebPage : public QWebEnginePage
39{
40 Q_OBJECT
41
42public:
43 enum JsWorld {
44 UnsafeJsWorld = QWebEngineScript::MainWorld,
45 SafeJsWorld = QWebEngineScript::ApplicationWorld
46 };
47
48 explicit WebPage(QObject* parent = nullptr);
49 ~WebPage() override;
50
51 WebView *view() const;
52
53 bool execPrintPage(QPrinter *printer, int timeout = 1000);
54 QVariant execJavaScript(const QString &scriptSource, quint32 worldId = UnsafeJsWorld, int timeout = 500);
55
56 QPointF mapToViewport(const QPointF &pos) const;
57 WebHitTestResult hitTestContent(const QPoint &pos) const;
58
59 void scroll(int x, int y);
60 void setScrollPosition(const QPointF &pos);
61
62 bool javaScriptPrompt(const QUrl &securityOrigin, const QString &msg, const QString &defaultValue, QString* result) override;
63 bool javaScriptConfirm(const QUrl &securityOrigin, const QString &msg) override;
64 void javaScriptAlert(const QUrl &securityOrigin, const QString &msg) override;
65 void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID) override;
66
67 QStringList autoFillUsernames() const;
68
69 QUrl registerProtocolHandlerRequestUrl() const;
70 QString registerProtocolHandlerRequestScheme() const;
71
72 bool isRunningLoop();
73
74 bool isLoading() const;
75
76 static QStringList internalSchemes();
77 static QStringList supportedSchemes();
78 static void addSupportedScheme(const QString &scheme);
79 static void removeSupportedScheme(const QString &scheme);
80
81Q_SIGNALS:
82 void privacyChanged(bool status);
84 void navigationRequestAccepted(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame);
85
86protected Q_SLOTS:
87 void progress(int prog);
88 void finished();
89
90private Q_SLOTS:
91 void urlChanged(const QUrl &url);
92 void watchedFileChanged(const QString &file);
93 void windowCloseRequested();
94 void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest);
95 void featurePermissionRequested(const QUrl &origin, const QWebEnginePage::Feature &feature);
96 void renderProcessTerminated(QWebEnginePage::RenderProcessTerminationStatus terminationStatus, int exitCode);
97 void onCertificateError(QWebEngineCertificateError error);
98
99private:
100 bool acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame) override;
101
102 QStringList chooseFiles(FileSelectionMode mode, const QStringList &oldFiles, const QStringList &acceptedMimeTypes) override;
103 QWebEnginePage* createWindow(QWebEnginePage::WebWindowType type) override;
104
105 void handleUnknownProtocol(const QUrl &url);
106 void desktopServicesOpen(const QUrl &url);
107
108 static QString s_lastUploadLocation;
109 static QUrl s_lastUnsupportedUrl;
110 static QElapsedTimer s_lastUnsupportedUrlTime;
111
112 DelayedFileWatcher* m_fileWatcher;
113 QEventLoop* m_runningLoop;
114
115 QStringList m_autoFillUsernames;
116 QWebEngineRegisterProtocolHandlerRequest *m_registerProtocolHandlerRequest = nullptr;
117
118 int m_loadProgress;
119 bool m_blockAlerts;
120 bool m_secureStatus;
121
122 QMetaObject::Connection m_contentsResizedConnection;
123
124 friend class WebView;
125};
126
127#endif // WEBPAGE_H
void privacyChanged(bool status)
void printRequested()
void navigationRequestAccepted(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
JsWorld
Definition: webpage.h:43
#define FALKON_EXPORT
Definition: qzcommon.h:28