Commit a836d827 authored by Erik Jensen's avatar Erik Jensen Committed by Commit Bot

remoting: Fix reading UTF-8 clipboard data on Linux.

https://crrev.com/c/2410841 updated x_server_clipboard.cc to use Xproto,
but introduced two errors that broke reading the clipboard in UTF-8
format.

The first error has to do with how 32-bit properties are returned. With
Xlib, such properties are returned as longs regardless of the platform,
meaning they are actually returned as 64-bit values on 64-bit
architectures. Xproto, however, always returns them as 32-bit values.
The clipboard code, however, was still expecting longs. This change
updates the clipboard code to expect 32-bit values as returned by
Xproto.

The second error was a mistranscription when converting
RequestSelectionTargets from XConvertSelection to the equivalent Xproto
call.

Bug: 1149033
Change-Id: Ib3fe97fcbd0b0579a578858796e084901dd8a360
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2537977Reviewed-by: default avatarJamie Walch <jamiewalch@chromium.org>
Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Commit-Queue: Erik Jensen <rkjnsn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827673}
parent 937b8bbc
...@@ -332,15 +332,9 @@ bool XServerClipboard::HandleSelectionTargetsEvent( ...@@ -332,15 +332,9 @@ bool XServerClipboard::HandleSelectionTargetsEvent(
auto selection = event.selection; auto selection = event.selection;
if (event.property == targets_atom_) { if (event.property == targets_atom_) {
if (data && format == 32) { if (data && format == 32) {
// The XGetWindowProperty man-page specifies that the returned const uint32_t* targets = static_cast<const uint32_t*>(data);
// property data will be an array of |long|s in the case where
// |format| == 32. Although the items are 32-bit values (as stored and
// sent over the X protocol), Xlib presents the data to the client as an
// array of |long|s, with zero-padding on a 64-bit system where |long|
// is bigger than 32 bits.
const long* targets = static_cast<const long*>(data);
for (int i = 0; i < item_count; i++) { for (int i = 0; i < item_count; i++) {
if (targets[i] == static_cast<long>(utf8_string_atom_)) { if (targets[i] == static_cast<uint32_t>(utf8_string_atom_)) {
RequestSelectionString(selection, utf8_string_atom_); RequestSelectionString(selection, utf8_string_atom_);
return false; return false;
} }
...@@ -377,8 +371,7 @@ void XServerClipboard::NotifyClipboardText(const std::string& text) { ...@@ -377,8 +371,7 @@ void XServerClipboard::NotifyClipboardText(const std::string& text) {
void XServerClipboard::RequestSelectionTargets(x11::Atom selection) { void XServerClipboard::RequestSelectionTargets(x11::Atom selection) {
connection_->ConvertSelection({clipboard_window_, selection, targets_atom_, connection_->ConvertSelection({clipboard_window_, selection, targets_atom_,
selection_string_atom_, targets_atom_, x11::Time::CurrentTime});
x11::Time::CurrentTime});
} }
void XServerClipboard::RequestSelectionString(x11::Atom selection, void XServerClipboard::RequestSelectionString(x11::Atom selection,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment