Falkon Develop
Cross-platform Qt-based web browser
qmlextensionscheme.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2018 Anmol Gautam <tarptaeya@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#include "qmlextensionscheme.h"
19#include "mainapplication.h"
20#include "networkmanager.h"
21#include <QWebEngineUrlRequestJob>
22#include <QQmlEngine>
23#include <QMap>
24
26 : QObject(parent)
27{
28 m_schemeHandler = new QmlExtensionSchemeHandler;
29 connect(m_schemeHandler, &QmlExtensionSchemeHandler::_requestStarted, this, [this](QWebEngineUrlRequestJob *job) {
30 auto *qmlRequest = new QmlWebEngineUrlRequestJob(job);
31 const QJSValue request = qmlEngine(this)->newQObject(qmlRequest);
32 Q_EMIT requestStarted(request);
33 });
34}
35
37{
38 mApp->networkManager()->unregisterExtensionSchemeHandler(m_schemeHandler);
39 m_schemeHandler->deleteLater();
40}
41
43{
44 mApp->networkManager()->registerExtensionSchemeHandler(m_name, m_schemeHandler);
45}
46
47QString QmlExtensionScheme::name() const
48{
49 return m_name;
50}
51
52void QmlExtensionScheme::setName(const QString &name)
53{
54 m_name = name;
55}
56
57void QmlExtensionSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job)
58{
59 Q_EMIT _requestStarted(job);
60}
void _requestStarted(QWebEngineUrlRequestJob *job)
void requestStarted(QWebEngineUrlRequestJob *job) override
QString name
extension scheme handle name
void componentComplete() override
QmlExtensionScheme(QObject *parent=nullptr)
void requestStarted(const QJSValue &request)
The signal emitted when the request to the scheme handle is started.
The QmlWebEngineUrlRequestJob class.
#define mApp