michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim:expandtab:shiftwidth=2:tabstop=2:cin: michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include "nsDBusHandlerApp.h" michael@0: #include "nsIURI.h" michael@0: #include "nsIClassInfoImpl.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsCExternalHandlerService.h" michael@0: michael@0: // XXX why does nsMIMEInfoImpl have a threadsafe nsISupports? do we need one michael@0: // here too? michael@0: NS_IMPL_CLASSINFO(nsDBusHandlerApp, nullptr, 0, NS_DBUSHANDLERAPP_CID) michael@0: NS_IMPL_ISUPPORTS_CI(nsDBusHandlerApp, nsIDBusHandlerApp, nsIHandlerApp) michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// nsIHandlerApp michael@0: michael@0: NS_IMETHODIMP nsDBusHandlerApp::GetName(nsAString& aName) michael@0: { michael@0: aName.Assign(mName); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsDBusHandlerApp::SetName(const nsAString & aName) michael@0: { michael@0: mName.Assign(aName); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsDBusHandlerApp::SetDetailedDescription(const nsAString & aDescription) michael@0: { michael@0: mDetailedDescription.Assign(aDescription); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsDBusHandlerApp::GetDetailedDescription(nsAString& aDescription) michael@0: { michael@0: aDescription.Assign(mDetailedDescription); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsDBusHandlerApp::Equals(nsIHandlerApp *aHandlerApp, bool *_retval) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aHandlerApp); michael@0: michael@0: // If the handler app isn't a dbus handler app, then it's not the same app. michael@0: nsCOMPtr dbusHandlerApp = do_QueryInterface(aHandlerApp); michael@0: if (!dbusHandlerApp) { michael@0: *_retval = false; michael@0: return NS_OK; michael@0: } michael@0: nsAutoCString service; michael@0: nsAutoCString method; michael@0: michael@0: nsresult rv = dbusHandlerApp->GetService(service); michael@0: if (NS_FAILED(rv)) { michael@0: *_retval = false; michael@0: return NS_OK; michael@0: } michael@0: rv = dbusHandlerApp->GetMethod(method); michael@0: if (NS_FAILED(rv)) { michael@0: *_retval = false; michael@0: return NS_OK; michael@0: } michael@0: michael@0: *_retval = service.Equals(mService) && method.Equals(mMethod); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsDBusHandlerApp::LaunchWithURI(nsIURI *aURI, michael@0: nsIInterfaceRequestor *aWindowContext) michael@0: { michael@0: nsAutoCString spec; michael@0: nsresult rv = aURI->GetAsciiSpec(spec); michael@0: NS_ENSURE_SUCCESS(rv,rv); michael@0: const char* uri = spec.get(); michael@0: michael@0: DBusError err; michael@0: dbus_error_init(&err); michael@0: michael@0: DBusConnection *connection; michael@0: connection = dbus_bus_get(DBUS_BUS_SESSION, &err); michael@0: if (dbus_error_is_set(&err)) { michael@0: dbus_error_free(&err); michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: if (nullptr == connection) { michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: dbus_connection_set_exit_on_disconnect(connection,false); michael@0: michael@0: DBusMessage* msg; michael@0: msg = dbus_message_new_method_call(mService.get(), michael@0: mObjpath.get(), michael@0: mInterface.get(), michael@0: mMethod.get()); michael@0: michael@0: if (!msg) { michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: dbus_message_set_no_reply(msg, true); michael@0: michael@0: DBusMessageIter iter; michael@0: dbus_message_iter_init_append(msg, &iter); michael@0: dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &uri); michael@0: michael@0: if (dbus_connection_send(connection, msg, nullptr)) { michael@0: dbus_connection_flush(connection); michael@0: dbus_message_unref(msg); michael@0: } else { michael@0: dbus_message_unref(msg); michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: return NS_OK; michael@0: michael@0: } michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// nsIDBusHandlerApp michael@0: michael@0: /* attribute AUTF8String service; */ michael@0: NS_IMETHODIMP nsDBusHandlerApp::GetService(nsACString & aService) michael@0: { michael@0: aService.Assign(mService); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsDBusHandlerApp::SetService(const nsACString & aService) michael@0: { michael@0: mService.Assign(aService); michael@0: return NS_OK; michael@0: } michael@0: michael@0: /* attribute AUTF8String method; */ michael@0: NS_IMETHODIMP nsDBusHandlerApp::GetMethod(nsACString & aMethod) michael@0: { michael@0: aMethod.Assign(mMethod); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsDBusHandlerApp::SetMethod(const nsACString & aMethod) michael@0: { michael@0: mMethod.Assign(aMethod); michael@0: return NS_OK; michael@0: } michael@0: michael@0: /* attribute AUTF8String interface; */ michael@0: NS_IMETHODIMP nsDBusHandlerApp::GetDBusInterface(nsACString & aInterface) michael@0: { michael@0: aInterface.Assign(mInterface); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsDBusHandlerApp::SetDBusInterface(const nsACString & aInterface) michael@0: { michael@0: mInterface.Assign(aInterface); michael@0: return NS_OK; michael@0: } michael@0: michael@0: /* attribute AUTF8String objpath; */ michael@0: NS_IMETHODIMP nsDBusHandlerApp::GetObjectPath(nsACString & aObjpath) michael@0: { michael@0: aObjpath.Assign(mObjpath); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsDBusHandlerApp::SetObjectPath(const nsACString & aObjpath) michael@0: { michael@0: mObjpath.Assign(aObjpath); michael@0: return NS_OK; michael@0: } michael@0: michael@0: