1 #ifndef WEBPAGE_H
2 #define WEBPAGE_H
3 #ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
4 
5 #include "./webviewdefs.h"
6 #include "./webviewincludes.h"
7 
8 #include "../global.h"
9 
10 QT_FORWARD_DECLARE_CLASS(QAuthenticator)
QT_FORWARD_DECLARE_CLASS(QNetworkReply)11 QT_FORWARD_DECLARE_CLASS(QNetworkReply)
12 QT_FORWARD_DECLARE_CLASS(QNetworkRequest)
13 QT_FORWARD_DECLARE_CLASS(QSslError)
14 
15 namespace QtGui {
16 
17 class WebViewDialog;
18 
19 class SYNCTHINGWIDGETS_EXPORT WebPage : public SYNCTHINGWIDGETS_WEB_PAGE {
20     Q_OBJECT
21 public:
22 #ifdef SYNCTHINGWIDGETS_USE_WEBENGINE
23     WebPage(QWebEngineProfile *profile = nullptr, WebViewDialog *dlg = nullptr, SYNCTHINGWIDGETS_WEB_VIEW *view = nullptr);
24 #else
25     WebPage(WebViewDialog *dlg = nullptr, SYNCTHINGWIDGETS_WEB_VIEW *view = nullptr);
26 #endif
27 
28     static bool isSamePage(const QUrl &url1, const QUrl &url2);
29 
30 protected:
31     SYNCTHINGWIDGETS_WEB_PAGE *createWindow(WebWindowType type) override;
32 #ifdef SYNCTHINGWIDGETS_USE_WEBENGINE
33     bool certificateError(const QWebEngineCertificateError &certificateError) override;
34     bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) override;
35     void javaScriptConsoleMessage(
36         QWebEnginePage::JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID) override;
37 #else
38     bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type) override;
39     void javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID) override;
40 #endif
41 
42 private Q_SLOTS:
43     void delegateNewWindowToExternalBrowser(const QUrl &url);
44     void supplyCredentials(const QUrl &requestUrl, QAuthenticator *authenticator);
45     void supplyCredentials(QNetworkReply *reply, QAuthenticator *authenticator);
46     void supplyCredentials(QAuthenticator *authenticator);
47 #ifdef SYNCTHINGWIDGETS_USE_WEBKIT
48     void handleSslErrors(QNetworkReply *, const QList<QSslError> &errors);
49 #endif
50     void injectJavaScripts(bool ok);
51     void processJavaScriptConsoleMessage(const QString &message);
52     void injectJavaScript(const QString &scriptSource);
53     void showFolderPathSelection(const QString &defaultDir);
54 
55 private:
56     static bool handleNavigationRequest(const QUrl &currentUrl, const QUrl &url);
57 
58     WebViewDialog *m_dlg;
59     SYNCTHINGWIDGETS_WEB_VIEW *m_view;
60 };
61 } // namespace QtGui
62 
63 #endif // SYNCTHINGWIDGETS_NO_WEBVIEW
64 #endif // WEBPAGE_H
65