Bug 441636 - Add support for mailto uri, use hildon actions as protocol handler lookup r=biesi
author"Brad Lassey" <blassey@mozilla.com>
Sun, 27 Jul 2008 08:54:30 -0400
changeset 16238 a9d6442f4b1e87cb3f9ab753a4fb734800624ca1
parent 16237 26c8643ce48302359fa2ee095425638aef4a1034
child 16239 795e54fddec25ed3e625f0ecd9f6a2c7fca98c12
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
bugs441636
milestone1.9.1a2pre
Bug 441636 - Add support for mailto uri, use hildon actions as protocol handler lookup r=biesi
config/autoconf.mk.in
configure.in
toolkit/library/Makefile.in
uriloader/exthandler/unix/nsMIMEInfoUnix.cpp
uriloader/exthandler/unix/nsMIMEInfoUnix.h
--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -622,16 +622,21 @@ MOZ_SUNBIRD	= @MOZ_SUNBIRD@
 MOZ_SUITE	= @MOZ_SUITE@
 WINCE		= @WINCE@
 
 MOZ_DISTRIBUTION_ID = @MOZ_DISTRIBUTION_ID@
 
 NS_HILDON	= @NS_HILDON@
 NS_OSSO 	= @NS_OSSO@
 
+NS_HILDONMIME_CFLAGS	= @NS_HILDONMIME_CFLAGS@
+NS_HILDONMIME_LIBS	= @NS_HILDONMIME_LIBS@
+NS_OSSO_CFLAGS 	= @NS_OSSO_CFLAGS@
+NS_OSSO_LIBS 	= @NS_OSSO_LIBS@
+
 
 MACOS_SDK_DIR	= @MACOS_SDK_DIR@
 NEXT_ROOT	= @NEXT_ROOT@
 GCC_VERSION	= @GCC_VERSION@
 XCODEBUILD_VERSION= @XCODEBUILD_VERSION@
 HAS_XCODE_2_1	= @HAS_XCODE_2_1@
 UNIVERSAL_BINARY= @UNIVERSAL_BINARY@
 HAVE_DTRACE= @HAVE_DTRACE@
--- a/configure.in
+++ b/configure.in
@@ -1577,31 +1577,36 @@ dnl Get version of various core apps fro
 FIREFOX_VERSION=`cat $topsrcdir/browser/config/version.txt`
 THUNDERBIRD_VERSION=`cat $topsrcdir/mail/config/version.txt`
 SUNBIRD_VERSION=`cat $topsrcdir/calendar/sunbird/config/version.txt`
 SEAMONKEY_VERSION=`cat $topsrcdir/suite/config/version.txt`
 
 AC_DEFINE_UNQUOTED(MOZILLA_VERSION,"$MOZILLA_VERSION")
 AC_DEFINE_UNQUOTED(MOZILLA_VERSION_U,$MOZILLA_VERSION)
 
-PKG_CHECK_MODULES(LIBHILONMIME,libhildonmime,
+PKG_CHECK_MODULES(NS_HILDONMIME,libhildonmime,
                   NS_HILDON=1,
                   NS_HILDON=)
 if test $NS_HILDON; then
    AC_DEFINE(NS_HILDON)
 fi
-
-PKG_CHECK_MODULES(LIBOSSO,libosso,
+AC_SUBST(NS_HILDONMIME_CFLAGS)
+AC_SUBST(NS_HILDONMIME_LIBS)
+
+PKG_CHECK_MODULES(NS_OSSO,libosso,
                   NS_OSSO=1,
                   NS_OSSO=)
 
 if test $NS_OSSO; then
    AC_DEFINE(NS_OSSO)     
 fi
 
+AC_SUBST(NS_OSSO_CFLAGS)
+AC_SUBST(NS_OSSO_LIBS)
+
 dnl ========================================================
 dnl System overrides of the defaults for target
 dnl ========================================================
 
 case "$target" in
 *-aix*)
     AC_DEFINE(AIX)
     if test ! "$GNU_CC"; then
--- a/toolkit/library/Makefile.in
+++ b/toolkit/library/Makefile.in
@@ -202,16 +202,24 @@ EXTRA_DSO_LDOPTS += \
 	-framework SystemConfiguration \
 	-framework QuickTime \
 	-framework IOKit \
 	-lcrypto \
 	$(TK_LIBS) \
 	$(NULL)
 endif
 
+ifdef NS_HILDON
+EXTRA_DSO_LDOPTS += $(NS_HILDONMIME_LIBS)
+endif 
+
+ifdef NS_OSSO
+EXTRA_DSO_LDOPTS += $(NS_OSSO_LIBS)
+endif
+
 ifdef MOZ_ENABLE_DBUS
 EXTRA_DSO_LDOPTS += $(MOZ_DBUS_GLIB_LIBS)
 endif
 
 ifeq (gtk2,$(MOZ_WIDGET_TOOLKIT))
 EXTRA_DSO_LDOPTS += $(XLDFLAGS) $(XLIBS) $(MOZ_XFT_LIBS) $(MOZ_GTK2_LIBS) $(XT_LIBS) -lgthread-2.0
 EXTRA_DSO_LDOPTS += $(FT2_LIBS)
 endif
--- a/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp
+++ b/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp
@@ -32,40 +32,73 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * 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 ***** */
 
+#ifdef NS_HILDON
+#include <glib.h>
+#include <hildon-uri.h>
+#endif
+
+
 #include "nsMIMEInfoUnix.h"
 #include "nsGNOMERegistry.h"
 #include "nsIGnomeVFSService.h"
+#include "nsPrintfCString.h"
+#ifdef MOZ_ENABLE_DBUS
+#include "nsDBusHandlerApp.h"
+#endif
+
 
 nsresult
 nsMIMEInfoUnix::LoadUriInternal(nsIURI * aURI)
-{
-  return nsGNOMERegistry::LoadURL(aURI);
+{ 
+  nsresult rv = nsGNOMERegistry::LoadURL(aURI);
+#ifdef NS_HILDON
+  if (NS_FAILED(rv)){
+    HildonURIAction *action = hildon_uri_get_default_action(mType.get(), nsnull);
+    if (action) {
+      nsCAutoString spec;
+      aURI->GetAsciiSpec(spec);
+      if (hildon_uri_open(spec.get(), action, nsnull))
+        rv = NS_OK;
+      hildon_uri_action_unref(action);
+    }
+  }
+#endif
+  return rv;
 }
 
 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;
   }
 
   if (*_retval)
     return NS_OK;
 
+#ifdef NS_HILDON
+  HildonURIAction *action = hildon_uri_get_default_action(mType.get(), nsnull);
+  if (action) {
+    *_retval = PR_TRUE;
+    hildon_uri_action_unref(action);
+    return NS_OK;
+  }
+#endif
+  
   // If we didn't find a VFS handler, fallback.
   return nsMIMEInfoImpl::GetHasDefaultHandler(_retval);
 }
 
 nsresult
 nsMIMEInfoUnix::LaunchDefaultWithFile(nsIFile *aFile)
 {
   nsCAutoString nativePath;
@@ -79,8 +112,63 @@ nsMIMEInfoUnix::LaunchDefaultWithFile(ns
       return app->Launch(nativePath);
   }
 
   if (!mDefaultApplication)
     return NS_ERROR_FILE_NOT_FOUND;
 
   return LaunchWithIProcess(mDefaultApplication, nativePath);
 }
