Bug 473045 - Update to nsIHandlerApp for win7 jump lists (plus tests). r=bz
[mozilla-central.git] / uriloader / exthandler / nsDBusHandlerApp.cpp
blobbac95802750dc60e3b81b0975de64d7b522d194c
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:cin:
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is the Mozilla browser.
18 * The Initial Developer of the Original Code is
19 * the Mozilla Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 2008
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Brad Lassey <blassey@mozila.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #include <dbus/dbus.h>
41 #include "nsDBusHandlerApp.h"
42 #include "nsIURI.h"
43 #include "nsIGenericFactory.h"
44 #include "nsIClassInfoImpl.h"
45 #include "nsCOMPtr.h"
47 #ifdef NS_OSSO
48 #include <libosso.h>
50 #define APP_LAUNCH_BANNER_SERVICE "com.nokia.hildon-desktop"
51 #define APP_LAUNCH_BANNER_METHOD_INTERFACE "com.nokia.hildon.hdwm.startupnotification"
52 #define APP_LAUNCH_BANNER_METHOD_PATH "/com/nokia/hildon/hdwm"
53 #define APP_LAUNCH_BANNER_METHOD "starting"
54 #endif
57 // XXX why does nsMIMEInfoImpl have a threadsafe nsISupports? do we need one
58 // here too?
59 NS_IMPL_ISUPPORTS2_CI(nsDBusHandlerApp, nsIDBusHandlerApp, nsIHandlerApp)
61 ////////////////////////////////////////////////////////////////////////////////
62 //// nsIHandlerApp
64 NS_IMETHODIMP nsDBusHandlerApp::GetName(nsAString& aName)
66 aName.Assign(mName);
67 return NS_OK;
70 NS_IMETHODIMP nsDBusHandlerApp::SetName(const nsAString & aName)
72 mName.Assign(aName);
73 return NS_OK;
76 NS_IMETHODIMP nsDBusHandlerApp::SetDetailedDescription(const nsAString & aDescription)
78 mDetailedDescription.Assign(aDescription);
80 return NS_OK;
83 NS_IMETHODIMP nsDBusHandlerApp::GetDetailedDescription(nsAString& aDescription)
85 aDescription.Assign(mDetailedDescription);
87 return NS_OK;
90 NS_IMETHODIMP
91 nsDBusHandlerApp::Equals(nsIHandlerApp *aHandlerApp, PRBool *_retval)
93 NS_ENSURE_ARG_POINTER(aHandlerApp);
95 // If the handler app isn't a dbus handler app, then it's not the same app.
96 nsCOMPtr<nsIDBusHandlerApp> dbusHandlerApp = do_QueryInterface(aHandlerApp);
97 if (!dbusHandlerApp) {
98 *_retval = PR_FALSE;
99 return NS_OK;
101 nsCAutoString service;
102 nsCAutoString method;
104 nsresult rv = dbusHandlerApp->GetService(service);
105 if (NS_FAILED(rv)) {
106 *_retval = PR_FALSE;
107 return NS_OK;
109 rv = dbusHandlerApp->GetMethod(method);
110 if (NS_FAILED(rv)) {
111 *_retval = PR_FALSE;
112 return NS_OK;
115 *_retval = service.Equals(mService) && method.Equals(mMethod);
116 return NS_OK;
119 NS_IMETHODIMP
120 nsDBusHandlerApp::LaunchWithURI(nsIURI *aURI,
121 nsIInterfaceRequestor *aWindowContext)
123 nsCAutoString spec;
124 nsresult rv = aURI->GetAsciiSpec(spec);
125 NS_ENSURE_SUCCESS(rv,rv);
126 const char* uri = spec.get();
128 DBusError err;
129 dbus_error_init(&err);
131 DBusConnection *connection;
132 connection = dbus_bus_get(DBUS_BUS_SESSION, &err);
133 if (dbus_error_is_set(&err)) {
134 dbus_error_free(&err);
135 return NS_ERROR_FAILURE;
137 if (nsnull == connection) {
138 return NS_ERROR_FAILURE;
140 dbus_connection_set_exit_on_disconnect(connection,false);
142 DBusMessage* msg;
143 msg = dbus_message_new_method_call(mService.get(),
144 mObjpath.get(),
145 mInterface.get(),
146 mMethod.get());
148 if (!msg) {
149 return NS_ERROR_FAILURE;
151 dbus_message_set_no_reply(msg, PR_TRUE);
153 DBusMessageIter iter;
154 dbus_message_iter_init_append(msg, &iter);
155 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &uri);
157 if (dbus_connection_send(connection, msg, NULL)) {
158 dbus_connection_flush(connection);
159 dbus_message_unref(msg);
160 #ifdef NS_OSSO
161 msg = dbus_message_new_method_call (APP_LAUNCH_BANNER_SERVICE,
162 APP_LAUNCH_BANNER_METHOD_PATH,
163 APP_LAUNCH_BANNER_METHOD_INTERFACE,
164 APP_LAUNCH_BANNER_METHOD);
166 if (msg) {
167 const char* service = mService.get();
168 if (dbus_message_append_args(msg,
169 DBUS_TYPE_STRING,
170 &service,
171 DBUS_TYPE_INVALID)) {
172 if (dbus_connection_send(connection, msg, NULL)) {
173 dbus_connection_flush(connection);
175 dbus_message_unref(msg);
178 #endif
179 } else {
180 dbus_message_unref(msg);
181 return NS_ERROR_FAILURE;
183 return NS_OK;
187 ////////////////////////////////////////////////////////////////////////////////
188 //// nsIDBusHandlerApp
190 /* attribute AUTF8String service; */
191 NS_IMETHODIMP nsDBusHandlerApp::GetService(nsACString & aService)
193 aService.Assign(mService);
194 return NS_OK;
197 NS_IMETHODIMP nsDBusHandlerApp::SetService(const nsACString & aService)
199 mService.Assign(aService);
200 return NS_OK;
203 /* attribute AUTF8String method; */
204 NS_IMETHODIMP nsDBusHandlerApp::GetMethod(nsACString & aMethod)
206 aMethod.Assign(mMethod);
207 return NS_OK;
210 NS_IMETHODIMP nsDBusHandlerApp::SetMethod(const nsACString & aMethod)
212 mMethod.Assign(aMethod);
213 return NS_OK;
216 /* attribute AUTF8String interface; */
217 NS_IMETHODIMP nsDBusHandlerApp::GetDBusInterface(nsACString & aInterface)
219 aInterface.Assign(mInterface);
220 return NS_OK;
223 NS_IMETHODIMP nsDBusHandlerApp::SetDBusInterface(const nsACString & aInterface)
225 mInterface.Assign(aInterface);
226 return NS_OK;
229 /* attribute AUTF8String objpath; */
230 NS_IMETHODIMP nsDBusHandlerApp::GetObjectPath(nsACString & aObjpath)
232 aObjpath.Assign(mObjpath);
233 return NS_OK;
236 NS_IMETHODIMP nsDBusHandlerApp::SetObjectPath(const nsACString & aObjpath)
238 mObjpath.Assign(aObjpath);
239 return NS_OK;
242 NS_DECL_CLASSINFO(nsDBusHandlerApp)