diff --git a/host/abstractbrowserplugin.cpp b/host/abstractbrowserplugin.cpp index 5e0b7aab..f6c02736 100644 --- a/host/abstractbrowserplugin.cpp +++ b/host/abstractbrowserplugin.cpp @@ -1,96 +1,97 @@ /* Copyright (C) 2017 by Kai Uwe Broulik Copyright (C) 2017 by David Edmundson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "abstractbrowserplugin.h" #include "connection.h" #include "settings.h" AbstractBrowserPlugin::AbstractBrowserPlugin::AbstractBrowserPlugin(const QString& subsystemId, int protocolVersion, QObject* parent): QObject(parent), - m_subsystem(subsystemId) + m_subsystem(subsystemId), + m_protocolVersion(protocolVersion) { } void AbstractBrowserPlugin::handleData(const QString& event, const QJsonObject& data) { Q_UNUSED(event); Q_UNUSED(data); } void AbstractBrowserPlugin::sendData(const QString &action, const QJsonObject &payload) { QJsonObject data; data[QStringLiteral("subsystem")] = m_subsystem; data[QStringLiteral("action")] = action; if (!payload.isEmpty()) { data[QStringLiteral("payload")] = payload; } Connection::self()->sendData(data); } bool AbstractBrowserPlugin::onLoad() { return true; } bool AbstractBrowserPlugin::onUnload() { return true; } void AbstractBrowserPlugin::onSettingsChanged(const QJsonObject &newSettings) { Q_UNUSED(newSettings); } QDebug AbstractBrowserPlugin::debug() const { auto d = qDebug(); d << m_subsystem << ": "; return d; } QString AbstractBrowserPlugin::subsystem() const { return m_subsystem; } bool AbstractBrowserPlugin::isLoaded() const { return m_loaded; } void AbstractBrowserPlugin::setLoaded(bool loaded) { if (m_loaded == loaded) { return; } m_loaded = loaded; } QJsonObject AbstractBrowserPlugin::settings() const { return Settings::self().settingsForPlugin(m_subsystem); } diff --git a/host/abstractbrowserplugin.h b/host/abstractbrowserplugin.h index f53733a5..365be818 100644 --- a/host/abstractbrowserplugin.h +++ b/host/abstractbrowserplugin.h @@ -1,64 +1,65 @@ /* Copyright (C) 2017 by Kai Uwe Broulik Copyright (C) 2017 by David Edmundson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #pragma once #include #include #include class AbstractBrowserPlugin : public QObject { Q_OBJECT public: ~AbstractBrowserPlugin() = default; QString subsystem() const; virtual void handleData(const QString &event, const QJsonObject &data); virtual bool onLoad(); virtual bool onUnload(); virtual void onSettingsChanged(const QJsonObject &newSettings); bool isLoaded() const; // FIXME this should not be public but we need to change it from main.cpp void setLoaded(bool loaded); 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); void sendData(const QString &action, const QJsonObject &payload = QJsonObject()); QDebug debug() const; QJsonObject settings() const; private: QString m_subsystem; + int m_protocolVersion; bool m_loaded = false; };