1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:cin:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "mozilla/Components.h"
9 #include "mozilla/DBusHelpers.h"
10 #include "nsDBusHandlerApp.h"
12 #include "nsIClassInfoImpl.h"
14 #include "nsCExternalHandlerService.h"
16 using namespace mozilla
;
18 // XXX why does nsMIMEInfoImpl have a threadsafe nsISupports? do we need one
20 NS_IMPL_CLASSINFO(nsDBusHandlerApp
, nullptr, 0,
21 components::DBusHandlerApp::CID())
22 NS_IMPL_ISUPPORTS_CI(nsDBusHandlerApp
, nsIDBusHandlerApp
, nsIHandlerApp
)
24 ////////////////////////////////////////////////////////////////////////////////
27 NS_IMETHODIMP
nsDBusHandlerApp::GetName(nsAString
& aName
) {
32 NS_IMETHODIMP
nsDBusHandlerApp::SetName(const nsAString
& aName
) {
37 NS_IMETHODIMP
nsDBusHandlerApp::SetDetailedDescription(
38 const nsAString
& aDescription
) {
39 mDetailedDescription
.Assign(aDescription
);
44 NS_IMETHODIMP
nsDBusHandlerApp::GetDetailedDescription(
45 nsAString
& aDescription
) {
46 aDescription
.Assign(mDetailedDescription
);
52 nsDBusHandlerApp::Equals(nsIHandlerApp
* aHandlerApp
, bool* _retval
) {
53 NS_ENSURE_ARG_POINTER(aHandlerApp
);
55 // If the handler app isn't a dbus handler app, then it's not the same app.
56 nsCOMPtr
<nsIDBusHandlerApp
> dbusHandlerApp
= do_QueryInterface(aHandlerApp
);
57 if (!dbusHandlerApp
) {
61 nsAutoCString service
;
64 nsresult rv
= dbusHandlerApp
->GetService(service
);
69 rv
= dbusHandlerApp
->GetMethod(method
);
75 *_retval
= service
.Equals(mService
) && method
.Equals(mMethod
);
80 nsDBusHandlerApp::LaunchWithURI(
81 nsIURI
* aURI
, mozilla::dom::BrowsingContext
* aBrowsingContext
) {
83 nsresult rv
= aURI
->GetAsciiSpec(spec
);
84 NS_ENSURE_SUCCESS(rv
, rv
);
85 const char* uri
= spec
.get();
88 dbus_error_init(&err
);
90 mozilla::UniquePtr
<DBusConnection
, mozilla::DBusConnectionDelete
> connection(
91 dbus_bus_get_private(DBUS_BUS_SESSION
, &err
));
93 if (dbus_error_is_set(&err
)) {
94 dbus_error_free(&err
);
95 return NS_ERROR_FAILURE
;
97 if (nullptr == connection
) {
98 return NS_ERROR_FAILURE
;
100 dbus_connection_set_exit_on_disconnect(connection
.get(), false);
102 RefPtr
<DBusMessage
> msg
=
103 already_AddRefed
<DBusMessage
>(dbus_message_new_method_call(
104 mService
.get(), mObjpath
.get(), mInterface
.get(), mMethod
.get()));
107 return NS_ERROR_FAILURE
;
109 dbus_message_set_no_reply(msg
, true);
111 DBusMessageIter iter
;
112 dbus_message_iter_init_append(msg
, &iter
);
113 dbus_message_iter_append_basic(&iter
, DBUS_TYPE_STRING
, &uri
);
115 if (dbus_connection_send(connection
.get(), msg
, nullptr)) {
116 dbus_connection_flush(connection
.get());
118 return NS_ERROR_FAILURE
;
123 ////////////////////////////////////////////////////////////////////////////////
124 //// nsIDBusHandlerApp
126 NS_IMETHODIMP
nsDBusHandlerApp::GetService(nsACString
& aService
) {
127 aService
.Assign(mService
);
131 NS_IMETHODIMP
nsDBusHandlerApp::SetService(const nsACString
& aService
) {
132 mService
.Assign(aService
);
136 NS_IMETHODIMP
nsDBusHandlerApp::GetMethod(nsACString
& aMethod
) {
137 aMethod
.Assign(mMethod
);
141 NS_IMETHODIMP
nsDBusHandlerApp::SetMethod(const nsACString
& aMethod
) {
142 mMethod
.Assign(aMethod
);
146 NS_IMETHODIMP
nsDBusHandlerApp::GetDBusInterface(nsACString
& aInterface
) {
147 aInterface
.Assign(mInterface
);
151 NS_IMETHODIMP
nsDBusHandlerApp::SetDBusInterface(const nsACString
& aInterface
) {
152 mInterface
.Assign(aInterface
);
156 NS_IMETHODIMP
nsDBusHandlerApp::GetObjectPath(nsACString
& aObjpath
) {
157 aObjpath
.Assign(mObjpath
);
161 NS_IMETHODIMP
nsDBusHandlerApp::SetObjectPath(const nsACString
& aObjpath
) {
162 mObjpath
.Assign(aObjpath
);