From ea20e95cdc2f17155b914373e1adb31acc508280 Mon Sep 17 00:00:00 2001 From: Alex Cooper Date: Wed, 10 Aug 2022 15:53:06 -0700 Subject: [PATCH] Fix improper cast from PipeWire portal to RequestResponse When ScreencastPortal::OnStartRequestResponseSignal receives either a non-zero response code or is missing the response data, it would directly cast this to a RequestResponse. However, this direct cast is an error. Per the documentation, the response signal returns the following values with their corresponding meanings: 0 - Success 1 - User Cancelled 2 - Error The RequestResponse enum however, has "kUnknown" as 0, and thus "kSuccess" as 1 (with all other values also shifted up by 1 value). This means that when the portal was cancelled, we were still receiving RequestResponse::kSuccess. This fixes the issue by removing the improper cast and adding a translation function. This function is local for now since no where else attempted to cast values to a RequestResponse; but can be moved if the need arises. Fixed: chromium:1351824 Change-Id: I4cd44d90055147c9592d590c7969dcfc3297a3d9 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/271240 Commit-Queue: Alexander Cooper Auto-Submit: Alexander Cooper Reviewed-by: Tomas Gunnarsson Cr-Commit-Position: refs/heads/main@{#37755} --- .../linux/wayland/screencast_portal.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/modules/desktop_capture/linux/wayland/screencast_portal.cc b/modules/desktop_capture/linux/wayland/screencast_portal.cc index d723e37675..46668d80d1 100644 --- a/modules/desktop_capture/linux/wayland/screencast_portal.cc +++ b/modules/desktop_capture/linux/wayland/screencast_portal.cc @@ -30,6 +30,21 @@ using xdg_portal::SetupSessionRequestHandlers; using xdg_portal::StartSessionRequest; using xdg_portal::TearDownSession; +RequestResponse ToRequestResponseFromSignal(uint32_t signal_response) { + // See: + // https://docs.flatpak.org/en/latest/portal-api-reference.html#gdbus-signal-org-freedesktop-portal-Request.Response + switch (signal_response) { + case 0: + return RequestResponse::kSuccess; + case 1: + return RequestResponse::kUserCancelled; + case 2: + return RequestResponse::kError; + default: + return RequestResponse::kUnknown; + } +} + } // namespace ScreenCastPortal::ScreenCastPortal( @@ -342,7 +357,7 @@ void ScreenCastPortal::OnStartRequestResponseSignal(GDBusConnection* connection, response_data.receive()); if (portal_response || !response_data) { RTC_LOG(LS_ERROR) << "Failed to start the screen cast session."; - that->OnPortalDone(static_cast(portal_response)); + that->OnPortalDone(ToRequestResponseFromSignal(portal_response)); return; }