Bug 468916 - make modifyLogin() smarter than just remove+add. r=zpao, r=gavin
[wine-gecko.git] / uriloader / exthandler / nsDBusHandlerApp.cpp
blob4017cb0cfd73c2bfad451bc00e5948a0f7a5dfc1
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
77 nsDBusHandlerApp::Equals(nsIHandlerApp *aHandlerApp, PRBool *_retval)
79 NS_ENSURE_ARG_POINTER(aHandlerApp);
81 // If the handler app isn't a dbus handler app, then it's not the same app.
82 nsCOMPtr<nsIDBusHandlerApp> dbusHandlerApp = do_QueryInterface(aHandlerApp);
83 if (!dbusHandlerApp) {
84 *_retval = PR_FALSE;
85 return NS_OK;
87 nsCAutoString service;
88 nsCAutoString method;
90 nsresult rv = dbusHandlerApp->GetService(service);
91 if (NS_FAILED(rv)) {
92 *_retval = PR_FALSE;
93 return NS_OK;
95 rv = dbusHandlerApp->GetMethod(method);
96 if (NS_FAILED(rv)) {
97 *_retval = PR_FALSE;
98 return NS_OK;
101 *_retval = service.Equals(mService) && method.Equals(mMethod);
102 return NS_OK;
105 NS_IMETHODIMP
106 nsDBusHandlerApp::LaunchWithURI(nsIURI *aURI,
107 nsIInterfaceRequestor *aWindowContext)
109 nsCAutoString spec;
110 nsresult rv = aURI->GetAsciiSpec(spec);
111 NS_ENSURE_SUCCESS(rv,rv);
112 const char* uri = spec.get();
114 DBusError err;
115 dbus_error_init(&err);
117 DBusConnection *connection;
118 connection = dbus_bus_get(DBUS_BUS_SESSION, &err);
119 if (dbus_error_is_set(&err)) {
120 dbus_error_free(&err);
121 return NS_ERROR_FAILURE;
123 if (nsnull == connection) {
124 return NS_ERROR_FAILURE;
126 dbus_connection_set_exit_on_disconnect(connection,false);
128 DBusMessage* msg;
129 msg = dbus_message_new_method_call(mService.get(),
130 mObjpath.get(),
131 mInterface.get(),
132 mMethod.get());
134 if (!msg) {
135 return NS_ERROR_FAILURE;
137 dbus_message_set_no_reply(msg, PR_TRUE);
139 DBusMessageIter iter;
140 dbus_message_iter_init_append(msg, &iter);
141 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &uri);
143 if (dbus_connection_send(connection, msg, NULL)) {
144 dbus_connection_flush(connection);
145 dbus_message_unref(msg);
146 #ifdef NS_OSSO
147 msg = dbus_message_new_method_call (APP_LAUNCH_BANNER_SERVICE,
148 APP_LAUNCH_BANNER_METHOD_PATH,
149 APP_LAUNCH_BANNER_METHOD_INTERFACE,
150 APP_LAUNCH_BANNER_METHOD);
152 if (msg) {
153 const char* service = mService.get();
154 if (dbus_message_append_args(msg,
155 DBUS_TYPE_STRING,
156 &service,
157 DBUS_TYPE_INVALID)) {
158 if (dbus_connection_send(connection, msg, NULL)) {
159 dbus_connection_flush(connection);
161 dbus_message_unref(msg);
164 #endif
165 } else {
166 dbus_message_unref(msg);
167 return NS_ERROR_FAILURE;
169 return NS_OK;
173 ////////////////////////////////////////////////////////////////////////////////
174 //// nsIDBusHandlerApp
176 /* attribute AUTF8String service; */
177 NS_IMETHODIMP nsDBusHandlerApp::GetService(nsACString & aService)
179 aService.Assign(mService);
180 return NS_OK;
183 NS_IMETHODIMP nsDBusHandlerApp::SetService(const nsACString & aService)
185 mService.Assign(aService);
186 return NS_OK;
189 /* attribute AUTF8String method; */
190 NS_IMETHODIMP nsDBusHandlerApp::GetMethod(nsACString & aMethod)
192 aMethod.Assign(mMethod);
193 return NS_OK;
196 NS_IMETHODIMP nsDBusHandlerApp::SetMethod(const nsACString & aMethod)
198 mMethod.Assign(aMethod);
199 return NS_OK;
202 /* attribute AUTF8String interface; */
203 NS_IMETHODIMP nsDBusHandlerApp::GetDBusInterface(nsACString & aInterface)
205 aInterface.Assign(mInterface);
206 return NS_OK;
209 NS_IMETHODIMP nsDBusHandlerApp::SetDBusInterface(const nsACString & aInterface)
211 mInterface.Assign(aInterface);
212 return NS_OK;
215 /* attribute AUTF8String objpath; */
216 NS_IMETHODIMP nsDBusHandlerApp::GetObjectPath(nsACString & aObjpath)
218 aObjpath.Assign(mObjpath);
219 return NS_OK;
222 NS_IMETHODIMP nsDBusHandlerApp::SetObjectPath(const nsACString & aObjpath)
224 mObjpath.Assign(aObjpath);
225 return NS_OK;
228 NS_DECL_CLASSINFO(nsDBusHandlerApp)