LCOV - code coverage report
Current view: top level - uriloader/exthandler - nsDBusHandlerApp.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 1 80 1.2 %
Date: 2017-07-14 16:53:18 Functions: 0 18 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13