Bug 590225 - webapps OS level integration : Android a=blocking-fennec, r=mwu, r=vladimir

This commit is contained in:
Brad Lassey 2010-10-04 10:54:40 -04:00
Родитель 3ffc13d76a
Коммит 1cfac33589
14 изменённых файлов: 344 добавлений и 4 удалений

Просмотреть файл

@ -9,9 +9,10 @@
<uses-sdk android:minSdkVersion="5"
android:targetSdkVersion="5"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<application android:label="@MOZ_APP_DISPLAYNAME@"
android:icon="@drawable/icon"

Просмотреть файл

@ -203,6 +203,15 @@ abstract public class GeckoApp
GeckoAppShell.sendEventToGecko(new GeckoEvent(uri));
Log.i("GeckoApp","onNewIntent: "+uri);
}
else if (Intent.ACTION_MAIN.equals(action)) {
Log.i("GeckoApp", "Intent : ACTION_MAIN");
GeckoAppShell.sendEventToGecko(new GeckoEvent(""));
}
else if (action.equals("org.mozilla.fennec.WEBAPP")) {
String uri = intent.getStringExtra("args");
GeckoAppShell.sendEventToGecko(new GeckoEvent(uri));
Log.i("GeckoApp","Intent : WEBAPP - " + uri);
}
}
@Override

Просмотреть файл

