Skip to content

Commit

Permalink
Updating the clipboard portal with new method signatures that changed…
Browse files Browse the repository at this point in the history
… upstream. Specifically the parameters have been updated for:

SelectionWriteDone
SelectionWrite
RequestClipboard

Bug: 1381233
Change-Id: I2e79c20daea3a18f21937edc9d05017c5d083d19
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4250363
Commit-Queue: Max Booth <maxbooth@chromium.org>
Reviewed-by: Lambros Lambrou <lambroslambrou@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1105908}
  • Loading branch information
maxhbooth authored and Chromium LUCI CQ committed Feb 15, 2023
1 parent a6e9022 commit a077f96
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 21 deletions.
6 changes: 5 additions & 1 deletion remoting/host/linux/clipboard_portal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ void ClipboardPortal::RequestClipboard() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
HOST_LOG << "Request clipboard for the remote desktop session.";

GVariantBuilder options_builder;
g_variant_builder_init(&options_builder, G_VARIANT_TYPE_VARDICT);

g_dbus_proxy_call(
proxy_, "RequestClipboard", g_variant_new("(o)", session_handle_.c_str()),
proxy_, "RequestClipboard",
g_variant_new("(oa{sv})", session_handle_.c_str(), &options_builder),
G_DBUS_CALL_FLAGS_NONE, /*timeout=*/-1, cancellable_,
reinterpret_cast<GAsyncReadyCallback>(OnClipboardRequest), this);
}
Expand Down
57 changes: 39 additions & 18 deletions remoting/host/linux/clipboard_portal_injector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,20 @@ void ClipboardPortalInjector::SelectionWrite() {
DCHECK(proxy_);
DCHECK(cancellable_);
DCHECK(!session_handle_.empty());
DCHECK(write_serial_);
DCHECK(!write_serials_.empty());
DCHECK(!write_data_.empty());

GVariantBuilder serials_builder;
g_variant_builder_init(&serials_builder, G_VARIANT_TYPE("au"));
for (auto serial : write_serials_) {
g_variant_builder_add(&serials_builder, "u", serial);
}
write_serials_.clear();

Scoped<GError> error;
g_dbus_proxy_call_with_unix_fd_list(
proxy_, "SelectionWrite",
g_variant_new("(ou)", session_handle_.c_str(), write_serial_),
g_variant_new("(oau)", session_handle_.c_str(), &serials_builder),
G_DBUS_CALL_FLAGS_NONE, /*timeout=*/-1, nullptr, cancellable_,
reinterpret_cast<GAsyncReadyCallback>(OnSelectionWriteCallback), this);
}
Expand All @@ -178,6 +185,7 @@ void ClipboardPortalInjector::OnSelectionWriteCallback(GDBusProxy* proxy,

Scoped<GError> error;
Scoped<GUnixFDList> outlist;
std::unordered_map<int, gboolean> request_successes;

Scoped<GVariant> variant(g_dbus_proxy_call_with_unix_fd_list_finish(
proxy, outlist.receive(), result, error.receive()));
Expand All @@ -186,32 +194,45 @@ void ClipboardPortalInjector::OnSelectionWriteCallback(GDBusProxy* proxy,
return;
}

int32_t index;
g_variant_get(variant.get(), "(h)", &index);

base::ScopedFD fd(g_unix_fd_list_get(outlist.get(), index, error.receive()));

gboolean write_succeeded = false;
if (!fd.is_valid()) {
LOG(ERROR) << "Failed to get file descriptor from the list: "
<< error->message;
} else {
write_succeeded = base::WriteFileDescriptor(fd.get(), that->write_data_);
int32_t fd_id;
guint serial;
GVariantIter iterator;
g_variant_iter_init(&iterator, g_variant_get_child_value(variant.get(), 0));
while (g_variant_iter_loop(&iterator, "{uh}", &serial, &fd_id)) {
base::ScopedFD fd(
g_unix_fd_list_get(outlist.get(), fd_id, error.receive()));

request_successes[serial] = false;
if (!fd.is_valid()) {
LOG(ERROR) << "Failed to get file descriptor from the list: "
<< error->message;
} else {
request_successes[serial] =
base::WriteFileDescriptor(fd.get(), that->write_data_);
LOG(ERROR) << "Failed to write clipboard data to file descriptor";
}
}

that->SelectionWriteDone(write_succeeded);
that->SelectionWriteDone(request_successes);
}

void ClipboardPortalInjector::SelectionWriteDone(gboolean success) {
void ClipboardPortalInjector::SelectionWriteDone(
const std::unordered_map<int, gboolean>& request_successes) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(proxy_);
DCHECK(cancellable_);
DCHECK(!session_handle_.empty());
DCHECK(write_serial_);

GVariantBuilder request_successes_builder;
g_variant_builder_init(&request_successes_builder, G_VARIANT_TYPE("a{ub}"));
for (const auto& [serial, success] : request_successes) {
g_variant_builder_add(&request_successes_builder, "{ub}", serial, success);
}

g_dbus_proxy_call(
proxy_, "SelectionWriteDone",
g_variant_new("(oub)", session_handle_.c_str(), write_serial_, success),
g_variant_new("(oa{ub})", session_handle_.c_str(),
&request_successes_builder),
G_DBUS_CALL_FLAGS_NONE, /*timeout=*/-1, cancellable_,
reinterpret_cast<GAsyncReadyCallback>(OnSelectionWriteDoneCallback),
this);
Expand Down Expand Up @@ -332,7 +353,7 @@ void ClipboardPortalInjector::OnSelectionTransferSignal(
g_variant_get(parameters, "(osu)", /*session_handle*/ nullptr,
/*mime_type*/ nullptr, &serial);

that->write_serial_ = serial;
that->write_serials_.insert(serial);

that->SelectionWrite();
}
Expand Down
7 changes: 5 additions & 2 deletions remoting/host/linux/clipboard_portal_injector.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <gio/gio.h>

#include <map>
#include <unordered_set>

#include "base/functional/callback.h"
Expand Down Expand Up @@ -44,7 +45,8 @@ class ClipboardPortalInjector {
private:
void SelectionRead(std::string mime_type);
void SelectionWrite();
void SelectionWriteDone(gboolean success);
void SelectionWriteDone(
const std::unordered_map<int, gboolean>& request_successes);
void SubscribeClipboardSignals();
void UnsubscribeSignalHandlers();

Expand Down Expand Up @@ -89,7 +91,8 @@ class ClipboardPortalInjector {
std::unordered_set<std::string> writable_mime_type_set_
GUARDED_BY_CONTEXT(sequence_checker_);
std::string write_data_ GUARDED_BY_CONTEXT(sequence_checker_);
guint write_serial_ GUARDED_BY_CONTEXT(sequence_checker_);
std::unordered_set<guint> write_serials_
GUARDED_BY_CONTEXT(sequence_checker_);
std::unordered_set<std::string> readable_mime_type_set_
GUARDED_BY_CONTEXT(sequence_checker_);

Expand Down

0 comments on commit a077f96

Please sign in to comment.