Revert "Bug 1945770 - Make call to host registry portal earlier before LookAndFeel is initialized r=emilio" for causing build bustages @WidgetUtilsGtk.cpp.
This reverts commit 79c1051e8a.
This commit is contained in:
committed by
agoloman@mozilla.com
parent
fad0b21b7e
commit
27c1331540
@@ -4507,12 +4507,6 @@ int XREMain::XRE_mainInit(bool* aExitFlag) {
|
||||
*aExitFlag = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
# ifdef MOZ_WIDGET_GTK
|
||||
if (XRE_IsParentProcess()) {
|
||||
widget::RegisterHostApp();
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
rv = XRE_InitCommandLine(gArgc, gArgv);
|
||||
|
||||
@@ -48,13 +48,6 @@ extern mozilla::LazyLogModule gWidgetLog;
|
||||
|
||||
namespace mozilla::widget {
|
||||
|
||||
#ifdef MOZ_ENABLE_DBUS
|
||||
constexpr char sXdpServiceName[] = "org.freedesktop.portal.Desktop";
|
||||
constexpr char sXdpDBusPath[] = "/org/freedesktop/portal/desktop";
|
||||
constexpr char sXdpRegistryInterfaceName[] =
|
||||
"org.freedesktop.host.portal.Registry";
|
||||
#endif
|
||||
|
||||
int32_t WidgetUtilsGTK::IsTouchDeviceSupportPresent() {
|
||||
int32_t result = 0;
|
||||
GdkDisplay* display = gdk_display_get_default();
|
||||
@@ -161,75 +154,6 @@ bool IsRunningUnderFlatpak() {
|
||||
return sRunning;
|
||||
}
|
||||
|
||||
#ifdef MOZ_ENABLE_DBUS
|
||||
static void DoRegisterHostApp() {
|
||||
GUniquePtr<GError> error;
|
||||
|
||||
RefPtr<GDBusProxy> proxy = dont_AddRef(g_dbus_proxy_new_for_bus_sync(
|
||||
G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, nullptr, sXdpServiceName,
|
||||
sXdpDBusPath, sXdpRegistryInterfaceName, nullptr /* cancellable */,
|
||||
getter_Transfers(error)));
|
||||
if (error) {
|
||||
NS_WARNING(
|
||||
nsPrintfCString("Failed to create DBus proxy : %s\n", error->message)
|
||||
.get());
|
||||
return;
|
||||
}
|
||||
|
||||
GVariantBuilder builder;
|
||||
g_variant_builder_init(&builder, G_VARIANT_TYPE("(sa{sv})"));
|
||||
g_variant_builder_add(&builder, "s", "org.mozilla.firefox");
|
||||
GVariantBuilder dict_builder;
|
||||
g_variant_builder_init(&dict_builder, G_VARIANT_TYPE("a{sv}"));
|
||||
g_variant_builder_add_value(&builder, g_variant_builder_end(&dict_builder));
|
||||
|
||||
RefPtr<GVariant> args =
|
||||
dont_AddRef(g_variant_ref_sink(g_variant_builder_end(&builder)));
|
||||
|
||||
widget::DBusProxyCall(proxy, "Register", args, G_DBUS_CALL_FLAGS_NONE, -1,
|
||||
/* cancellable */ nullptr)
|
||||
->Then(GetCurrentSerialEventTarget(), __func__,
|
||||
[](const mozilla::widget::DBusCallPromise::ResolveOrRejectValue&
|
||||
aValue) {
|
||||
if (aValue.IsReject()) {
|
||||
NS_WARNING(
|
||||
"Failed to register host application for "
|
||||
"portals\n");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void RegisterHostApp() {
|
||||
static bool sInitialized = false;
|
||||
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
MOZ_ASSERT(!sInitialized);
|
||||
|
||||
sInitialized = true;
|
||||
|
||||
// Register unsandboxed application with an application ID that will be used
|
||||
// in portals. It has to be called before any other portal call, which
|
||||
// happens with gtk_init or in our LookAndFeel code. We also need to
|
||||
// re-register again when the portal is restarted. Documentation:
|
||||
// https://github.com/flatpak/xdg-desktop-portal/blob/main/data/org.freedesktop.host.portal.Registry.xml
|
||||
if (IsRunningUnderFlatpakOrSnap() || g_getenv("XPCSHELL_TEST")) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t DBusID = g_bus_watch_name(
|
||||
G_BUS_TYPE_SESSION, sXdpServiceName, G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
|
||||
[](GDBusConnection*, const gchar*, const gchar*, gpointer data) -> void {
|
||||
DoRegisterHostApp();
|
||||
},
|
||||
nullptr, nullptr, nullptr);
|
||||
|
||||
if (DBusID) {
|
||||
RunOnShutdown([DBusID] { g_bus_unwatch_name(DBusID); });
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool IsPackagedAppFileExists() {
|
||||
static bool sRunning = [] {
|
||||
nsresult rv;
|
||||
|
||||
@@ -49,9 +49,6 @@ bool IsPackagedAppFileExists();
|
||||
inline bool IsRunningUnderFlatpakOrSnap() {
|
||||
return IsRunningUnderFlatpak() || IsRunningUnderSnap();
|
||||
}
|
||||
#ifdef MOZ_ENABLE_DBUS
|
||||
void RegisterHostApp();
|
||||
#endif
|
||||
|
||||
enum class PortalKind {
|
||||
FilePicker,
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "nsIPowerManagerService.h"
|
||||
#ifdef MOZ_ENABLE_DBUS
|
||||
# include <gio/gio.h>
|
||||
# include "AsyncDBus.h"
|
||||
# include "nsIObserverService.h"
|
||||
# include "WidgetUtilsGtk.h"
|
||||
#endif
|
||||
@@ -48,6 +49,13 @@ using mozilla::widget::ScreenManager;
|
||||
#define NOTIFY_TOKEN 0xFA
|
||||
#define QUIT_TOKEN 0xFB
|
||||
|
||||
#ifdef MOZ_ENABLE_DBUS
|
||||
constexpr char sXdpServiceName[] = "org.freedesktop.portal.Desktop";
|
||||
constexpr char sXdpDBusPath[] = "/org/freedesktop/portal/desktop";
|
||||
constexpr char sXdpRegistryInterfaceName[] =
|
||||
"org.freedesktop.host.portal.Registry";
|
||||
#endif
|
||||
|
||||
LazyLogModule gWidgetLog("Widget");
|
||||
LazyLogModule gWidgetDragLog("WidgetDrag");
|
||||
LazyLogModule gWidgetWaylandLog("WidgetWayland");
|
||||
@@ -165,6 +173,10 @@ nsAppShell::~nsAppShell() {
|
||||
|
||||
#ifdef MOZ_ENABLE_DBUS
|
||||
StopDBusListening();
|
||||
if (mDBusID) {
|
||||
g_bus_unwatch_name(mDBusID);
|
||||
mDBusID = 0;
|
||||
}
|
||||
#endif
|
||||
mozilla::hal::Shutdown();
|
||||
|
||||
@@ -324,6 +336,45 @@ void nsAppShell::StopDBusListening() {
|
||||
}
|
||||
mTimedate1Proxy = nullptr;
|
||||
}
|
||||
|
||||
void nsAppShell::RegisterHostApp() {
|
||||
GUniquePtr<GError> error;
|
||||
RefPtr<GDBusProxy> proxy;
|
||||
RefPtr<GVariant> result;
|
||||
|
||||
proxy = g_dbus_proxy_new_for_bus_sync(
|
||||
G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, nullptr, sXdpServiceName,
|
||||
sXdpDBusPath, sXdpRegistryInterfaceName, nullptr /* cancellable */,
|
||||
getter_Transfers(error));
|
||||
if (error) {
|
||||
NS_WARNING(
|
||||
nsPrintfCString("Failed to create DBus proxy : %s\n", error->message)
|
||||
.get());
|
||||
return;
|
||||
}
|
||||
|
||||
GVariantBuilder builder;
|
||||
g_variant_builder_init(&builder, G_VARIANT_TYPE("(sa{sv})"));
|
||||
g_variant_builder_add(&builder, "s", "org.mozilla.firefox");
|
||||
GVariantBuilder dict_builder;
|
||||
g_variant_builder_init(&dict_builder, G_VARIANT_TYPE("a{sv}"));
|
||||
g_variant_builder_add_value(&builder, g_variant_builder_end(&dict_builder));
|
||||
|
||||
RefPtr<GVariant> args =
|
||||
dont_AddRef(g_variant_ref_sink(g_variant_builder_end(&builder)));
|
||||
|
||||
widget::DBusProxyCall(proxy, "Register", args, G_DBUS_CALL_FLAGS_NONE, -1,
|
||||
/* cancellable */ nullptr)
|
||||
->Then(GetCurrentSerialEventTarget(), __func__,
|
||||
[](const mozilla::widget::DBusCallPromise::ResolveOrRejectValue&
|
||||
aValue) {
|
||||
if (aValue.IsReject()) {
|
||||
NS_WARNING(
|
||||
"Failed to register host application for "
|
||||
"portals\n");
|
||||
}
|
||||
});
|
||||
}
|
||||
#endif
|
||||
|
||||
void nsAppShell::TermSignalHandler(int signo) {
|
||||
@@ -360,6 +411,23 @@ nsresult nsAppShell::Init() {
|
||||
#ifdef MOZ_ENABLE_DBUS
|
||||
if (XRE_IsParentProcess()) {
|
||||
StartDBusListening();
|
||||
|
||||
// Register unsandboxed application with an application ID that will be used
|
||||
// in portals. It has to be called before any other portal call, which
|
||||
// happens with gtk_init or in our LookAndFeel code. We also need to
|
||||
// re-register again when the portal is restarted. Documentation:
|
||||
// https://github.com/flatpak/xdg-desktop-portal/blob/main/data/org.freedesktop.host.portal.Registry.xml
|
||||
if (!widget::IsRunningUnderFlatpakOrSnap() && !g_getenv("XPCSHELL_TEST")) {
|
||||
mDBusID = g_bus_watch_name(
|
||||
G_BUS_TYPE_SESSION, sXdpServiceName,
|
||||
G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
|
||||
[](GDBusConnection*, const gchar*, const gchar*,
|
||||
gpointer data) -> void {
|
||||
auto* appShell = static_cast<nsAppShell*>(data);
|
||||
appShell->RegisterHostApp();
|
||||
},
|
||||
nullptr, this, nullptr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ class nsAppShell : public nsBaseAppShell {
|
||||
unsigned mTag = 0;
|
||||
|
||||
#ifdef MOZ_ENABLE_DBUS
|
||||
uint32_t mDBusID = 0;
|
||||
RefPtr<GDBusProxy> mLogin1Proxy;
|
||||
RefPtr<GCancellable> mLogin1ProxyCancellable;
|
||||
RefPtr<GDBusProxy> mTimedate1Proxy;
|
||||
|
||||
Reference in New Issue
Block a user