1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
/*
SPDX-FileCopyrightText: 2017 Kai Uwe Broulik <kde@privat.broulik.de>
SPDX-FileCopyrightText: 2017 David Edmundson <davidedmundson@kde.org>
SPDX-License-Identifier: MIT
*/
#pragma once
#include <QDebug>
#include <QJsonObject>
#include <QObject>
class AbstractBrowserPlugin : public QObject
{
Q_OBJECT
public:
~AbstractBrowserPlugin() override = default;
QString subsystem() const;
int protocolVersion() const;
bool isLoaded() const;
// FIXME this should not be public but we need to change it from main.cpp
void setLoaded(bool loaded);
/**
* Lets the plugin add additional status information to the getSubsystemStatus request
*
* E.g. whether a library dependency or external binary is present.
*/
virtual QJsonObject status() const;
protected:
/*
* @arg subsystemId
* The name of the plugin. This will be used for the "subsystem" parameter for all data sent
*
* @arg protocolVersion
* As the browser extension will be shipped separately to the native plugin a user could have incompatiable setups
* 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
*/
AbstractBrowserPlugin(const QString &subsystemId, int protocolVersion, QObject *parent);
virtual void handleData(const QString &event, const QJsonObject &data);
virtual QJsonObject handleData(int serial, const QString &event, const QJsonObject &data);
virtual bool onLoad();
virtual bool onUnload();
virtual void onSettingsChanged(const QJsonObject &newSettings);
void sendData(const QString &action, const QJsonObject &payload = QJsonObject());
void sendReply(int requestSerial, const QJsonObject &payload = QJsonObject());
QDebug debug() const;
QJsonObject settings() const;
static QByteArray dataFromDataUrl(const QString &urlString);
friend class PluginManager;
private:
QString m_subsystem;
int m_protocolVersion;
bool m_loaded = false;
};
|