From 498bde9c6e2dd3c823a983eb5500b226d1e2fe18 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Mon, 29 Aug 2022 17:26:08 +0300 Subject: [PATCH] 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 --- src/xwayland/drag_x.cpp | 8 ++-- src/xwayland/transfer.cpp | 90 +-------------------------------------- src/xwayland/transfer.h | 28 +----------- 3 files changed, 8 insertions(+), 118 deletions(-) diff --git a/src/xwayland/drag_x.cpp b/src/xwayland/drag_x.cpp index 3169c2368b..9b3944b663 100644 --- a/src/xwayland/drag_x.cpp +++ b/src/xwayland/drag_x.cpp @@ -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); } diff --git a/src/xwayland/transfer.cpp b/src/xwayland/transfer.cpp index 7035bde8ca..4bb45dac76 100644 --- a/src/xwayland/transfer.cpp +++ b/src/xwayland/transfer.cpp @@ -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(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(); diff --git a/src/xwayland/transfer.h b/src/xwayland/transfer.h index 0b68d1006c..7491c838e9 100644 --- a/src/xwayland/transfer.h +++ b/src/xwayland/transfer.h @@ -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. */