From 27a2f554ac3900e650b84768e75d4541970c4831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabrice=20Desr=C3=A9?= Date: Fri, 15 Oct 2010 14:16:45 -0400 Subject: [PATCH] Bug 590225 - webapps OS level integration for Android a=blocking-fennec, r=mwu,vladimir, blassey --- embedding/android/AndroidManifest.xml.in | 7 +- embedding/android/GeckoApp.java | 9 +++ embedding/android/GeckoAppShell.java | 20 +++++ toolkit/components/Makefile.in | 1 + toolkit/components/build/Makefile.in | 10 +++ toolkit/components/build/nsToolkitCompsCID.h | 7 ++ .../components/build/nsToolkitCompsModule.cpp | 18 +++++ toolkit/components/webapps/Makefile.in | 65 ++++++++++++++++ .../components/webapps/nsIWebappsSupport.idl | 60 ++++++++++++++ .../components/webapps/nsWebappsSupport.cpp | 78 +++++++++++++++++++ toolkit/components/webapps/nsWebappsSupport.h | 56 +++++++++++++ widget/src/android/AndroidBridge.cpp | 5 ++ widget/src/android/AndroidBridge.h | 5 ++ widget/src/android/nsAppShell.cpp | 1 - 14 files changed, 338 insertions(+), 4 deletions(-) create mode 100644 toolkit/components/webapps/Makefile.in create mode 100644 toolkit/components/webapps/nsIWebappsSupport.idl create mode 100644 toolkit/components/webapps/nsWebappsSupport.cpp create mode 100644 toolkit/components/webapps/nsWebappsSupport.h diff --git a/embedding/android/AndroidManifest.xml.in b/embedding/android/AndroidManifest.xml.in index e434976ef904..a4acae6ca610 100644 --- a/embedding/android/AndroidManifest.xml.in +++ b/embedding/android/AndroidManifest.xml.in @@ -9,9 +9,10 @@ - - - + + + + +# +# Alternatively, the contents of this file may be used under the terms of +# either 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 ***** + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE_NAME = webapps +MODULE = webapps + +ifeq (Android,$(OS_TARGET)) +LIBRARY_NAME = webapps_s +LIBXUL_LIBRARY = 1 +IS_COMPONENT = 1 +EXPORT_LIBRARY = 1 + +CPPSRCS = \ + nsWebappsSupport.cpp \ + $(NULL) + +EXTRA_DSO_LDOPTS += \ + $(MOZ_COMPONENT_LIBS) \ + $(NULL) +endif + +XPIDLSRCS = nsIWebappsSupport.idl + +include $(topsrcdir)/config/rules.mk diff --git a/toolkit/components/webapps/nsIWebappsSupport.idl b/toolkit/components/webapps/nsIWebappsSupport.idl new file mode 100644 index 000000000000..694b09ddcf5c --- /dev/null +++ b/toolkit/components/webapps/nsIWebappsSupport.idl @@ -0,0 +1,60 @@ +/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- + * ***** 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 Mozilla Webapp code. + * + * The Initial Developer of the Original Code is Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Fabrice Desré + * + * Alternatively, the contents of this file may be used under the terms of + * either 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 "nsISupports.idl" + +[scriptable, uuid(adb91273-0cf1-4bbe-a37b-22e660192e2a)] +interface nsIWebappsSupport : nsISupports +{ + /** + * This method installs a web app. + * + * @param title the user-friendly name of the application. + * @param uri the uri of the web app. + * @param iconData a base64 encoded representation of the application's icon. + */ + void installApplication(in wstring title, in wstring uri, in wstring iconUri, in wstring iconData); + + /** + * Checks is a web app is already installed + * + * @param uri the uri of the web app + * @return true if the web app is installed, false if it's not installed + */ + boolean isApplicationInstalled(in wstring uri); +}; + diff --git a/toolkit/components/webapps/nsWebappsSupport.cpp b/toolkit/components/webapps/nsWebappsSupport.cpp new file mode 100644 index 000000000000..f8ebb308439c --- /dev/null +++ b/toolkit/components/webapps/nsWebappsSupport.cpp @@ -0,0 +1,78 @@ +/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- + * ***** 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 Mozilla Webapp code. + * + * The Initial Developer of the Original Code is Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Fabrice Desré + * + * Alternatively, the contents of this file may be used under the terms of + * either 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 "AndroidBridge.h" +#include "nsCRTGlue.h" +#include "nsWebappsSupport.h" + +using namespace mozilla; + +NS_IMPL_ISUPPORTS1(nsWebappsSupport, nsIWebappsSupport) + +NS_IMETHODIMP +nsWebappsSupport::InstallApplication(const PRUnichar *aTitle, const PRUnichar *aURI, const PRUnichar *aIconURI, const PRUnichar *aIconData) +{ + ALOG("in nsWebappsSupport::InstallApplication()\n"); + AndroidBridge::AutoLocalJNIFrame jniFrame; + JNIEnv *jEnv = GetJNIForThread(); + jclass jGeckoAppShellClass = GetGeckoAppShellClass(); + + if (!jEnv || !jGeckoAppShellClass) + return NS_ERROR_FAILURE; + + jmethodID jInstallWebApplication = jEnv->GetStaticMethodID(jGeckoAppShellClass, "installWebApplication", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); + jstring jstrURI = jEnv->NewString(aURI, NS_strlen(aURI)); + jstring jstrTitle = jEnv->NewString(aTitle, NS_strlen(aTitle)); + jstring jstrIconData = jEnv->NewString(aIconData, NS_strlen(aIconData)); + + if (!jstrURI || !jstrTitle || !jstrIconData) + return NS_ERROR_FAILURE; + + jEnv->CallStaticVoidMethod(jGeckoAppShellClass, jInstallWebApplication, jstrURI, jstrTitle, jstrIconData); + return NS_OK; +} + +/* + * we have no way to know if an application is installed, so pretend it's not installed + */ +NS_IMETHODIMP +nsWebappsSupport::IsApplicationInstalled(const PRUnichar *aURI, PRBool *_retval) +{ + *_retval = PR_FALSE; + return NS_OK; +} + diff --git a/toolkit/components/webapps/nsWebappsSupport.h b/toolkit/components/webapps/nsWebappsSupport.h new file mode 100644 index 000000000000..49b4cc79482a --- /dev/null +++ b/toolkit/components/webapps/nsWebappsSupport.h @@ -0,0 +1,56 @@ +/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- + * ***** 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 Mozilla Webapp code. + * + * The Initial Developer of the Original Code is Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Fabrice Desré + * + * Alternatively, the contents of this file may be used under the terms of + * either 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 nsWebappsSupport_h__ +#define nsWebappsSupport_h__ + +#include "nsIWebappsSupport.h" + +class nsWebappsSupport : public nsIWebappsSupport +{ +public: + + NS_DECL_ISUPPORTS + NS_DECL_NSIWEBAPPSSUPPORT + + nsWebappsSupport() {}; + ~nsWebappsSupport() {}; + +}; + +#endif // nsWebappsSupport_h__ + diff --git a/widget/src/android/AndroidBridge.cpp b/widget/src/android/AndroidBridge.cpp index 3baad7501f5a..d45405b51988 100644 --- a/widget/src/android/AndroidBridge.cpp +++ b/widget/src/android/AndroidBridge.cpp @@ -577,3 +577,8 @@ extern "C" JNIEnv * GetJNIForThread() { return mozilla::AndroidBridge::JNIForThread(); } + +jclass GetGeckoAppShellClass() +{ + return mozilla::AndroidBridge::GetGeckoAppShellClass(); +} diff --git a/widget/src/android/AndroidBridge.h b/widget/src/android/AndroidBridge.h index 49bf3de24863..4c2a8d195f7b 100644 --- a/widget/src/android/AndroidBridge.h +++ b/widget/src/android/AndroidBridge.h @@ -90,6 +90,10 @@ public: return sBridge->AttachThread(); return nsnull; } + + static jclass GetGeckoAppShellClass() { + return sBridge->mGeckoAppShellClass; + } // The bridge needs to be constructed via ConstructBridge first, // and then once the Gecko main thread is spun up (Gecko side), @@ -236,5 +240,6 @@ protected: extern "C" JNIEnv * GetJNIForThread(); extern PRBool mozilla_AndroidBridge_SetMainThread(void *); +extern jclass GetGeckoAppShellClass(); #endif /* AndroidBridge_h__ */ diff --git a/widget/src/android/nsAppShell.cpp b/widget/src/android/nsAppShell.cpp index d33354ef6bbf..83528705fe71 100644 --- a/widget/src/android/nsAppShell.cpp +++ b/widget/src/android/nsAppShell.cpp @@ -129,7 +129,6 @@ nsAppShell::ScheduleNativeEventCallback() PostEvent(new AndroidGeckoEvent(AndroidGeckoEvent::NATIVE_POKE)); } - PRBool nsAppShell::ProcessNextNativeEvent(PRBool mayWait) {