+
+#ifdef NS_HILDON
+
+NS_IMETHODIMP
+nsMIMEInfoUnix::GetPossibleApplicationHandlers(nsIMutableArray ** aPossibleAppHandlers)
+{
+  if (!mPossibleApplications) {
+    mPossibleApplications = do_CreateInstance(NS_ARRAY_CONTRACTID);
+    
+    if (!mPossibleApplications)
+      return NS_ERROR_OUT_OF_MEMORY;
+
+    GSList *actions = hildon_uri_get_actions(mType.get(), nsnull);
+    GSList *actionsPtr = actions;
+    while (actionsPtr) {
+      HildonURIAction *action = (HildonURIAction*)actionsPtr->data;
+      actionsPtr = actionsPtr->next;
+      nsDBusHandlerApp* app = new nsDBusHandlerApp();
+      if (!app){
+        hildon_uri_free_actions(actions);
+        return NS_ERROR_OUT_OF_MEMORY;
+      }
+      nsDependentCString method(hildon_uri_action_get_method(action));
+      nsDependentCString key(hildon_uri_action_get_service(action));
+      nsCString service, objpath, interface;
+      app->SetMethod(method);
+      app->SetName(NS_ConvertUTF8toUTF16(key));
+
+      if (key.FindChar('.', 0) > 0) {
+        service.Assign(key);
+        int len = key.Length() + 1;
+        objpath.Assign(NS_LITERAL_CSTRING("/") + key);
+        objpath.ReplaceChar('.', '/');
+        interface.Assign(key);
+      } else {
+        int len = key.Length() + 11;
+        service.Assign(NS_LITERAL_CSTRING("com.nokia.") + key);
+        objpath.Assign(NS_LITERAL_CSTRING("/com/nokia/") + key);
+        interface.Assign(NS_LITERAL_CSTRING("com.nokia.") + key);  
+      }
+      
+      app->SetService(service);
+      app->SetObjectPath(objpath);
+      app->SetDBusInterface(interface);
+      
+      mPossibleApplications->AppendElement(app, PR_FALSE);    
+    }
+    hildon_uri_free_actions(actions);
+  }
+
+  *aPossibleAppHandlers = mPossibleApplications;
+  NS_ADDREF(*aPossibleAppHandlers);
+  return NS_OK;
+}
+#endif
--- a/uriloader/exthandler/unix/nsMIMEInfoUnix.h
+++ b/uriloader/exthandler/unix/nsMIMEInfoUnix.h
@@ -51,11 +51,14 @@ public:
     nsMIMEInfoImpl(aType, aClass) {}
 
 protected:
   NS_IMETHOD GetHasDefaultHandler(PRBool *_retval);
 
   virtual NS_HIDDEN_(nsresult) LoadUriInternal(nsIURI *aURI);
 
   virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile *aFile);
+#ifdef NS_HILDON
+  NS_IMETHOD GetPossibleApplicationHandlers(nsIMutableArray * *aPossibleAppHandlers);
+#endif
 };
 
 #endif // nsMIMEInfoUnix_h_