diff --git a/uriloader/exthandler/Makefile.in b/uriloader/exthandler/Makefile.in --- a/uriloader/exthandler/Makefile.in +++ b/uriloader/exthandler/Makefile.in @@ -158,16 +158,23 @@ CPPSRCS = \ $(NULL) ifdef MOZ_ENABLE_DBUS CPPSRCS += nsDBusHandlerApp.cpp LOCAL_INCLUDES += $(TK_CFLAGS) $(MOZ_DBUS_GLIB_CFLAGS) EXTRA_DSO_LDOPTS += $(MOZ_DBUS_GLIB_LIBS) endif +ifdef MOZ_PLATFORM_HILDON +ifdef MOZ_ENABLE_GNOMEVFS +LOCAL_INCLUDES += $(MOZ_GNOMEVFS_CFLAGS) +EXTRA_DSO_LDOPTS += $(MOZ_GNOMEVFS_LIBS) +endif +endif + ifeq ($(OS_ARCH),WINNT WINCE) OS_LIBS += shell32.lib GARBAGE += nsOSHelperAppService.cpp $(srcdir)/nsOSHelperAppService.cpp \ nsMIMEInfoWin.cpp $(srcdir)/nsMIMEInfoWin.cpp endif EXTRA_COMPONENTS = \ nsHandlerService.js \ diff --git a/uriloader/exthandler/unix/nsGNOMERegistry.cpp b/uriloader/exthandler/unix/nsGNOMERegistry.cpp --- a/uriloader/exthandler/unix/nsGNOMERegistry.cpp +++ b/uriloader/exthandler/unix/nsGNOMERegistry.cpp @@ -45,16 +45,20 @@ #include "nsMIMEInfoUnix.h" #include "nsAutoPtr.h" #include "nsIGConfService.h" #include "nsIGnomeVFSService.h" #ifdef MOZ_WIDGET_GTK2 #include #include + +#ifdef MOZ_PLATFORM_HILDON +#include +#endif #endif /* static */ PRBool nsGNOMERegistry::HandlerExists(const char *aProtocolScheme) { nsCOMPtr gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID); if (!gconf) return PR_FALSE; @@ -148,15 +152,26 @@ nsGNOMERegistry::GetFromType(const nsACS NS_ENSURE_TRUE(mimeInfo, nsnull); nsCAutoString description; vfs->GetDescriptionForMimeType(aMIMEType, description); mimeInfo->SetDescription(NS_ConvertUTF8toUTF16(description)); nsCAutoString name; handlerApp->GetName(name); +#ifdef MOZ_PLATFORM_HILDON + // On Maemo/Hildon, GetName ends up calling gnome_vfs_mime_application_get_name, + // which happens to return a non-localized message-id for the application. To + // get the localized name for the application, we have to call dgettext with + // the default maemo domain-name to try and translate the string into the operating + // system's native language. + const char kDefaultTextDomain [] = "maemo-af-desktop"; + nsCAutoString realName (dgettext(kDefaultTextDomain, PromiseFlatCString(name).get())); + mimeInfo->SetDefaultDescription(NS_ConvertUTF8toUTF16(realName)); +#else mimeInfo->SetDefaultDescription(NS_ConvertUTF8toUTF16(name)); +#endif mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault); nsMIMEInfoBase* retval; NS_ADDREF((retval = mimeInfo)); return retval; } diff --git a/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp b/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp --- a/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp +++ b/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp @@ -35,27 +35,27 @@ * 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 MOZ_PLATFORM_HILDON #include #include +#include +#include #endif - #include "nsMIMEInfoUnix.h" #include "nsGNOMERegistry.h" #include "nsIGnomeVFSService.h" #ifdef MOZ_ENABLE_DBUS #include "nsDBusHandlerApp.h" #endif - nsresult nsMIMEInfoUnix::LoadUriInternal(nsIURI * aURI) { nsresult rv = nsGNOMERegistry::LoadURL(aURI); #ifdef MOZ_PLATFORM_HILDON if (NS_FAILED(rv)){ HildonURIAction *action = hildon_uri_get_default_action(mType.get(), nsnull); if (action) { @@ -98,31 +98,67 @@ nsMIMEInfoUnix::GetHasDefaultHandler(PRB } nsresult nsMIMEInfoUnix::LaunchDefaultWithFile(nsIFile *aFile) { nsCAutoString nativePath; aFile->GetNativePath(nativePath); +#ifdef MOZ_PLATFORM_HILDON + if(NS_SUCCEEDED(LaunchDefaultWithDBus(PromiseFlatCString(nativePath).get()))) + return NS_OK; +#endif + nsCOMPtr vfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID); - if (vfs) { nsCOMPtr app; if (NS_SUCCEEDED(vfs->GetAppForMimeType(mType, getter_AddRefs(app))) && app) return app->Launch(nativePath); } if (!mDefaultApplication) return NS_ERROR_FILE_NOT_FOUND; return LaunchWithIProcess(mDefaultApplication, nativePath); } #ifdef MOZ_PLATFORM_HILDON + +/* This method tries to launch the associated default handler for the given + * mime/file via hildon specific APIs (in this case hildon_mime_open_file* + * which are essetially wrappers to the DBUS mime_open method). + */ + +nsresult +nsMIMEInfoUnix::LaunchDefaultWithDBus(const char *aFilePath) +{ + const PRInt32 kHILDON_SUCCESS = 1; + PRInt32 result = 0; + DBusError err; + dbus_error_init(&err); + + DBusConnection *connection = dbus_bus_get(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) { + dbus_error_free(&err); + return NS_ERROR_FAILURE; + } + + if (nsnull == connection) + return NS_ERROR_FAILURE; + + result = hildon_mime_open_file_with_mime_type(connection, + aFilePath, + mType.get()); + if (result != kHILDON_SUCCESS) + if (hildon_mime_open_file(connection, aFilePath) != kHILDON_SUCCESS) + return NS_ERROR_FAILURE; + + return NS_OK; +} /* static */ PRBool nsMIMEInfoUnix::HandlerExists(const char *aProtocolScheme) { PRBool isEnabled = PR_FALSE; HildonURIAction *action = hildon_uri_get_default_action(aProtocolScheme, nsnull); if (action) { isEnabled = PR_TRUE; diff --git a/uriloader/exthandler/unix/nsMIMEInfoUnix.h b/uriloader/exthandler/unix/nsMIMEInfoUnix.h --- a/uriloader/exthandler/unix/nsMIMEInfoUnix.h +++ b/uriloader/exthandler/unix/nsMIMEInfoUnix.h @@ -53,13 +53,14 @@ public: protected: NS_IMETHOD GetHasDefaultHandler(PRBool *_retval); virtual NS_HIDDEN_(nsresult) LoadUriInternal(nsIURI *aURI); virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile *aFile); #ifdef MOZ_PLATFORM_HILDON + nsresult LaunchDefaultWithDBus(const char *aFilePath); NS_IMETHOD GetPossibleApplicationHandlers(nsIMutableArray * *aPossibleAppHandlers); #endif }; #endif // nsMIMEInfoUnix_h_