Bug 1544222 - Port bug 1526243 [Don't use nsGConfService in nsGNOMEShellService.cpp] to suite. r=IanN
authorBill Gianopoulos <wgianopoulos@gmail.com>
Thu, 11 Apr 2019 09:06:12 -0400
changeset 26337 38970ece368e7f1c76b511c18d92b0ffc62942f0
parent 26336 0696198c7fa8d9b6157113e1ddabd6162fc444e2
child 26338 552dd1355efae3044c6008fcea598ff23f459f0b
push id15792
push userfrgrahl@gmx.net
push dateSun, 14 Apr 2019 17:43:12 +0000
treeherdercomm-central@38970ece368e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersIanN
bugs1544222, 1526243
Bug 1544222 - Port bug 1526243 [Don't use nsGConfService in nsGNOMEShellService.cpp] to suite. r=IanN
suite/components/shell/nsGNOMEShellService.cpp
--- a/suite/components/shell/nsGNOMEShellService.cpp
+++ b/suite/components/shell/nsGNOMEShellService.cpp
@@ -9,17 +9,16 @@
 #include "nsShellService.h"
 #include "nsIServiceManager.h"
 #include "nsIFile.h"
 #include "nsIProperties.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsIPrefService.h"
 #include "prenv.h"
 #include "nsString.h"
-#include "nsIGConfService.h"
 #include "nsIGIOService.h"
 #include "nsIGSettingsService.h"
 #include "nsIStringBundle.h"
 #include "nsIOutputStream.h"
 #include "nsIProcess.h"
 #include "nsServiceManagerUtils.h"
 #include "nsComponentManagerUtils.h"
 #include "nsIImageLoadingContent.h"
@@ -33,24 +32,16 @@
 #include <glib.h>
 #include <glib-object.h>
 #include <gtk/gtk.h>
 #include <gdk/gdk.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <limits.h>
 #include <stdlib.h>
 
-// GConf registry key constants
-#define DG_BACKGROUND "/desktop/gnome/background"
-
-#define DGB_OPTIONS DG_BACKGROUND "/picture_options"
-#define DGB_IMAGE DG_BACKGROUND "/picture_filename"
-#define DGB_DRAWBG DG_BACKGROUND "/draw_background"
-#define DGB_COLOR DG_BACKGROUND "/primary_color"
-
 #define OGDB_SCHEMA "org.gnome.desktop.background"
 #define OGDB_OPTIONS "picture-options"
 #define OGDB_IMAGE "picture-uri"
 #define OGDB_DRAWBG "draw-background"
 #define OGDB_COLOR "primary-color"
 
 using namespace mozilla;
 
@@ -170,39 +161,32 @@ NS_IMETHODIMP
 nsGNOMEShellService::IsDefaultClient(bool aStartupCheck, uint16_t aApps,
                                      bool* aIsDefaultClient)
 {
   *aIsDefaultClient = false;
 
   nsCString handler;
   nsCOMPtr<nsIGIOMimeApp> gioApp;
   nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
-  nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
 
   for (unsigned i = 0; i < mozilla::ArrayLength(gProtocols); i++) {
     if (aApps & gProtocols[i].app) {
       nsDependentCString protocol(gProtocols[i].protocol);
       if (giovfs) {
         nsCOMPtr<nsIHandlerApp> handlerApp;
         giovfs->GetAppForURIScheme(protocol, getter_AddRefs(handlerApp));
 
         gioApp = do_QueryInterface(handlerApp);
         if (!gioApp)
           return NS_OK;
         
         if (NS_SUCCEEDED(gioApp->GetCommand(handler)) &&
             !HandlerMatchesAppName(handler.get()))
          return NS_OK;
       }
-
-      bool enabled;
-      if (gconf &&
-          NS_SUCCEEDED(gconf->GetAppForProtocol(protocol, &enabled, handler)) &&
-          (!enabled || !HandlerMatchesAppName(handler.get())))
-        return NS_OK;
     }
   }
 
   *aIsDefaultClient = true;
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -213,64 +197,64 @@ nsGNOMEShellService::SetDefaultClient(bo
 
   nsCOMPtr<nsIGIOMimeApp> app;
   nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
   if (giovfs) {
     nsCString brandName;
     rv = GetBrandName(brandName);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    rv = giovfs->CreateAppFromCommand(mAppPath, brandName, getter_AddRefs(app));
-    NS_ENSURE_SUCCESS(rv, rv);
+    rv = giovfs->FindAppFromCommand(mAppPath, getter_AddRefs(app));
+    if (NS_FAILED(rv)) {
+      // Application was not found in the list of installed applications
+      // provided by OS. Fallback to create appInfo from command and name.
+      rv = giovfs->CreateAppFromCommand(mAppPath, brandName, getter_AddRefs(app));
+      NS_ENSURE_SUCCESS(rv, rv);
+    }
+
+    // set handler for the protocols
+    for (unsigned int i = 0; i < ArrayLength(gProtocols); ++i) {
+      if (aApps & gProtocols[i].app) {
+        nsDependentCString protocol(gProtocols[i].protocol);
+        if (app) {
+          rv = app->SetAsDefaultForURIScheme(protocol);
+          NS_ENSURE_SUCCESS(rv, rv);
+        }
+      }
+    }
 
     for (unsigned i = 0; i < mozilla::ArrayLength(gMimeTypes); i++) {
       if (aApps & gMimeTypes[i].app) {
         rv = app->SetAsDefaultForMimeType(nsDependentCString(gMimeTypes[i].mimeType));
         NS_ENSURE_SUCCESS(rv, rv);
         rv = app->SetAsDefaultForFileExtensions(nsDependentCString(gMimeTypes[i].extensions));
         NS_ENSURE_SUCCESS(rv, rv);
       }
     }
   }
 
-  nsCString appKeyValue;
-  nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
-  if (gconf) {
-    if (!mAppIsInPath)
-      appKeyValue = mAppPath;
-    else {
-      gchar* basename = g_path_get_basename(mAppPath.get());
-      appKeyValue = basename;
-      g_free(basename);
-    }
-    appKeyValue.AppendLiteral(" %s");
-  }
-
-  for (unsigned i = 0; i < mozilla::ArrayLength(gProtocols); i++) {
-    if (aApps & gProtocols[i].app) {
-      nsDependentCString protocol(gProtocols[i].protocol);
-      if (app) {
-        rv = app->SetAsDefaultForURIScheme(protocol);
-        NS_ENSURE_SUCCESS(rv, rv);
-      }
-      if (gconf) {
-        rv = gconf->SetAppForProtocol(protocol, appKeyValue);
-        NS_ENSURE_SUCCESS(rv, rv);
-      }
-    }
-  }
-
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsGNOMEShellService::GetCanSetDesktopBackground(bool* aResult)
 {
-  nsCOMPtr<nsIGConfService> gconf(do_GetService(NS_GCONFSERVICE_CONTRACTID));
-  *aResult = gconf && getenv("GNOME_DESKTOP_SESSION_ID");
+  // for Gnome or desktops using the same GSettings keys
+  const char *currentDesktop = getenv("XDG_CURRENT_DESKTOP");
+  if (currentDesktop && strstr(currentDesktop, "GNOME") != nullptr) {
+    *aResult = true;
+    return NS_OK;
+  }
+  const char *gnomeSession = getenv("GNOME_DESKTOP_SESSION_ID");
+  if (gnomeSession) {
+    *aResult = true;
+  } else {
+    *aResult = false;
+  }
+
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsGNOMEShellService::SetDesktopBackground(dom::Element* aElement,
                                           int32_t aPosition,
                                           const nsACString& aImageName)
 
@@ -329,19 +313,16 @@ nsGNOMEShellService::SetDesktopBackgroun
     case BACKGROUND_FIT:
       options = "scaled";
       break;
     default:
       options = "centered";
       break;
   }
 
-  // Try GSettings first. If we don't have GSettings or the right schema, fall back
-  // to using GConf instead. Note that if GSettings works ok, the changes get
-  // mirrored to GConf by the gsettings->gconf bridge in gnome-settings-daemon
   nsCOMPtr<nsIGSettingsService> gsettings(do_GetService(NS_GSETTINGSSERVICE_CONTRACTID));
   if (gsettings) {
     nsCOMPtr<nsIGSettingsCollection> background_settings;
     gsettings->GetCollectionForSchema(NS_LITERAL_CSTRING(OGDB_SCHEMA),
                                       getter_AddRefs(background_settings));
     if (background_settings) {
       gchar *file_uri = g_filename_to_uri(filePath.get(), nullptr, nullptr);
       if (!file_uri)
@@ -352,31 +333,17 @@ nsGNOMEShellService::SetDesktopBackgroun
       background_settings->SetString(NS_LITERAL_CSTRING(OGDB_IMAGE),
                                      nsDependentCString(file_uri));
       g_free(file_uri);
       background_settings->SetBoolean(NS_LITERAL_CSTRING(OGDB_DRAWBG), true);
       return NS_OK;
     }
   }
 
-  // if the file was written successfully, set it as the system wallpaper
-  nsCOMPtr<nsIGConfService> gconf(do_GetService(NS_GCONFSERVICE_CONTRACTID));
-
-  if (gconf) {
-    gconf->SetString(NS_LITERAL_CSTRING(DGB_OPTIONS), nsDependentCString(options));
-
-    // Set the image to an empty string first to force a refresh (since we could
-    // be writing a new image on top of an existing SeaMonkey_wallpaper.png
-    // and nautilus doesn't monitor the file for changes).
-    gconf->SetString(NS_LITERAL_CSTRING(DGB_IMAGE), EmptyCString());
-    gconf->SetString(NS_LITERAL_CSTRING(DGB_IMAGE), filePath);
-    gconf->SetBool(NS_LITERAL_CSTRING(DGB_DRAWBG), true);
-  }
-
-  return NS_OK;
+  return NS_ERROR_FAILURE;
 }
 
 #define COLOR_16_TO_8_BIT(_c) ((_c) >> 8)
 
 NS_IMETHODIMP
 nsGNOMEShellService::GetDesktopBackgroundColor(uint32_t *aColor)
 {
   nsCOMPtr<nsIGSettingsService> gsettings(do_GetService(NS_GSETTINGSSERVICE_CONTRACTID));
@@ -385,21 +352,16 @@ nsGNOMEShellService::GetDesktopBackgroun
   if (gsettings)
     gsettings->GetCollectionForSchema(NS_LITERAL_CSTRING(OGDB_SCHEMA),
                                       getter_AddRefs(background_settings));
 
   nsCString background;
   if (background_settings)
     background_settings->GetString(NS_LITERAL_CSTRING(OGDB_COLOR),
                                    background);
-  else {
-    nsCOMPtr<nsIGConfService> gconf(do_GetService(NS_GCONFSERVICE_CONTRACTID));
-    if (gconf)
-      gconf->GetString(NS_LITERAL_CSTRING(DGB_COLOR), background);
-  }
 
   if (background.IsEmpty())
     return NS_ERROR_FAILURE;
 
   GdkColor color;
   NS_ENSURE_TRUE(gdk_color_parse(background.get(), &color), NS_ERROR_FAILURE);
 
   *aColor = COLOR_16_TO_8_BIT(color.red) << 16 |
@@ -429,21 +391,17 @@ nsGNOMEShellService::SetDesktopBackgroun
                                       getter_AddRefs(background_settings));
     if (background_settings) {
       background_settings->SetString(NS_LITERAL_CSTRING(OGDB_COLOR),
                                      nsDependentCString(colorString));
       return NS_OK;
     }
   }
 
-  nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
-  if (gconf)
-    gconf->SetString(NS_LITERAL_CSTRING(DGB_COLOR), nsDependentCString(colorString));
-
-  return NS_OK;
+  return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsGNOMEShellService::OpenApplicationWithURI(nsIFile* aApplication, const nsACString& aURI)
 {
   nsresult rv;
   nsCOMPtr<nsIProcess> process =
     do_CreateInstance("@mozilla.org/process/util;1", &rv);