From 717bd8d70c401d01ec90ac85c5c0e326fd9f47e3 Mon Sep 17 00:00:00 2001 From: Wolfgang Rosenauer Date: Fri, 30 Jul 2010 12:46:20 -0700 Subject: [PATCH] Bug 562897 - Add required implementation to open files on Maemo 6. r=dougt --HG-- extra : rebase_source : 49d8fbe234bf447b87486ac4404a148d676e009c --- configure.in | 8 ++ uriloader/exthandler/Makefile.in | 6 +- uriloader/exthandler/nsContentHandlerApp.cpp | 111 ++++++++++++++++++ uriloader/exthandler/nsContentHandlerApp.h | 63 ++++++++++ uriloader/exthandler/unix/nsMIMEInfoUnix.cpp | 68 +++++++++++ uriloader/exthandler/unix/nsMIMEInfoUnix.h | 3 + .../exthandler/unix/nsOSHelperAppService.cpp | 14 +++ xpcom/io/Makefile.in | 11 +- xpcom/io/nsLocalFileUnix.cpp | 17 +++ 9 files changed, 297 insertions(+), 4 deletions(-) create mode 100644 uriloader/exthandler/nsContentHandlerApp.cpp create mode 100644 uriloader/exthandler/nsContentHandlerApp.h diff --git a/configure.in b/configure.in index e9f5f14dcb0..70a709e62a4 100644 --- a/configure.in +++ b/configure.in @@ -6889,6 +6889,14 @@ if test $MOZ_PLATFORM_MAEMO; then fi fi + if test $MOZ_PLATFORM_MAEMO = 6; then + PKG_CHECK_MODULES(LIBCONTENTACTION, contentaction-0.1, _LIB_FOUND=1, _LIB_FOUND=) + MOZ_PLATFORM_MAEMO_LIBS="$MOZ_PLATFORM_MAEMO_LIBS $LIBCONTENTACTION_LIBS" + MOZ_PLATFORM_MAEMO_CFLAGS="$MOZ_PLATFORM_MAEMO_CFLAGS $LIBCONTENTACTION_CFLAGS" + if test -z "$_LIB_FOUND"; then + AC_MSG_ERROR([libcontentaction is required when build for Maemo]) + fi + fi if test "$MOZ_PLATFORM_MAEMO" -gt 5; then MOZ_THUMB2=1 diff --git a/uriloader/exthandler/Makefile.in b/uriloader/exthandler/Makefile.in index 2fa1b5ac39f..5d68475e79b 100644 --- a/uriloader/exthandler/Makefile.in +++ b/uriloader/exthandler/Makefile.in @@ -144,7 +144,7 @@ LOCAL_INCLUDES += $(TK_CFLAGS) $(MOZ_DBUS_CFLAGS) EXTRA_DSO_LDOPTS += $(MOZ_DBUS_LIBS) endif -ifdef MOZ_PLATFORM_MAEMO +ifeq ($(MOZ_PLATFORM_MAEMO),5) ifdef MOZ_ENABLE_GNOMEVFS LOCAL_INCLUDES += $(MOZ_GNOMEVFS_CFLAGS) EXTRA_DSO_LDOPTS += $(MOZ_GNOMEVFS_LIBS) @@ -155,6 +155,10 @@ EXTRA_DSO_LDOPTS += $(MOZ_GIO_LIBS) endif endif +ifeq ($(MOZ_PLATFORM_MAEMO),6) +CPPSRCS += nsContentHandlerApp.cpp +endif + ifeq ($(OS_ARCH),WINNT WINCE) OS_LIBS += shell32.lib GARBAGE += nsOSHelperAppService.cpp $(srcdir)/nsOSHelperAppService.cpp \ diff --git a/uriloader/exthandler/nsContentHandlerApp.cpp b/uriloader/exthandler/nsContentHandlerApp.cpp new file mode 100644 index 00000000000..58b6aab8181 --- /dev/null +++ b/uriloader/exthandler/nsContentHandlerApp.cpp @@ -0,0 +1,111 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * vim:expandtab:shiftwidth=2:tabstop=2:cin: + * ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is libcontentaction integration. + * + * The Initial Developer of the Original Code is + * the Nokia Corporation. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Egor Starkov + * + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * 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 ***** */ + +#include "nsContentHandlerApp.h" +#include "nsIURI.h" +#include "nsIGenericFactory.h" +#include "nsIClassInfoImpl.h" +#include "nsCOMPtr.h" +#include "nsString.h" + +NS_IMPL_ISUPPORTS1_CI(nsContentHandlerApp, nsIHandlerApp) + +nsContentHandlerApp::nsContentHandlerApp(nsString aName, nsCString aType, + ContentAction::Action& aAction) : + mName(aName), + mType(aType), + mAction(aAction) +{ +} + +//////////////////////////////////////////////////////////////////////////////// +//// nsIHandlerInfo + +NS_IMETHODIMP nsContentHandlerApp::GetName(nsAString& aName) +{ + aName.Assign(mName); + return NS_OK; +} + +NS_IMETHODIMP nsContentHandlerApp::SetName(const nsAString& aName) +{ + mName.Assign(aName); + return NS_OK; +} + +NS_IMETHODIMP nsContentHandlerApp::Equals(nsIHandlerApp *aHandlerApp, PRBool *_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP nsContentHandlerApp::GetDetailedDescription(nsAString& aDetailedDescription) +{ + aDetailedDescription.Assign(mDetailedDescription); + return NS_OK; +} + +NS_IMETHODIMP nsContentHandlerApp::SetDetailedDescription(const nsAString& aDetailedDescription) +{ + mDetailedDescription.Assign(aDetailedDescription); + return NS_OK; +} + +NS_IMETHODIMP +nsContentHandlerApp::LaunchWithURI(nsIURI *aURI, + nsIInterfaceRequestor *aWindowContext) +{ + nsCAutoString spec; + nsresult rv = aURI->GetAsciiSpec(spec); + NS_ENSURE_SUCCESS(rv,rv); + const char* url = spec.get(); + + QList actions = + ContentAction::Action::actionsForFile(QUrl(url), QString(mType.get())); + for (int i = 0; i < actions.size(); ++i) { + if (actions[i].name() == QString((QChar*)mName.get(), mName.Length())) { + actions[i].trigger(); + break; + } + } + + return NS_OK; +} + +NS_DECL_CLASSINFO(nsContentHandlerApp) + diff --git a/uriloader/exthandler/nsContentHandlerApp.h b/uriloader/exthandler/nsContentHandlerApp.h new file mode 100644 index 00000000000..6e353635cb9 --- /dev/null +++ b/uriloader/exthandler/nsContentHandlerApp.h @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * vim:expandtab:shiftwidth=2:tabstop=2:cin: + * ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla browser. + * + * The Initial Developer of the Original Code is + * the Nokia Corporation. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Egor Starkov + * + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * 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 ***** */ + +#ifndef __nsContentHandlerAppImpl_h__ +#define __nsContentHandlerAppImpl_h__ + +#include +#include "nsString.h" +#include "nsIMIMEInfo.h" + +class nsContentHandlerApp : public nsIHandlerApp +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIHANDLERAPP + + nsContentHandlerApp(nsString aName, nsCString aType, ContentAction::Action& aAction); + virtual ~nsContentHandlerApp() { } + +protected: + nsString mName; + nsCString mType; + nsString mDetailedDescription; + + ContentAction::Action mAction; +}; +#endif diff --git a/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp b/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp index 71dab23cfca..b2c3f31f1f6 100644 --- a/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp +++ b/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp @@ -22,6 +22,7 @@ * * Contributor(s): * Shawn Wilsher (Original Author) + * Wolfgang Rosenauer * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -43,6 +44,13 @@ #include #include #endif +#if (MOZ_PLATFORM_MAEMO == 6) +#include +#include +#include +#include +#include "nsContentHandlerApp.h" +#endif #include "nsMIMEInfoUnix.h" #include "nsGNOMERegistry.h" @@ -57,6 +65,7 @@ nsresult nsMIMEInfoUnix::LoadUriInternal(nsIURI * aURI) { nsresult rv = nsGNOMERegistry::LoadURL(aURI); + #if (MOZ_PLATFORM_MAEMO == 5) && defined (MOZ_ENABLE_GNOMEVFS) if (NS_FAILED(rv)){ HildonURIAction *action = hildon_uri_get_default_action(mSchemeOrType.get(), nsnull); @@ -69,6 +78,17 @@ nsMIMEInfoUnix::LoadUriInternal(nsIURI * aURI) } } #endif + +#if (MOZ_PLATFORM_MAEMO == 6) + if (NS_FAILED(rv)) { + nsCAutoString spec; + aURI->GetAsciiSpec(spec); + if (QDesktopServices::openUrl(QUrl(spec.get()))) { + rv = NS_OK; + } + } +#endif + return rv; } @@ -99,6 +119,15 @@ nsMIMEInfoUnix::GetHasDefaultHandler(PRBool *_retval) } #endif +#if (MOZ_PLATFORM_MAEMO == 6) + ContentAction::Action action = + ContentAction::Action::defaultActionForFile(QUrl(), QString(mSchemeOrType.get())); + if (action.isValid()) { + *_retval = PR_TRUE; + return NS_OK; + } +#endif + // If we didn't find a VFS handler, fallback. return nsMIMEInfoImpl::GetHasDefaultHandler(_retval); } @@ -114,6 +143,17 @@ nsMIMEInfoUnix::LaunchDefaultWithFile(nsIFile *aFile) return NS_OK; #endif +#if (MOZ_PLATFORM_MAEMO == 6) + QUrl uri = QUrl::fromLocalFile(QString::fromUtf8(nativePath.get())); + ContentAction::Action action = + ContentAction::Action::defaultActionForFile(uri, QString(mSchemeOrType.get())); + if (action.isValid()) { + action.trigger(); + return NS_OK; + } + return NS_ERROR_FAILURE; +#endif + nsCOMPtr giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID); nsCOMPtr gnomevfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID); if (giovfs) { @@ -246,3 +286,31 @@ nsMIMEInfoUnix::GetPossibleApplicationHandlers(nsIMutableArray ** aPossibleAppHa return NS_OK; } #endif + +#if (MOZ_PLATFORM_MAEMO == 6) +NS_IMETHODIMP +nsMIMEInfoUnix::GetPossibleApplicationHandlers(nsIMutableArray ** aPossibleAppHandlers) +{ + if (!mPossibleApplications) { + mPossibleApplications = do_CreateInstance(NS_ARRAY_CONTRACTID); + + if (!mPossibleApplications) + return NS_ERROR_OUT_OF_MEMORY; + + QList actions = + ContentAction::Action::actionsForFile(QUrl(), QString(mSchemeOrType.get())); + + for (int i = 0; i < actions.size(); ++i) { + nsContentHandlerApp* app = + new nsContentHandlerApp(nsString((PRUnichar*)actions[i].name().data()), + mSchemeOrType, actions[i]); + mPossibleApplications->AppendElement(app, PR_FALSE); + } + } + + *aPossibleAppHandlers = mPossibleApplications; + NS_ADDREF(*aPossibleAppHandlers); + return NS_OK; +} +#endif + diff --git a/uriloader/exthandler/unix/nsMIMEInfoUnix.h b/uriloader/exthandler/unix/nsMIMEInfoUnix.h index f05ae505cc5..63a7f59254a 100644 --- a/uriloader/exthandler/unix/nsMIMEInfoUnix.h +++ b/uriloader/exthandler/unix/nsMIMEInfoUnix.h @@ -61,6 +61,9 @@ protected: nsresult LaunchDefaultWithDBus(const char *aFilePath); NS_IMETHOD GetPossibleApplicationHandlers(nsIMutableArray * *aPossibleAppHandlers); #endif +#if (MOZ_PLATFORM_MAEMO == 6) + NS_IMETHOD GetPossibleApplicationHandlers(nsIMutableArray * *aPossibleAppHandlers); +#endif }; #endif // nsMIMEInfoUnix_h_ diff --git a/uriloader/exthandler/unix/nsOSHelperAppService.cpp b/uriloader/exthandler/unix/nsOSHelperAppService.cpp index a0806068e4d..756dea4cd92 100644 --- a/uriloader/exthandler/unix/nsOSHelperAppService.cpp +++ b/uriloader/exthandler/unix/nsOSHelperAppService.cpp @@ -41,6 +41,11 @@ #include #include +#if (MOZ_PLATFORM_MAEMO == 6) +#include +#include +#endif + #include "nsOSHelperAppService.h" #include "nsMIMEInfoUnix.h" #ifdef MOZ_WIDGET_GTK2 @@ -1208,6 +1213,15 @@ nsresult nsOSHelperAppService::OSProtocolHandlerExists(const char * aProtocolSch aProtocolScheme)); *aHandlerExists = PR_FALSE; +#if (MOZ_PLATFORM_MAEMO == 6) + // libcontentaction requires character ':' after scheme + ContentAction::Action action = + ContentAction::Action::defaultActionForScheme(QString(aProtocolScheme) + ':'); + + if (action.isValid()) + *aHandlerExists = PR_TRUE; +#endif + #ifdef MOZ_WIDGET_GTK2 // Check the GConf registry for a protocol handler *aHandlerExists = nsGNOMERegistry::HandlerExists(aProtocolScheme); diff --git a/xpcom/io/Makefile.in b/xpcom/io/Makefile.in index a9caa057653..baa53d0e20a 100644 --- a/xpcom/io/Makefile.in +++ b/xpcom/io/Makefile.in @@ -198,8 +198,13 @@ endif LOCAL_INCLUDES = -I.. -ifeq ($(MOZ_PLATFORM_MAEMO), 5) -CFLAGS += $(MOZ_DBUS_CFLAGS) $(MOZ_PLATFORM_MAEMO_CFLAGS) -CXXFLAGS += $(MOZ_DBUS_CFLAGS) $(MOZ_PLATFORM_MAEMO_CFLAGS) +ifeq ($(MOZ_PLATFORM_MAEMO),5) +CFLAGS += $(MOZ_DBUS_CFLAGS) +CXXFLAGS += $(MOZ_DBUS_CFLAGS) +endif + +ifdef MOZ_PLATFORM_MAEMO +CFLAGS += $(MOZ_PLATFORM_MAEMO_CFLAGS) +CXXFLAGS += $(MOZ_PLATFORM_MAEMO_CFLAGS) endif diff --git a/xpcom/io/nsLocalFileUnix.cpp b/xpcom/io/nsLocalFileUnix.cpp index c8a3476ab34..7b0f4da96a8 100644 --- a/xpcom/io/nsLocalFileUnix.cpp +++ b/xpcom/io/nsLocalFileUnix.cpp @@ -72,6 +72,12 @@ #include #endif +#if (MOZ_PLATFORM_MAEMO == 6) +#include +#include +#include +#endif + #include "nsDirectoryServiceDefs.h" #include "nsCRT.h" #include "nsCOMPtr.h" @@ -1891,6 +1897,17 @@ nsLocalFile::Launch() return NS_ERROR_FAILURE; #endif +#elif (MOZ_PLATFORM_MAEMO == 6) + QUrl uri = QUrl::fromLocalFile(QString::fromUtf8(mPath.get())); + ContentAction::Action action = + ContentAction::Action::defaultActionForFile(uri); + + if (action.isValid()) { + action.trigger(); + return NS_OK; + } + + return NS_ERROR_FAILURE; #elif defined(ANDROID) // Try to get a mimetype, if this fails just use the file uri alone nsresult rv;