/src/mozilla-central/uriloader/exthandler/nsDBusHandlerApp.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #include <dbus/dbus.h> |
8 | | #include "mozilla/DBusHelpers.h" |
9 | | #include "nsDBusHandlerApp.h" |
10 | | #include "nsIURI.h" |
11 | | #include "nsIClassInfoImpl.h" |
12 | | #include "nsCOMPtr.h" |
13 | | #include "nsCExternalHandlerService.h" |
14 | | |
15 | | // XXX why does nsMIMEInfoImpl have a threadsafe nsISupports? do we need one |
16 | | // here too? |
17 | | NS_IMPL_CLASSINFO(nsDBusHandlerApp, nullptr, 0, NS_DBUSHANDLERAPP_CID) |
18 | | NS_IMPL_ISUPPORTS_CI(nsDBusHandlerApp, nsIDBusHandlerApp, nsIHandlerApp) |
19 | | |
20 | | //////////////////////////////////////////////////////////////////////////////// |
21 | | //// nsIHandlerApp |
22 | | |
23 | | NS_IMETHODIMP nsDBusHandlerApp::GetName(nsAString& aName) |
24 | 0 | { |
25 | 0 | aName.Assign(mName); |
26 | 0 | return NS_OK; |
27 | 0 | } |
28 | | |
29 | | NS_IMETHODIMP nsDBusHandlerApp::SetName(const nsAString & aName) |
30 | 0 | { |
31 | 0 | mName.Assign(aName); |
32 | 0 | return NS_OK; |
33 | 0 | } |
34 | | |
35 | | NS_IMETHODIMP nsDBusHandlerApp::SetDetailedDescription(const nsAString & aDescription) |
36 | 0 | { |
37 | 0 | mDetailedDescription.Assign(aDescription); |
38 | 0 |
|
39 | 0 | return NS_OK; |
40 | 0 | } |
41 | | |
42 | | NS_IMETHODIMP nsDBusHandlerApp::GetDetailedDescription(nsAString& aDescription) |
43 | 0 | { |
44 | 0 | aDescription.Assign(mDetailedDescription); |
45 | 0 |
|
46 | 0 | return NS_OK; |
47 | 0 | } |
48 | | |
49 | | NS_IMETHODIMP |
50 | | nsDBusHandlerApp::Equals(nsIHandlerApp *aHandlerApp, bool *_retval) |
51 | 0 | { |
52 | 0 | NS_ENSURE_ARG_POINTER(aHandlerApp); |
53 | 0 |
|
54 | 0 | // If the handler app isn't a dbus handler app, then it's not the same app. |
55 | 0 | nsCOMPtr<nsIDBusHandlerApp> dbusHandlerApp = do_QueryInterface(aHandlerApp); |
56 | 0 | if (!dbusHandlerApp) { |
57 | 0 | *_retval = false; |
58 | 0 | return NS_OK; |
59 | 0 | } |
60 | 0 | nsAutoCString service; |
61 | 0 | nsAutoCString method; |
62 | 0 |
|
63 | 0 | nsresult rv = dbusHandlerApp->GetService(service); |
64 | 0 | if (NS_FAILED(rv)) { |
65 | 0 | *_retval = false; |
66 | 0 | return NS_OK; |
67 | 0 | } |
68 | 0 | rv = dbusHandlerApp->GetMethod(method); |
69 | 0 | if (NS_FAILED(rv)) { |
70 | 0 | *_retval = false; |
71 | 0 | return NS_OK; |
72 | 0 | } |
73 | 0 | |
74 | 0 | *_retval = service.Equals(mService) && method.Equals(mMethod); |
75 | 0 | return NS_OK; |
76 | 0 | } |
77 | | |
78 | | NS_IMETHODIMP |
79 | | nsDBusHandlerApp::LaunchWithURI(nsIURI *aURI, |
80 | | nsIInterfaceRequestor *aWindowContext) |
81 | 0 | { |
82 | 0 | nsAutoCString spec; |
83 | 0 | nsresult rv = aURI->GetAsciiSpec(spec); |
84 | 0 | NS_ENSURE_SUCCESS(rv,rv); |
85 | 0 | const char* uri = spec.get(); |
86 | 0 |
|
87 | 0 | DBusError err; |
88 | 0 | dbus_error_init(&err); |
89 | 0 |
|
90 | 0 | mozilla::UniquePtr<DBusConnection, mozilla::DBusConnectionDelete> |
91 | 0 | connection(dbus_bus_get_private(DBUS_BUS_SESSION, &err)); |
92 | 0 |
|
93 | 0 | if (dbus_error_is_set(&err)) { |
94 | 0 | dbus_error_free(&err); |
95 | 0 | return NS_ERROR_FAILURE; |
96 | 0 | } |
97 | 0 | if (nullptr == connection) { |
98 | 0 | return NS_ERROR_FAILURE; |
99 | 0 | } |
100 | 0 | dbus_connection_set_exit_on_disconnect(connection.get(),false); |
101 | 0 |
|
102 | 0 | RefPtr<DBusMessage> msg = already_AddRefed<DBusMessage>( |
103 | 0 | dbus_message_new_method_call(mService.get(), |
104 | 0 | mObjpath.get(), |
105 | 0 | mInterface.get(), |
106 | 0 | mMethod.get())); |
107 | 0 |
|
108 | 0 | if (!msg) { |
109 | 0 | return NS_ERROR_FAILURE; |
110 | 0 | } |
111 | 0 | dbus_message_set_no_reply(msg, true); |
112 | 0 |
|
113 | 0 | DBusMessageIter iter; |
114 | 0 | dbus_message_iter_init_append(msg, &iter); |
115 | 0 | dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &uri); |
116 | 0 |
|
117 | 0 | if (dbus_connection_send(connection.get(), msg, nullptr)) { |
118 | 0 | dbus_connection_flush(connection.get()); |
119 | 0 | } else { |
120 | 0 | return NS_ERROR_FAILURE; |
121 | 0 | } |
122 | 0 | return NS_OK; |
123 | 0 | } |
124 | | |
125 | | //////////////////////////////////////////////////////////////////////////////// |
126 | | //// nsIDBusHandlerApp |
127 | | |
128 | | NS_IMETHODIMP nsDBusHandlerApp::GetService(nsACString & aService) |
129 | 0 | { |
130 | 0 | aService.Assign(mService); |
131 | 0 | return NS_OK; |
132 | 0 | } |
133 | | |
134 | | NS_IMETHODIMP nsDBusHandlerApp::SetService(const nsACString & aService) |
135 | 0 | { |
136 | 0 | mService.Assign(aService); |
137 | 0 | return NS_OK; |
138 | 0 | } |
139 | | |
140 | | NS_IMETHODIMP nsDBusHandlerApp::GetMethod(nsACString & aMethod) |
141 | 0 | { |
142 | 0 | aMethod.Assign(mMethod); |
143 | 0 | return NS_OK; |
144 | 0 | } |
145 | | |
146 | | NS_IMETHODIMP nsDBusHandlerApp::SetMethod(const nsACString & aMethod) |
147 | 0 | { |
148 | 0 | mMethod.Assign(aMethod); |
149 | 0 | return NS_OK; |
150 | 0 | } |
151 | | |
152 | | NS_IMETHODIMP nsDBusHandlerApp::GetDBusInterface(nsACString & aInterface) |
153 | 0 | { |
154 | 0 | aInterface.Assign(mInterface); |
155 | 0 | return NS_OK; |
156 | 0 | } |
157 | | |
158 | | NS_IMETHODIMP nsDBusHandlerApp::SetDBusInterface(const nsACString & aInterface) |
159 | 0 | { |
160 | 0 | mInterface.Assign(aInterface); |
161 | 0 | return NS_OK; |
162 | 0 | } |
163 | | |
164 | | NS_IMETHODIMP nsDBusHandlerApp::GetObjectPath(nsACString & aObjpath) |
165 | 0 | { |
166 | 0 | aObjpath.Assign(mObjpath); |
167 | 0 | return NS_OK; |
168 | 0 | } |
169 | | |
170 | | NS_IMETHODIMP nsDBusHandlerApp::SetObjectPath(const nsACString & aObjpath) |
171 | 0 | { |
172 | 0 | mObjpath.Assign(aObjpath); |
173 | 0 | return NS_OK; |
174 | 0 | } |
175 | | |
176 | | |