uriloader/exthandler/nsDBusHandlerApp.cpp

Wed, 31 Dec 2014 07:53:36 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:53:36 +0100
branch
TOR_BUG_3246
changeset 5
4ab42b5ab56c
permissions
-rw-r--r--

Correct small whitespace inconsistency, lost while renaming variables.

     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/. */
     7 #include  <dbus/dbus.h>
     8 #include "nsDBusHandlerApp.h"
     9 #include "nsIURI.h"
    10 #include "nsIClassInfoImpl.h"
    11 #include "nsCOMPtr.h"
    12 #include "nsCExternalHandlerService.h"
    14 // XXX why does nsMIMEInfoImpl have a threadsafe nsISupports?  do we need one 
    15 // here too?
    16 NS_IMPL_CLASSINFO(nsDBusHandlerApp, nullptr, 0, NS_DBUSHANDLERAPP_CID)
    17 NS_IMPL_ISUPPORTS_CI(nsDBusHandlerApp, nsIDBusHandlerApp, nsIHandlerApp)
    19 ////////////////////////////////////////////////////////////////////////////////
    20 //// nsIHandlerApp
    22 NS_IMETHODIMP nsDBusHandlerApp::GetName(nsAString& aName)
    23 {
    24   aName.Assign(mName);
    25   return NS_OK;
    26 }
    28 NS_IMETHODIMP nsDBusHandlerApp::SetName(const nsAString & aName)
    29 {
    30   mName.Assign(aName);
    31   return NS_OK;
    32 }
    34 NS_IMETHODIMP nsDBusHandlerApp::SetDetailedDescription(const nsAString & aDescription)
    35 {
    36   mDetailedDescription.Assign(aDescription);
    38   return NS_OK;
    39 }
    41 NS_IMETHODIMP nsDBusHandlerApp::GetDetailedDescription(nsAString& aDescription)
    42 {
    43   aDescription.Assign(mDetailedDescription);
    45   return NS_OK;
    46 }
    48 NS_IMETHODIMP
    49 nsDBusHandlerApp::Equals(nsIHandlerApp *aHandlerApp, bool *_retval)
    50 {
    51   NS_ENSURE_ARG_POINTER(aHandlerApp);
    53   // If the handler app isn't a dbus handler app, then it's not the same app.
    54   nsCOMPtr<nsIDBusHandlerApp> dbusHandlerApp = do_QueryInterface(aHandlerApp);
    55   if (!dbusHandlerApp) {
    56     *_retval = false;
    57     return NS_OK;
    58   }
    59   nsAutoCString service;
    60   nsAutoCString method;
    62   nsresult rv = dbusHandlerApp->GetService(service);
    63   if (NS_FAILED(rv)) {
    64     *_retval = false;
    65     return NS_OK;
    66   }
    67   rv = dbusHandlerApp->GetMethod(method);
    68   if (NS_FAILED(rv)) {
    69     *_retval = false;
    70     return NS_OK;
    71   }
    73   *_retval = service.Equals(mService) && method.Equals(mMethod);
    74   return NS_OK;
    75 }
    77 NS_IMETHODIMP
    78 nsDBusHandlerApp::LaunchWithURI(nsIURI *aURI,
    79                                 nsIInterfaceRequestor *aWindowContext)
    80 {
    81   nsAutoCString spec;
    82   nsresult rv = aURI->GetAsciiSpec(spec);
    83   NS_ENSURE_SUCCESS(rv,rv);
    84   const char* uri = spec.get(); 
    86   DBusError err;
    87   dbus_error_init(&err);
    89   DBusConnection  *connection;
    90   connection = dbus_bus_get(DBUS_BUS_SESSION, &err);
    91   if (dbus_error_is_set(&err)) { 
    92     dbus_error_free(&err); 
    93     return NS_ERROR_FAILURE;
    94   }
    95   if (nullptr == connection) { 
    96     return NS_ERROR_FAILURE; 
    97   }
    98   dbus_connection_set_exit_on_disconnect(connection,false);
   100   DBusMessage* msg;
   101   msg = dbus_message_new_method_call(mService.get(), 
   102                                      mObjpath.get(), 
   103                                      mInterface.get(), 
   104                                      mMethod.get());
   106   if (!msg) {
   107     return NS_ERROR_FAILURE;
   108   }
   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, msg, nullptr)) {
   116     dbus_connection_flush(connection);
   117     dbus_message_unref(msg);
   118   } else {
   119     dbus_message_unref(msg);
   120     return NS_ERROR_FAILURE;
   121   }
   122   return NS_OK;
   124 }
   126 ////////////////////////////////////////////////////////////////////////////////
   127 //// nsIDBusHandlerApp
   129 /* attribute AUTF8String service; */
   130 NS_IMETHODIMP nsDBusHandlerApp::GetService(nsACString & aService)
   131 {
   132   aService.Assign(mService);
   133   return NS_OK;
   134 }
   136 NS_IMETHODIMP nsDBusHandlerApp::SetService(const nsACString & aService)
   137 {
   138   mService.Assign(aService);
   139   return NS_OK;
   140 }
   142 /* attribute AUTF8String method; */
   143 NS_IMETHODIMP nsDBusHandlerApp::GetMethod(nsACString & aMethod)
   144 {
   145   aMethod.Assign(mMethod);
   146   return NS_OK;
   147 }
   149 NS_IMETHODIMP nsDBusHandlerApp::SetMethod(const nsACString & aMethod)
   150 {
   151   mMethod.Assign(aMethod);
   152   return NS_OK;
   153 }
   155 /* attribute AUTF8String interface; */
   156 NS_IMETHODIMP nsDBusHandlerApp::GetDBusInterface(nsACString & aInterface)
   157 {
   158   aInterface.Assign(mInterface);
   159   return NS_OK;
   160 }
   162 NS_IMETHODIMP nsDBusHandlerApp::SetDBusInterface(const nsACString & aInterface)
   163 {
   164   mInterface.Assign(aInterface);
   165   return NS_OK;
   166 }
   168 /* attribute AUTF8String objpath; */
   169 NS_IMETHODIMP nsDBusHandlerApp::GetObjectPath(nsACString & aObjpath)
   170 {
   171   aObjpath.Assign(mObjpath);
   172   return NS_OK;
   173 }
   175 NS_IMETHODIMP nsDBusHandlerApp::SetObjectPath(const nsACString & aObjpath)
   176 {
   177   mObjpath.Assign(aObjpath);
   178   return NS_OK;
   179 }

mercurial