Bug 273524 - "Helper applications with parameters don't work ( GTK2/Gnome )" [p=mh+mozilla@glandium.org (Mike Hommey) r=biesi a1.9=beltzner]
authorreed@reedloden.com
Tue, 26 Feb 2008 16:58:15 -0800
changeset 12301 3c41c81e407550f1cedaf42af88ba19fc735d7bf
parent 12300 1b902acc2dedb72ea97db46bbbd712f6c123dd75
child 12302 bed389092054aae22d094877511d5e2bd1722278
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbiesi
bugs273524
milestone1.9b4pre
Bug 273524 - "Helper applications with parameters don't work ( GTK2/Gnome )" [p=mh+mozilla@glandium.org (Mike Hommey) r=biesi a1.9=beltzner]
uriloader/exthandler/unix/nsGNOMERegistry.cpp
uriloader/exthandler/unix/nsMIMEInfoUnix.cpp
uriloader/exthandler/unix/nsMIMEInfoUnix.h
--- a/uriloader/exthandler/unix/nsGNOMERegistry.cpp
+++ b/uriloader/exthandler/unix/nsGNOMERegistry.cpp
@@ -144,45 +144,17 @@ nsGNOMERegistry::GetFromType(const nsACS
 
   nsRefPtr<nsMIMEInfoUnix> mimeInfo = new nsMIMEInfoUnix(aMIMEType);
   NS_ENSURE_TRUE(mimeInfo, nsnull);
 
   nsCAutoString description;
   vfs->GetDescriptionForMimeType(aMIMEType, description);
   mimeInfo->SetDescription(NS_ConvertUTF8toUTF16(description));
 
-  // Convert UTF-8 registry value to filesystem encoding, which
-  // g_find_program_in_path() uses.
-
-  nsCAutoString command;
-  handlerApp->GetCommand(command);
-  gchar *nativeCommand = g_filename_from_utf8(command.get(),
-                                              -1, NULL, NULL, NULL);
-  if (!nativeCommand) {
-    NS_ERROR("Could not convert helper app command to filesystem encoding");
-    return nsnull;
-  }
-
-  gchar *commandPath = g_find_program_in_path(nativeCommand);
-
-  g_free(nativeCommand);
-
-  if (!commandPath) {
-    return nsnull;
-  }
-
-  nsCOMPtr<nsILocalFile> appFile;
-  NS_NewNativeLocalFile(nsDependentCString(commandPath), PR_TRUE,
-                        getter_AddRefs(appFile));
-  if (appFile) {
-    mimeInfo->SetDefaultApplication(appFile);
-    nsCAutoString name;
-    handlerApp->GetName(name);
-    mimeInfo->SetDefaultDescription(NS_ConvertUTF8toUTF16(name));
-    mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
-  }
-
-  g_free(commandPath);
+  nsCAutoString name;
+  handlerApp->GetName(name);
+  mimeInfo->SetDefaultDescription(NS_ConvertUTF8toUTF16(name));
+  mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
 
   nsMIMEInfoBase* retval;
   NS_ADDREF((retval = mimeInfo));
   return retval;
 }
--- a/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp
+++ b/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp
@@ -34,15 +34,48 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsMIMEInfoUnix.h"
 #include "nsGNOMERegistry.h"
+#include "nsIGnomeVFSService.h"
 
 nsresult
 nsMIMEInfoUnix::LoadUriInternal(nsIURI * aURI)
 {
   return nsGNOMERegistry::LoadURL(aURI);
 }
 
+NS_IMETHODIMP
+nsMIMEInfoUnix::GetHasDefaultHandler(PRBool *_retval)
+{
+  *_retval = PR_FALSE;
+  nsCOMPtr<nsIGnomeVFSService> vfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID);
+  if (vfs) {
+    nsCOMPtr<nsIGnomeVFSMimeApp> app;
+    if (NS_SUCCEEDED(vfs->GetAppForMimeType(mType, getter_AddRefs(app))) && app)
+      *_retval = PR_TRUE;
+  }
+  return NS_OK;
+}
+
+nsresult
+nsMIMEInfoUnix::LaunchDefaultWithFile(nsIFile *aFile)
+{
+  nsCAutoString nativePath;
+  aFile->GetNativePath(nativePath);
+
+  nsCOMPtr<nsIGnomeVFSService> vfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID);
+
+  if (vfs) {
+    nsCOMPtr<nsIGnomeVFSMimeApp> app;
+    if (NS_SUCCEEDED(vfs->GetAppForMimeType(mType, getter_AddRefs(app))) && app)
+      return vfs->ShowURIForInput(nativePath);
+  }
+
+  if (!mDefaultApplication)
+    return NS_ERROR_FILE_NOT_FOUND;
+
+  return LaunchWithIProcess(mDefaultApplication, nativePath);
+}
--- a/uriloader/exthandler/unix/nsMIMEInfoUnix.h
+++ b/uriloader/exthandler/unix/nsMIMEInfoUnix.h
@@ -46,12 +46,16 @@ class nsMIMEInfoUnix : public nsMIMEInfo
 {
 public:
   nsMIMEInfoUnix(const char *aMIMEType = "") : nsMIMEInfoImpl(aMIMEType) {}
   nsMIMEInfoUnix(const nsACString& aMIMEType) : nsMIMEInfoImpl(aMIMEType) {}
   nsMIMEInfoUnix(const nsACString& aType, HandlerClass aClass) :
     nsMIMEInfoImpl(aType, aClass) {}
 
 protected:
+  NS_IMETHOD GetHasDefaultHandler(PRBool *_retval);
+
   virtual NS_HIDDEN_(nsresult) LoadUriInternal(nsIURI *aURI);
+
+  virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile *aFile);
 };
 
 #endif // nsMIMEInfoUnix_h_