1 /* 2 * Copyright 2022 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_PORTAL_XDG_DESKTOP_PORTAL_UTILS_H_ 12 #define MODULES_PORTAL_XDG_DESKTOP_PORTAL_UTILS_H_ 13 14 #include <gio/gio.h> 15 #include <stdint.h> 16 17 #include <string> 18 #include <vector> 19 20 #include "absl/strings/string_view.h" 21 #include "modules/portal/portal_request_response.h" 22 #include "modules/portal/scoped_glib.h" 23 #include "modules/portal/xdg_session_details.h" 24 #include "rtc_base/checks.h" 25 #include "rtc_base/logging.h" 26 27 namespace webrtc { 28 namespace xdg_portal { 29 30 constexpr char kDesktopBusName[] = "org.freedesktop.portal.Desktop"; 31 constexpr char kDesktopObjectPath[] = "/org/freedesktop/portal/desktop"; 32 constexpr char kDesktopRequestObjectPath[] = 33 "/org/freedesktop/portal/desktop/request"; 34 constexpr char kSessionInterfaceName[] = "org.freedesktop.portal.Session"; 35 constexpr char kRequestInterfaceName[] = "org.freedesktop.portal.Request"; 36 constexpr char kScreenCastInterfaceName[] = "org.freedesktop.portal.ScreenCast"; 37 38 using ProxyRequestCallback = void (*)(GObject*, GAsyncResult*, gpointer); 39 using SessionRequestCallback = void (*)(GDBusProxy*, GAsyncResult*, gpointer); 40 using SessionRequestResponseSignalHandler = void (*)(GDBusConnection*, 41 const char*, 42 const char*, 43 const char*, 44 const char*, 45 GVariant*, 46 gpointer); 47 using StartRequestResponseSignalHandler = void (*)(GDBusConnection*, 48 const char*, 49 const char*, 50 const char*, 51 const char*, 52 GVariant*, 53 gpointer); 54 using SessionStartRequestedHandler = void (*)(GDBusProxy*, 55 GAsyncResult*, 56 gpointer); 57 58 std::string RequestResponseToString(RequestResponse request); 59 60 RequestResponse RequestResponseFromPortalResponse(uint32_t portal_response); 61 62 // Returns a string path for signal handle based on the provided connection and 63 // token. 64 std::string PrepareSignalHandle(absl::string_view token, 65 GDBusConnection* connection); 66 67 // Sets up the callback to execute when a response signal is received for the 68 // given object. 69 uint32_t SetupRequestResponseSignal(absl::string_view object_path, 70 const GDBusSignalCallback callback, 71 gpointer user_data, 72 GDBusConnection* connection); 73 74 void RequestSessionProxy(absl::string_view interface_name, 75 const ProxyRequestCallback proxy_request_callback, 76 GCancellable* cancellable, 77 gpointer user_data); 78 79 void SetupSessionRequestHandlers( 80 absl::string_view portal_prefix, 81 const SessionRequestCallback session_request_callback, 82 const SessionRequestResponseSignalHandler request_response_signale_handler, 83 GDBusConnection* connection, 84 GDBusProxy* proxy, 85 GCancellable* cancellable, 86 std::string& portal_handle, 87 guint& session_request_signal_id, 88 gpointer user_data); 89 90 void StartSessionRequest( 91 absl::string_view prefix, 92 absl::string_view session_handle, 93 const StartRequestResponseSignalHandler signal_handler, 94 const SessionStartRequestedHandler session_started_handler, 95 GDBusProxy* proxy, 96 GDBusConnection* connection, 97 GCancellable* cancellable, 98 guint& start_request_signal_id, 99 std::string& start_handle, 100 gpointer user_data); 101 102 // Tears down the portal session and cleans up related objects. 103 void TearDownSession(absl::string_view session_handle, 104 GDBusProxy* proxy, 105 GCancellable* cancellable, 106 GDBusConnection* connection); 107 108 } // namespace xdg_portal 109 } // namespace webrtc 110 111 #endif // MODULES_PORTAL_XDG_DESKTOP_PORTAL_UTILS_H_ 112