1 /* 2 * Copyright (c) 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_DESKTOP_CAPTURE_LINUX_WAYLAND_SCREEN_CAPTURE_PORTAL_INTERFACE_H_ 12 #define MODULES_DESKTOP_CAPTURE_LINUX_WAYLAND_SCREEN_CAPTURE_PORTAL_INTERFACE_H_ 13 14 #include <gio/gio.h> 15 16 #include <string> 17 18 #include "modules/portal/portal_request_response.h" 19 #include "modules/portal/scoped_glib.h" 20 #include "modules/portal/xdg_desktop_portal_utils.h" 21 #include "modules/portal/xdg_session_details.h" 22 23 namespace webrtc { 24 namespace xdg_portal { 25 26 using SessionClosedSignalHandler = void (*)(GDBusConnection*, 27 const char*, 28 const char*, 29 const char*, 30 const char*, 31 GVariant*, 32 gpointer); 33 34 // A base class for XDG desktop portals that can capture desktop/screen. 35 // Note: downstream clients inherit from this class so it is advisable to 36 // provide a default implementation of any new virtual methods that may be added 37 // to this class. 38 class ScreenCapturePortalInterface { 39 public: ~ScreenCapturePortalInterface()40 virtual ~ScreenCapturePortalInterface() {} 41 // Gets details about the session such as session handle. GetSessionDetails()42 virtual xdg_portal::SessionDetails GetSessionDetails() { return {}; } 43 // Starts the portal setup. Start()44 virtual void Start() {} 45 46 // Stops and cleans up the portal. Stop()47 virtual void Stop() {} 48 49 // Notifies observers about the success/fail state of the portal 50 // request/response. OnPortalDone(xdg_portal::RequestResponse result)51 virtual void OnPortalDone(xdg_portal::RequestResponse result) {} 52 // Sends a create session request to the portal. RequestSession(GDBusProxy * proxy)53 virtual void RequestSession(GDBusProxy* proxy) {} 54 55 // Following methods should not be made virtual as they share a common 56 // implementation between portals. 57 58 // Requests portal session using the proxy object. 59 void RequestSessionUsingProxy(GAsyncResult* result); 60 // Handles the session request result. 61 void OnSessionRequestResult(GDBusProxy* proxy, GAsyncResult* result); 62 // Subscribes to session close signal and sets up a handler for it. 63 void RegisterSessionClosedSignalHandler( 64 const SessionClosedSignalHandler session_close_signal_handler, 65 GVariant* parameters, 66 GDBusConnection* connection, 67 std::string& session_handle, 68 guint& session_closed_signal_id); 69 // Handles the result of session start request. 70 void OnStartRequestResult(GDBusProxy* proxy, GAsyncResult* result); 71 }; 72 73 } // namespace xdg_portal 74 } // namespace webrtc 75 76 #endif // MODULES_DESKTOP_CAPTURE_LINUX_WAYLAND_SCREEN_CAPTURE_PORTAL_INTERFACE_H_ 77