File indexing completed on 2024-04-28 16:51:32

0001 /*
0002     SPDX-FileCopyrightText: 2017 Kai Uwe Broulik <kde@privat.broulik.de>
0003     SPDX-FileCopyrightText: 2017 David Edmundson <davidedmundson@kde.org>
0004 
0005     SPDX-License-Identifier: MIT
0006 */
0007 
0008 #pragma once
0009 
0010 #include <QDebug>
0011 #include <QJsonObject>
0012 #include <QObject>
0013 
0014 class AbstractBrowserPlugin : public QObject
0015 {
0016     Q_OBJECT
0017 public:
0018     ~AbstractBrowserPlugin() override = default;
0019     QString subsystem() const;
0020     int protocolVersion() const;
0021 
0022     bool isLoaded() const;
0023     // FIXME this should not be public but we need to change it from main.cpp
0024     void setLoaded(bool loaded);
0025 
0026     /**
0027      * Lets the plugin add additional status information to the getSubsystemStatus request
0028      *
0029      * E.g. whether a library dependency or external binary is present.
0030      */
0031     virtual QJsonObject status() const;
0032 
0033 protected:
0034     /*
0035      * @arg subsystemId
0036      * The name of the plugin. This will be used for the "subsystem" parameter for all data sent
0037      *
0038      * @arg protocolVersion
0039      * As the browser extension will be shipped separately to the native plugin a user could have incompatiable setups
0040      * Here we inform the browser of the protocol used so if we do ever changed the native API we can at least detect it on the JS side and handle it
0041      */
0042     AbstractBrowserPlugin(const QString &subsystemId, int protocolVersion, QObject *parent);
0043 
0044     virtual void handleData(const QString &event, const QJsonObject &data);
0045     virtual QJsonObject handleData(int serial, const QString &event, const QJsonObject &data);
0046 
0047     virtual bool onLoad();
0048     virtual bool onUnload();
0049 
0050     virtual void onSettingsChanged(const QJsonObject &newSettings);
0051 
0052     void sendData(const QString &action, const QJsonObject &payload = QJsonObject());
0053 
0054     void sendReply(int requestSerial, const QJsonObject &payload = QJsonObject());
0055 
0056     QDebug debug() const;
0057 
0058     QJsonObject settings() const;
0059 
0060     friend class PluginManager;
0061 
0062 private:
0063     QString m_subsystem;
0064     int m_protocolVersion;
0065     bool m_loaded = false;
0066 };