@ -360,6 +360,26 @@ class GeckoAppShell
Log.i("GeckoAppJava", "scheduling restart");
gRestartScheduled = true;
}
// "Installs" an application by creating a shortcut
static void installWebApplication(String aURI, String aTitle, String aIconData) {
Log.w("GeckoAppJava", "installWebApplication for " + aURI + " [" + aTitle + "]");
// the intent to be launched by the shortcut
Intent shortcutIntent = new Intent("org.mozilla.fennec.WEBAPP");
shortcutIntent.setClassName(GeckoApp.mAppContext,
"org.mozilla." + GeckoApp.mAppContext.getAppName() + ".App");
shortcutIntent.putExtra("args", "--webapp=" + aURI);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, aTitle);
byte[] raw = Base64.decode(aIconData.substring(22), Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(raw, 0, raw.length);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
GeckoApp.mAppContext.sendBroadcast(intent);
}
static String[] getHandlersForMimeType(String aMimeType, String aAction) {
Intent intent = getIntentForActionString(aAction);

Просмотреть файл

@ -70,6 +70,7 @@ PARALLEL_DIRS += \
typeaheadfind \
urlformatter \
viewconfig \
webapps \
$(NULL)
ifdef BUILD_CTYPES

Просмотреть файл

@ -80,6 +80,12 @@ LOCAL_INCLUDES += \
$(NULL)
endif
ifeq (Android,$(OS_TARGET))
LOCAL_INCLUDES += \
-I$(srcdir)/../webapps \
$(NULL)
endif
SHARED_LIBRARY_LIBS = \
../find/src/$(LIB_PREFIX)mozfind_s.$(LIB_SUFFIX) \
../typeaheadfind/src/$(LIB_PREFIX)fastfind_s.$(LIB_SUFFIX) \
@ -120,6 +126,10 @@ ifdef MOZ_FEEDS
SHARED_LIBRARY_LIBS += ../feeds/src/$(LIB_PREFIX)feed_s.$(LIB_SUFFIX)
endif
ifeq (Android,$(OS_TARGET))
SHARED_LIBRARY_LIBS += ../webapps/$(LIB_PREFIX)webapps_s.$(LIB_SUFFIX)
endif
EXTRA_DSO_LIBS = gkgfx
EXTRA_DSO_LDOPTS += \

Просмотреть файл

@ -119,6 +119,9 @@
#define NS_APPSTARTUP_CONTRACTID \
"@mozilla.org/toolkit/app-startup;1"
#define NS_WEBAPPSSUPPORT_CONTRACTID \
"@mozilla.org/webapps/installer;1"
/////////////////////////////////////////////////////////////////////////////
// {A0CCAAF8-09DA-44D8-B250-9AC3E93C8117}
@ -202,3 +205,7 @@
// {6fb0c970-e1b1-11db-8314-0800200c9a66}
#define NS_PLACESIMPORTEXPORTSERVICE_CID \
{ 0x6fb0c970, 0xe1b1, 0x11db, { 0x83, 0x14, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 } }
#define NS_WEBAPPSSUPPORT_CID \
{ 0xd0b62752, 0x88be, 0x4c88, {0x94, 0xe5, 0xc6, 0x9e, 0x15, 0xa1, 0x0c, 0x4e} }

Просмотреть файл

@ -72,6 +72,10 @@
#include "nsBrowserStatusFilter.h"
#ifdef ANDROID
#include "nsWebappsSupport.h"
#endif
/////////////////////////////////////////////////////////////////////////////
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsAppStartup, Init)
@ -125,6 +129,10 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptableUnescapeHTML)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBrowserStatusFilter)
#ifdef ANDROID
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebappsSupport)
#endif
NS_DEFINE_NAMED_CID(NS_TOOLKIT_APPSTARTUP_CID);
NS_DEFINE_NAMED_CID(NS_USERINFO_CID);
#ifdef ALERTS_SERVICE
@ -151,6 +159,10 @@ NS_DEFINE_NAMED_CID(NS_SCRIPTABLEUNESCAPEHTML_CID);
NS_DEFINE_NAMED_CID(NS_BROWSERSTATUSFILTER_CID);
NS_DEFINE_NAMED_CID(NS_CHARSETMENU_CID);
#ifdef ANDROID
NS_DEFINE_NAMED_CID(NS_WEBAPPSSUPPORT_CID);
#endif
static const mozilla::Module::CIDEntry kToolkitCIDs[] = {
{ &kNS_TOOLKIT_APPSTARTUP_CID, false, NULL, nsAppStartupConstructor },
{ &kNS_USERINFO_CID, false, NULL, nsUserInfoConstructor },
@ -177,6 +189,9 @@ static const mozilla::Module::CIDEntry kToolkitCIDs[] = {
#endif
{ &kNS_BROWSERSTATUSFILTER_CID, false, NULL, nsBrowserStatusFilterConstructor },
{ &kNS_CHARSETMENU_CID, false, NULL, NS_NewCharsetMenu },
#ifdef ANDROID
{ &kNS_WEBAPPSSUPPORT_CID, false, NULL, nsWebappsSupportConstructor },
#endif
{ NULL }
};
@ -207,6 +222,9 @@ static const mozilla::Module::ContractIDEntry kToolkitContracts[] = {
#endif
{ NS_BROWSERSTATUSFILTER_CONTRACTID, &kNS_BROWSERSTATUSFILTER_CID },
{ NS_RDF_DATASOURCE_CONTRACTID_PREFIX NS_CHARSETMENU_PID, &kNS_CHARSETMENU_CID },
#ifdef ANDROID
{ NS_WEBAPPSSUPPORT_CONTRACTID, &kNS_WEBAPPSSUPPORT_CID },
#endif
{ NULL }
};

Просмотреть файл

@ -0,0 +1,71 @@
# ***** 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
# the Mozilla Foundation.
# Portions created by the Initial Developer are Copyright (C) 2010
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Fabrice Desré <fabrice@mozilla.com>
#
# 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
LIBRARY_NAME = webapps_s
LIBXUL_LIBRARY = 1
IS_COMPONENT = 1
EXPORT_LIBRARY = 1
REQUIRES = xpcom \
string \
$(NULL)
ifeq (Android,$(OS_TARGET))
CPPSRCS = \
nsWebappsSupport.cpp \
$(NULL)
endif
XPIDLSRCS = nsIWebappsSupport.idl
EXTRA_DSO_LDOPTS += \
$(MOZ_COMPONENT_LIBS) \
$(XPCOM_GLUE_LDOPTS) \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -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é <fabrice@mozilla.com>
*
* 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);
};

Просмотреть файл

@ -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é <fabrice@mozilla.com>
*
* 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;
}

Просмотреть файл

@ -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é <fabrice@mozilla.com>
*
* 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__

Просмотреть файл

@ -562,3 +562,8 @@ extern "C" JNIEnv * GetJNIForThread()
{
return mozilla::AndroidBridge::JNIForThread();
}
jclass GetGeckoAppShellClass()
{
return mozilla::AndroidBridge::GetGeckoAppShellClass();
}

Просмотреть файл

@ -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),
@ -230,5 +234,6 @@ protected:
extern "C" JNIEnv * GetJNIForThread();
extern PRBool mozilla_AndroidBridge_SetMainThread(void *);
extern jclass GetGeckoAppShellClass();
#endif /* AndroidBridge_h__ */

Просмотреть файл

@ -129,7 +129,6 @@ nsAppShell::ScheduleNativeEventCallback()
PostEvent(new AndroidGeckoEvent(AndroidGeckoEvent::NATIVE_POKE));
}
PRBool
nsAppShell::ProcessNextNativeEvent(PRBool mayWait)
{