2008-07-27 17:44:20 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim:expandtab:shiftwidth=2:tabstop=2:cin:
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2008-07-27 17:44:20 +04:00
|
|
|
|
2016-04-21 12:24:23 +03:00
|
|
|
#include <dbus/dbus.h>
|
2018-12-17 04:27:58 +03:00
|
|
|
#include "mozilla/Components.h"
|
2017-10-27 19:41:40 +03:00
|
|
|
#include "mozilla/DBusHelpers.h"
|
2008-07-27 17:44:20 +04:00
|
|
|
#include "nsDBusHandlerApp.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIClassInfoImpl.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2010-06-22 20:59:57 +04:00
|
|
|
#include "nsCExternalHandlerService.h"
|
2008-07-27 17:44:20 +04:00
|
|
|
|
2018-12-17 04:27:58 +03:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2016-04-21 12:24:23 +03:00
|
|
|
// XXX why does nsMIMEInfoImpl have a threadsafe nsISupports? do we need one
|
2008-07-27 17:44:20 +04:00
|
|
|
// here too?
|
2018-12-17 04:27:58 +03:00
|
|
|
NS_IMPL_CLASSINFO(nsDBusHandlerApp, nullptr, 0,
|
|
|
|
components::DBusHandlerApp::CID())
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS_CI(nsDBusHandlerApp, nsIDBusHandlerApp, nsIHandlerApp)
|
2008-07-27 17:44:20 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIHandlerApp
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDBusHandlerApp::GetName(nsAString& aName) {
|
|
|
|
aName.Assign(mName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDBusHandlerApp::SetName(const nsAString& aName) {
|
|
|
|
mName.Assign(aName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-09-25 06:45:16 +04:00
|
|
|
NS_IMETHODIMP nsDBusHandlerApp::SetDetailedDescription(
|
|
|
|
const nsAString& aDescription) {
|
|
|
|
mDetailedDescription.Assign(aDescription);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDBusHandlerApp::GetDetailedDescription(
|
|
|
|
nsAString& aDescription) {
|
|
|
|
aDescription.Assign(mDetailedDescription);
|
2016-04-21 12:24:23 +03:00
|
|
|
|
2009-09-25 06:45:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-07-27 17:44:20 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsDBusHandlerApp::Equals(nsIHandlerApp* aHandlerApp, bool* _retval) {
|
2008-07-27 17:44:20 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aHandlerApp);
|
2016-04-21 12:24:23 +03:00
|
|
|
|
2008-07-27 17:44:20 +04:00
|
|
|
// If the handler app isn't a dbus handler app, then it's not the same app.
|
|
|
|
nsCOMPtr<nsIDBusHandlerApp> dbusHandlerApp = do_QueryInterface(aHandlerApp);
|
|
|
|
if (!dbusHandlerApp) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*_retval = false;
|
2008-07-27 17:44:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString service;
|
|
|
|
nsAutoCString method;
|
2016-04-21 12:24:23 +03:00
|
|
|
|
2008-07-27 17:44:20 +04:00
|
|
|
nsresult rv = dbusHandlerApp->GetService(service);
|
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*_retval = false;
|
2008-07-27 17:44:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
rv = dbusHandlerApp->GetMethod(method);
|
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*_retval = false;
|
2008-07-27 17:44:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-04-21 12:24:23 +03:00
|
|
|
|
2008-07-27 17:44:20 +04:00
|
|
|
*_retval = service.Equals(mService) && method.Equals(mMethod);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2020-05-11 16:13:03 +03:00
|
|
|
nsDBusHandlerApp::LaunchWithURI(
|
|
|
|
nsIURI* aURI, mozilla::dom::BrowsingContext* aBrowsingContext) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec;
|
2008-07-27 17:44:20 +04:00
|
|
|
nsresult rv = aURI->GetAsciiSpec(spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2016-04-21 12:24:23 +03:00
|
|
|
const char* uri = spec.get();
|
|
|
|
|
2008-07-27 17:44:20 +04:00
|
|
|
DBusError err;
|
|
|
|
dbus_error_init(&err);
|
2016-04-21 12:24:23 +03:00
|
|
|
|
2016-05-04 12:41:07 +03:00
|
|
|
mozilla::UniquePtr<DBusConnection, mozilla::DBusConnectionDelete> connection(
|
|
|
|
dbus_bus_get_private(DBUS_BUS_SESSION, &err));
|
2016-04-21 12:24:23 +03:00
|
|
|
|
2016-04-21 12:24:23 +03:00
|
|
|
if (dbus_error_is_set(&err)) {
|
|
|
|
dbus_error_free(&err);
|
2008-07-27 17:44:20 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2016-04-21 12:24:23 +03:00
|
|
|
if (nullptr == connection) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2008-07-27 17:44:20 +04:00
|
|
|
}
|
2016-05-04 12:41:07 +03:00
|
|
|
dbus_connection_set_exit_on_disconnect(connection.get(), false);
|
2016-04-21 12:24:23 +03:00
|
|
|
|
2016-04-21 12:24:23 +03:00
|
|
|
RefPtr<DBusMessage> msg =
|
|
|
|
already_AddRefed<DBusMessage>(dbus_message_new_method_call(
|
|
|
|
mService.get(), mObjpath.get(), mInterface.get(), mMethod.get()));
|
2016-04-21 12:24:23 +03:00
|
|
|
|
2008-07-27 17:44:20 +04:00
|
|
|
if (!msg) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
dbus_message_set_no_reply(msg, true);
|
2016-04-21 12:24:23 +03:00
|
|
|
|
2008-07-27 17:44:20 +04:00
|
|
|
DBusMessageIter iter;
|
|
|
|
dbus_message_iter_init_append(msg, &iter);
|
|
|
|
dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &uri);
|
2016-04-21 12:24:23 +03:00
|
|
|
|
2016-05-04 12:41:07 +03:00
|
|
|
if (dbus_connection_send(connection.get(), msg, nullptr)) {
|
|
|
|
dbus_connection_flush(connection.get());
|
2008-07-27 17:44:20 +04:00
|
|
|
} else {
|
2013-10-24 00:36:09 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2008-07-27 17:44:20 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIDBusHandlerApp
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDBusHandlerApp::GetService(nsACString& aService) {
|
|
|
|
aService.Assign(mService);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDBusHandlerApp::SetService(const nsACString& aService) {
|
|
|
|
mService.Assign(aService);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDBusHandlerApp::GetMethod(nsACString& aMethod) {
|
|
|
|
aMethod.Assign(mMethod);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDBusHandlerApp::SetMethod(const nsACString& aMethod) {
|
|
|
|
mMethod.Assign(aMethod);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDBusHandlerApp::GetDBusInterface(nsACString& aInterface) {
|
|
|
|
aInterface.Assign(mInterface);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDBusHandlerApp::SetDBusInterface(const nsACString& aInterface) {
|
|
|
|
mInterface.Assign(aInterface);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDBusHandlerApp::GetObjectPath(nsACString& aObjpath) {
|
|
|
|
aObjpath.Assign(mObjpath);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDBusHandlerApp::SetObjectPath(const nsACString& aObjpath) {
|
|
|
|
mObjpath.Assign(aObjpath);
|
|
|
|
return NS_OK;
|
|
|
|
}
|