File indexing completed on 2024-12-22 04:41:13

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #pragma once
0019 
0020 #include "schemehandlers/extensionschemehandler.h"
0021 #include "qmlwebengineurlrequestjob.h"
0022 #include <QQmlParserStatus>
0023 #include <QJSValue>
0024 
0025 class QmlExtensionSchemeHandler;
0026 
0027 /**
0028  * @brief The QmlExtensionScheme class, exposed to QML as ExtensionScheme
0029  */
0030 class QmlExtensionScheme : public QObject, public QQmlParserStatus
0031 {
0032     Q_OBJECT
0033     Q_INTERFACES(QQmlParserStatus)
0034     /**
0035      * @brief extension scheme handle name
0036      */
0037     Q_PROPERTY(QString name READ name WRITE setName)
0038 public:
0039     explicit QmlExtensionScheme(QObject *parent = nullptr);
0040     ~QmlExtensionScheme() override;
0041     void classBegin() override {}
0042     void componentComplete() override;
0043 Q_SIGNALS:
0044     /**
0045      * @brief The signal emitted when the request to the scheme handle is started
0046      * @param request of the type [QmlWebEngineUrlRequestJob](@ref QmlWebEngineUrlRequestJob)
0047      */
0048     void requestStarted(const QJSValue &request);
0049 private:
0050     QString m_name;
0051     QmlExtensionSchemeHandler *m_schemeHandler = nullptr;
0052 
0053     QString name() const;
0054     void setName(const QString &name);
0055 };
0056 
0057 class QmlExtensionSchemeHandler : public ExtensionSchemeHandler
0058 {
0059     Q_OBJECT
0060 public:
0061     void requestStarted(QWebEngineUrlRequestJob *job) override;
0062 Q_SIGNALS:
0063     void _requestStarted(QWebEngineUrlRequestJob *job);
0064 };