File: abstractbrowserplugin.cpp

package info (click to toggle)
plasma-browser-integration 6.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,000 kB
  • sloc: cpp: 3,195; javascript: 2,553; xml: 127; python: 77; sh: 46; makefile: 16
file content (126 lines) | stat: -rw-r--r-- 2,941 bytes parent folder | download
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
    SPDX-FileCopyrightText: 2017 Kai Uwe Broulik <kde@privat.broulik.de>
    SPDX-FileCopyrightText: 2017 David Edmundson <davidedmundson@kde.org>

    SPDX-License-Identifier: MIT
*/

#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_protocolVersion(protocolVersion)
{
}

void AbstractBrowserPlugin::handleData(const QString &event, const QJsonObject &data)
{
    Q_UNUSED(event);
    Q_UNUSED(data);
}

QJsonObject AbstractBrowserPlugin::handleData(int serial, const QString &event, const QJsonObject &data)
{
    Q_UNUSED(serial);
    Q_UNUSED(event);
    Q_UNUSED(data);
    return QJsonObject();
}

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);
}

void AbstractBrowserPlugin::sendReply(int requestSerial, const QJsonObject &payload)
{
    QJsonObject data{
        {QStringLiteral("replyToSerial"), requestSerial},
    };

    if (!payload.isEmpty()) {
        data.insert(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);
}

QJsonObject AbstractBrowserPlugin::status() const
{
    return {};
}

QDebug AbstractBrowserPlugin::debug() const
{
    auto d = qDebug();
    QDebugStateSaver saver(d);
    d.nospace().noquote() << m_subsystem << ":";
    return d;
}

QString AbstractBrowserPlugin::subsystem() const
{
    return m_subsystem;
}

int AbstractBrowserPlugin::protocolVersion() const
{
    return m_protocolVersion;
}

bool AbstractBrowserPlugin::isLoaded() const
{
    return m_loaded;
}

void AbstractBrowserPlugin::setLoaded(bool loaded)
{
    m_loaded = loaded;
}

QJsonObject AbstractBrowserPlugin::settings() const
{
    return Settings::self().settingsForPlugin(m_subsystem);
}

QByteArray AbstractBrowserPlugin::dataFromDataUrl(const QString &urlString)
{
    if (!urlString.startsWith(QLatin1String("data:"))) {
        return QByteArray();
    }

    const auto b64start = urlString.indexOf(QLatin1Char(','));
    if (b64start == -1) {
        qWarning() << "Invalid data URL format for" << urlString.left(30);
        return QByteArray();
    }

    const QByteArray b64 = QStringView(urlString).right(urlString.length() - b64start - 1).toLatin1();
    return QByteArray::fromBase64(b64);
}

#include "moc_abstractbrowserplugin.cpp"