mirror of
https://github.com/mozilla-firefox/firefox
synced 2026-08-11 12:19:28 +00:00
Bug 2046568 - Part 2: Remove DBusHelpers.h. r=emilio
I suspect these were left over from a previous libdbus(-glib?)
implementation.
Additionally, this moves away from using libdbus via dlsym to using
GLib/GIO directly for two functions:
dbus_validate_bus_name -> g_dbus_is_name
dbus_validate_path -> g_variant_is_object_path
(...odd name, I guess you have to put it somewhere?)
Had to keep the <dbus/dbus.h> include unfortunately for the
DBUS_MAXIMUM_NAME_LENGTH define. It should always be 255, so I guess we
could define it somewhere, but this was slightly easier. The whole
truncation thing seems really sketchy too, it was added in bug 1418770
but I'd rather not touch it right now.
Differential Revision: https://phabricator.services.mozilla.com/D305983
This commit is contained in:
committed by
dmcintosh@mozilla.com
parent
1854f85534
commit
39b74afdac
@@ -12,7 +12,7 @@
|
||||
#include "mozilla/GUniquePtr.h"
|
||||
#include "nsAppShell.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
#undef LOG
|
||||
#ifdef MOZ_LOGGING
|
||||
@@ -77,20 +77,12 @@ bool nsDBusRemoteClient::GetRemoteDestinationName(const char* aProgram,
|
||||
if (aDestinationName.Length() > DBUS_MAXIMUM_NAME_LENGTH)
|
||||
aDestinationName.Truncate(DBUS_MAXIMUM_NAME_LENGTH);
|
||||
|
||||
static auto sDBusValidateBusName = (bool (*)(const char*, DBusError*))dlsym(
|
||||
RTLD_DEFAULT, "dbus_validate_bus_name");
|
||||
if (!sDBusValidateBusName) {
|
||||
LOG(" failed to get dbus_validate_bus_name()");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!sDBusValidateBusName(aDestinationName.get(), nullptr)) {
|
||||
if (!g_dbus_is_name(aDestinationName.get())) {
|
||||
// We don't have a valid busName yet - try to create a default one.
|
||||
aDestinationName =
|
||||
nsPrintfCString("org.mozilla.%s.%s", aProgram, "default");
|
||||
if (!sDBusValidateBusName(aDestinationName.get(), nullptr)) {
|
||||
// We failed completelly to get a valid bus name - just quit
|
||||
// to prevent crash at dbus_bus_request_name().
|
||||
if (!g_dbus_is_name(aDestinationName.get())) {
|
||||
// We failed completely to get a valid bus name - just quit.
|
||||
LOG(" failed to validate profile DBus name");
|
||||
return false;
|
||||
}
|
||||
@@ -120,10 +112,7 @@ nsresult nsDBusRemoteClient::DoSendDBusCommandLine(const char* aProfile,
|
||||
nsAutoCString pathName;
|
||||
pathName = nsPrintfCString("/org/mozilla/%s/Remote", appName.get());
|
||||
|
||||
static auto sDBusValidatePathName = (bool (*)(const char*, DBusError*))dlsym(
|
||||
RTLD_DEFAULT, "dbus_validate_path");
|
||||
if (!sDBusValidatePathName ||
|
||||
!sDBusValidatePathName(pathName.get(), nullptr)) {
|
||||
if (!g_variant_is_object_path(pathName.get())) {
|
||||
LOG(" failed to validate path name");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
# include "mozilla/GRefPtr.h"
|
||||
#endif
|
||||
#include "nsRemoteClient.h"
|
||||
#include "mozilla/DBusHelpers.h"
|
||||
#include "nsString.h"
|
||||
#include "nscore.h"
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "nsPrintfCString.h"
|
||||
#include "nsGTKToolkit.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
@@ -129,11 +129,8 @@ static const GDBusInterfaceVTable gInterfaceVTable = {
|
||||
|
||||
void nsDBusRemoteServer::OnBusAcquired(GDBusConnection* aConnection) {
|
||||
mPathName = nsPrintfCString("/org/mozilla/%s/Remote", mAppName.get());
|
||||
static auto sDBusValidatePathName = (bool (*)(const char*, DBusError*))dlsym(
|
||||
RTLD_DEFAULT, "dbus_validate_path");
|
||||
if (!sDBusValidatePathName ||
|
||||
!sDBusValidatePathName(mPathName.get(), nullptr)) {
|
||||
g_warning("nsDBusRemoteServer: dbus_validate_path() failed!");
|
||||
if (!g_variant_is_object_path(mPathName.get())) {
|
||||
g_warning("nsDBusRemoteServer: object path is not valid");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -208,20 +205,12 @@ nsresult nsDBusRemoteServer::Startup(const char* aAppName,
|
||||
busName.Truncate(DBUS_MAXIMUM_NAME_LENGTH);
|
||||
}
|
||||
|
||||
static auto sDBusValidateBusName = (bool (*)(const char*, DBusError*))dlsym(
|
||||
RTLD_DEFAULT, "dbus_validate_bus_name");
|
||||
if (!sDBusValidateBusName) {
|
||||
g_warning("nsDBusRemoteServer: dbus_validate_bus_name() is missing!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// We don't have a valid busName yet - try to create a default one.
|
||||
if (!sDBusValidateBusName(busName.get(), nullptr)) {
|
||||
if (!g_dbus_is_name(busName.get())) {
|
||||
busName = nsPrintfCString("org.mozilla.%s.%s", mAppName.get(), "default");
|
||||
if (!sDBusValidateBusName(busName.get(), nullptr)) {
|
||||
// We failed completelly to get a valid bus name - just quit
|
||||
// to prevent crash at dbus_bus_request_name().
|
||||
g_warning("nsDBusRemoteServer: dbus_validate_bus_name() failed!");
|
||||
if (!g_dbus_is_name(busName.get())) {
|
||||
// We failed completely to get a valid bus name - just quit.
|
||||
g_warning("nsDBusRemoteServer: couldn't get a valid bus name!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "nsRemoteServer.h"
|
||||
#include "nsUnixRemoteServer.h"
|
||||
#include "mozilla/DBusHelpers.h"
|
||||
#include "mozilla/Span.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_DBusHelpers_h
|
||||
#define mozilla_DBusHelpers_h
|
||||
|
||||
#include <dbus/dbus.h>
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
template <>
|
||||
struct RefPtrTraits<DBusMessage> {
|
||||
static void AddRef(DBusMessage* aMessage) {
|
||||
MOZ_ASSERT(aMessage);
|
||||
dbus_message_ref(aMessage);
|
||||
}
|
||||
static void Release(DBusMessage* aMessage) {
|
||||
MOZ_ASSERT(aMessage);
|
||||
dbus_message_unref(aMessage);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct RefPtrTraits<DBusPendingCall> {
|
||||
static void AddRef(DBusPendingCall* aPendingCall) {
|
||||
MOZ_ASSERT(aPendingCall);
|
||||
dbus_pending_call_ref(aPendingCall);
|
||||
}
|
||||
static void Release(DBusPendingCall* aPendingCall) {
|
||||
MOZ_ASSERT(aPendingCall);
|
||||
dbus_pending_call_unref(aPendingCall);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* |RefPtrTraits<DBusConnection>| specializes |RefPtrTraits<>|
|
||||
* for managing |DBusConnection| with |RefPtr|.
|
||||
*
|
||||
* |RefPtrTraits<DBusConnection>| will _not_ close the DBus
|
||||
* connection upon the final unref. The caller is responsible
|
||||
* for closing the connection.
|
||||
*/
|
||||
template <>
|
||||
struct RefPtrTraits<DBusConnection> {
|
||||
static void AddRef(DBusConnection* aConnection) {
|
||||
MOZ_ASSERT(aConnection);
|
||||
dbus_connection_ref(aConnection);
|
||||
}
|
||||
static void Release(DBusConnection* aConnection) {
|
||||
MOZ_ASSERT(aConnection);
|
||||
dbus_connection_unref(aConnection);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* |DBusConnectionDelete| is a deleter for managing instances
|
||||
* of |DBusConnection| in |UniquePtr|. Upon destruction, it
|
||||
* will close an open connection before unref'ing the data
|
||||
* structure.
|
||||
*
|
||||
* Do not use |UniquePtr| with shared DBus connections. For
|
||||
* shared connections, use |RefPtr|.
|
||||
*/
|
||||
class DBusConnectionDelete {
|
||||
public:
|
||||
constexpr DBusConnectionDelete() {}
|
||||
|
||||
void operator()(DBusConnection* aConnection) const {
|
||||
MOZ_ASSERT(aConnection);
|
||||
if (dbus_connection_get_is_connected(aConnection)) {
|
||||
dbus_connection_close(aConnection);
|
||||
}
|
||||
dbus_connection_unref(aConnection);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_DBusHelpers_h
|
||||
@@ -97,11 +97,6 @@ elif CONFIG["MOZ_WIDGET_TOOLKIT"] == "windows":
|
||||
"win/nsMIMEInfoWin.cpp",
|
||||
]
|
||||
|
||||
if CONFIG["MOZ_ENABLE_DBUS"]:
|
||||
EXPORTS.mozilla += [
|
||||
"DBusHelpers.h",
|
||||
]
|
||||
|
||||
EXTRA_JS_MODULES += [
|
||||
"ExtHandlerService.sys.mjs",
|
||||
"WebHandlerApp.sys.mjs",
|
||||
|
||||
Reference in New Issue
Block a user