1 /**************************************************************************
2 * Otter Browser: Web browser controlled by the user, not vice-versa.
3 * Copyright (C) 2015 - 2019 Michal Dutkiewicz aka Emdek <michal@emdek.pl>
4 * Copyright (C) 2016 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_QTWEBENGINEWEBBACKEND_H
22 #define OTTER_QTWEBENGINEWEBBACKEND_H
23 
24 #include "../../../../core/WebBackend.h"
25 
26 #include <QtWebEngineWidgets/QWebEngineDownloadItem>
27 
28 namespace Otter
29 {
30 
31 class QtWebEnginePage;
32 class QtWebEngineUrlRequestInterceptor;
33 
34 class QtWebEngineWebBackend final : public WebBackend
35 {
36 	Q_OBJECT
37 
38 public:
39 	explicit QtWebEngineWebBackend(QObject *parent = nullptr);
40 
41 	WebWidget* createWidget(const QVariantMap &parameters, ContentsWidget *parent = nullptr) override;
42 	QString getName() const override;
43 	QString getTitle() const override;
44 	QString getDescription() const override;
45 	QString getVersion() const override;
46 	QString getEngineVersion() const override;
47 	QString getSslVersion() const override;
48 	QString getUserAgent(const QString &pattern = {}) const override;
49 #if QTWEBENGINECORE_VERSION < 0x050D00
50 	QStringList getBlockedElements(const QString &domain) const;
51 #endif
52 	QUrl getHomePage() const override;
53 	WebBackend::BackendCapabilities getCapabilities() const override;
54 	bool requestThumbnail(const QUrl &url, const QSize &size) override;
55 
56 protected slots:
57 	void handleDownloadRequested(QWebEngineDownloadItem *item);
58 	void handleOptionChanged(int identifier);
59 
60 private:
61 #if QTWEBENGINECORE_VERSION < 0x050D00
62 	QtWebEngineUrlRequestInterceptor *m_requestInterceptor;
63 #endif
64 	bool m_isInitialized;
65 
66 	static QString m_engineVersion;
67 	static QHash<QString, QString> m_userAgentComponents;
68 	static QMap<QString, QString> m_userAgents;
69 
70 friend class QtWebEnginePage;
71 };
72 
73 }
74 
75 #endif
76