Bug 562897 - Add required implementation to open files on Maemo 6. r=dougt

--HG--
extra : rebase_source : 49d8fbe234bf447b87486ac4404a148d676e009c
This commit is contained in:
Wolfgang Rosenauer 2010-07-30 12:46:20 -07:00
parent 8b30a102a6
commit 717bd8d70c
9 changed files with 297 additions and 4 deletions

View File

@ -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

View File

@ -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 \

View File

@ -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 <starkov.egor@gmail.com>
*
* 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<ContentAction::Action> 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)

View File

@ -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 <starkov.egor@gmail.com>
*
* 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 <contentaction/contentaction.h>
#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

View File

@ -22,6 +22,7 @@
*
* Contributor(s):
* Shawn Wilsher <me@shawnwilsher.com> (Original Author)
* Wolfgang Rosenauer <wr@rosenauer.org>
*
* 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 <hildon-mime.h>
#include <libosso.h>
#endif
#if (MOZ_PLATFORM_MAEMO == 6)
#include <QDesktopServices>
#include <QUrl>
#include <QString>
#include <contentaction/contentaction.h>
#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<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
nsCOMPtr<nsIGnomeVFSService> 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<ContentAction::Action> 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

View File

@ -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_

View File

@ -41,6 +41,11 @@
#include <sys/types.h>
#include <sys/stat.h>
#if (MOZ_PLATFORM_MAEMO == 6)
#include <contentaction/contentaction.h>
#include <QString>
#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);

View File

@ -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

View File

@ -72,6 +72,12 @@
#include <sys/quota.h>
#endif
#if (MOZ_PLATFORM_MAEMO == 6)
#include <QUrl>
#include <QString>
#include <contentaction/contentaction.h>
#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;