Bug 1544739 - Part 4: Update GNOME shell service - Change to CheckHandlerMatchesAppName. r=frg a=frg
authorIan Neal <iann_cvs@blueyonder.co.uk>
Wed, 24 Apr 2019 18:54:00 +0200
changeset 32183 2a75b48d5863bc9a85b30affc711ea6f7b702225
parent 32182 e7d6b59c504dd02a3609adbd850d4da4b5615f1f
child 32184 c12542ef7b070d72ed6aa23b6d598fe6d4e6debf
push id187
push userfrgrahl@gmx.net
push dateWed, 24 Apr 2019 16:55:18 +0000
treeherdercomm-esr60@33e9c7be6768 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrg, frg
bugs1544739
Bug 1544739 - Part 4: Update GNOME shell service - Change to CheckHandlerMatchesAppName. r=frg a=frg
suite/components/shell/nsGNOMEShellService.cpp
suite/components/shell/nsGNOMEShellService.h
--- a/suite/components/shell/nsGNOMEShellService.cpp
+++ b/suite/components/shell/nsGNOMEShellService.cpp
@@ -129,38 +129,49 @@ bool nsGNOMEShellService::GetAppPathFrom
     mAppIsInPath = true;
   }
 
   g_free(tmp);
   return true;
 }
 
 bool
-nsGNOMEShellService::HandlerMatchesAppName(const char* aHandler)
+nsGNOMEShellService::CheckHandlerMatchesAppName(const nsACString &handler) const
 {
-  bool matches = false;
   gint argc;
   gchar** argv;
-  if (g_shell_parse_argv(aHandler, &argc, &argv, nullptr) && argc > 0) {
-    gchar* command = nullptr;
-    if (!mUseLocaleFilenames)
-      command = g_find_program_in_path(argv[0]);
-    else {
-      gchar* nativeFile = g_filename_from_utf8(argv[0], -1,
-                                               nullptr, nullptr, nullptr);
-      if (nativeFile) {
-        command = g_find_program_in_path(nativeFile);
-        g_free(nativeFile);
-      }
-    }
-    matches = command && mAppPath.Equals(command);
-    g_free(command);
+  nsAutoCString command(handler);
+
+  // The string will be something of the form: [/path/to/]application "%s"
+  // We want to remove all of the parameters and get just the binary name.
+
+  if (g_shell_parse_argv(command.get(), &argc, &argv, nullptr) && argc > 0) {
+    command.Assign(argv[0]);
     g_strfreev(argv);
   }
 
+  gchar *commandPath;
+  if (mUseLocaleFilenames) {
+    gchar *nativePath =
+        g_filename_from_utf8(command.get(), -1, nullptr, nullptr, nullptr);
+    if (!nativePath) {
+      NS_ERROR("Error converting path to filesystem encoding");
+      return false;
+    }
+
+    commandPath = g_find_program_in_path(nativePath);
+    g_free(nativePath);
+  } else {
+    commandPath = g_find_program_in_path(command.get());
+  }
+
+  if (!commandPath) return false;
+
+  bool matches = mAppPath.Equals(commandPath);
+  g_free(commandPath);
   return matches;
 }
 
 NS_IMETHODIMP
 nsGNOMEShellService::IsDefaultClient(bool aStartupCheck, uint16_t aApps,
                                      bool* aIsDefaultClient)
 {
   *aIsDefaultClient = false;
@@ -176,17 +187,17 @@ nsGNOMEShellService::IsDefaultClient(boo
         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()))
+            !CheckHandlerMatchesAppName(handler))
          return NS_OK;
       }
     }
   }
 
   *aIsDefaultClient = true;
   return NS_OK;
 }
--- a/suite/components/shell/nsGNOMEShellService.h
+++ b/suite/components/shell/nsGNOMEShellService.h
@@ -22,17 +22,17 @@ public:
   NS_DECL_NSISHELLSERVICE
   NS_DECL_NSIGNOMESHELLSERVICE
 
   nsresult Init();
 
 private:
   ~nsGNOMEShellService() {}
 
-  bool HandlerMatchesAppName(const char* aHandler);
+  bool CheckHandlerMatchesAppName(const nsACString& handler) const;
 
   bool GetAppPathFromLauncher();
   bool mUseLocaleFilenames;
   nsCString mAppPath;
   bool mAppIsInPath;
 };
 
 #endif // nsgnomeshellservice_h____