xwayland: Remove text/x-moz-url and _NETSCAPE_URL mime converters

The xwayland data bridge tries to be helpful and convert some mimes.
However, that mime conversion code is buggy, and it appears like
Thunderbird can send text/x-moz-url in format, which our bridge doesn't
handle properly.

However, mime type conversion is completely out of the scope of the
compositor. We also can't keep up with various mime types. Given that
X11 clients already must handle _NETSCAPE_URL and text/x-moz-url, this
change removes our mime type conversion helpers. For the record, neither
wlroots-based compositors nor mutter perform such conversion either.

With this change, kwin will send text/x-moz-url and _NETSCAPE_URL data
as is.

BUG: 458226
This commit is contained in:
Vlad Zahorodnii 2022-08-29 17:26:08 +03:00
parent 0bf1183286
commit 498bde9c6e
3 changed files with 8 additions and 118 deletions

View file

@ -44,10 +44,12 @@ static QStringList atomToMimeTypes(xcb_atom_t atom)
mimeTypes << QString::fromLatin1("text/plain;charset=utf-8");
} else if (atom == atoms->text) {
mimeTypes << QString::fromLatin1("text/plain");
} else if (atom == atoms->uri_list || atom == atoms->netscape_url || atom == atoms->moz_url) {
// We identify netscape and moz format as less detailed formats text/uri-list,
// text/x-uri and accept the information loss.
} else if (atom == atoms->uri_list) {
mimeTypes << QString::fromLatin1("text/uri-list") << QString::fromLatin1("text/x-uri");
} else if (atom == atoms->moz_url) {
mimeTypes << QStringLiteral("text/x-moz-url");
} else if (atom == atoms->netscape_url) {
mimeTypes << QStringLiteral("_NETSCAPE_URL");
} else {
mimeTypes << Selection::atomName(atom);
}

View file

@ -330,13 +330,8 @@ bool TransferXtoWl::handleSelectionNotify(xcb_selection_notify_event_t *event)
return true;
}
if (event->target == atoms->netscape_url) {
m_receiver = new NetscapeUrlReceiver;
} else if (event->target == atoms->moz_url) {
m_receiver = new MozUrlReceiver;
} else {
m_receiver = new DataReceiver;
}
m_receiver = new DataReceiver;
startTransfer();
return true;
}
@ -447,87 +442,6 @@ void DataReceiver::partRead(int length)
}
}
void NetscapeUrlReceiver::setData(const char *value, int length)
{
auto origData = QByteArray::fromRawData(value, length);
if (origData.indexOf('\n') == -1) {
// there are no line breaks, not in Netscape url format or empty,
// but try anyway
setDataInternal(origData);
return;
}
// remove every second line
QByteArray data;
int start = 0;
bool remLine = false;
while (start < length) {
auto part = QByteArray::fromRawData(value + start, length - start);
const int linebreak = part.indexOf('\n');
if (linebreak == -1) {
// no more linebreaks, end of work
if (!remLine) {
// append the rest
data.append(part);
}
break;
}
if (remLine) {
// no data to add, but add a linebreak for the next line
data.append('\n');
} else {
// add data till before linebreak
data.append(part.data(), linebreak);
}
remLine = !remLine;
start = linebreak + 1;
}
setDataInternal(data);
}
void MozUrlReceiver::setData(const char *value, int length)
{
// represent as QByteArray (guaranteed '\0'-terminated)
const auto origData = QByteArray::fromRawData(value, length);
// text/x-moz-url data is sent in utf-16 - copies the content
// and converts it into 8 byte representation
const auto byteData = QString::fromUtf16(reinterpret_cast<const char16_t *>(origData.data())).toLatin1();
if (byteData.indexOf('\n') == -1) {
// there are no line breaks, not in text/x-moz-url format or empty,
// but try anyway
setDataInternal(byteData);
return;
}
// remove every second line
QByteArray data;
int start = 0;
bool remLine = false;
while (start < length) {
auto part = QByteArray::fromRawData(byteData.data() + start, byteData.size() - start);
const int linebreak = part.indexOf('\n');
if (linebreak == -1) {
// no more linebreaks, end of work
if (!remLine) {
// append the rest
data.append(part);
}
break;
}
if (remLine) {
// no data to add, but add a linebreak for the next line
data.append('\n');
} else {
// add data till before linebreak
data.append(part.data(), linebreak);
}
remLine = !remLine;
start = linebreak + 1;
}
setDataInternal(data);
}
void TransferXtoWl::dataSourceWrite()
{
QByteArray property = m_receiver->data();

View file

@ -155,43 +155,17 @@ public:
void transferFromProperty(xcb_get_property_reply_t *reply);
virtual void setData(const char *value, int length);
void setData(const char *value, int length);
QByteArray data() const;
void partRead(int length);
protected:
void setDataInternal(QByteArray data)
{
m_data = data;
}
private:
xcb_get_property_reply_t *m_propertyReply = nullptr;
int m_propertyStart = 0;
QByteArray m_data;
};
/**
* Compatibility receiver for clients only
* supporting the NETSCAPE_URL scheme (Firefox)
*/
class NetscapeUrlReceiver : public DataReceiver
{
public:
void setData(const char *value, int length) override;
};
/**
* Compatibility receiver for clients only
* supporting the text/x-moz-url scheme (Chromium on own drags)
*/
class MozUrlReceiver : public DataReceiver
{
public:
void setData(const char *value, int length) override;
};
/**
* Represents a transfer from an X window to a Wayland native client.
*/