Bug 782211 - Part 1: Implemented additional functionality in Fennec to support Notification API. r=wesj

This commit is contained in:
William Chen 2013-03-18 06:24:53 -07:00
parent c4023b941a
commit 41cc11a176
6 changed files with 35 additions and 18 deletions

View File

@ -56,6 +56,10 @@ public class AlertNotification
try {
URL url = new URL(aIconUri.toString());
Bitmap bm = BitmapFactory.decodeStream(url.openStream());
if (bm == null) {
Log.e(LOGTAG, "failed to decode icon");
return;
}
view.setImageViewBitmap(R.id.notification_image, bm);
view.setTextViewText(R.id.notification_title, mTitle);
if (mText.length() > 0) {

View File

@ -79,6 +79,7 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URL;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@ -106,6 +107,9 @@ public class GeckoAppShell
static private GeckoEditableListener mEditableListener = null;
static private final HashMap<String, String>
mAlertCookies = new HashMap<String, String>();
/* Keep in sync with constants found here:
http://mxr.mozilla.org/mozilla-central/source/uriloader/base/nsIWebProgressListener.idl
*/
@ -1204,6 +1208,9 @@ public class GeckoAppShell
clearNotificationIntent.setData(dataUri);
PendingIntent clearIntent = PendingIntent.getBroadcast(GeckoApp.mAppContext, 0, clearNotificationIntent, 0);
mAlertCookies.put(aAlertName, aAlertCookie);
callObserver(aAlertName, "alertshow", aAlertCookie);
sNotificationClient.add(notificationID, aImageUrl, aAlertTitle, aAlertText, contentIntent, clearIntent);
}
@ -1217,11 +1224,17 @@ public class GeckoAppShell
}
}
public static void alertsProgressListener_OnCancel(String aAlertName) {
public static void closeNotification(String aAlertName) {
String alertCookie = mAlertCookies.get(aAlertName);
if (alertCookie != null) {
callObserver(aAlertName, "alertfinished", alertCookie);
mAlertCookies.remove(aAlertName);
}
removeObserver(aAlertName);
int notificationID = aAlertName.hashCode();
removeNotification(notificationID);
sNotificationClient.remove(notificationID);
}
public static void handleNotification(String aAction, String aAlertName, String aAlertCookie) {
@ -1236,19 +1249,12 @@ public class GeckoAppShell
}
}
callObserver(aAlertName, "alertfinished", aAlertCookie);
// Also send a notification to the observer service
// New listeners should register for these notifications since they will be called even if
// Gecko has been killed and restared between when your notification was shown and when the
// user clicked on it.
sendEventToGecko(GeckoEvent.createBroadcastEvent("Notification:Clicked", aAlertCookie));
removeObserver(aAlertName);
removeNotification(notificationID);
}
private static void removeNotification(int notificationID) {
sNotificationClient.remove(notificationID);
closeNotification(aAlertName);
}
public static int getDpi() {

View File

@ -69,8 +69,14 @@ ContentPermissionPrompt.prototype = {
label: browserBundle.GetStringFromName(entityName + ".allow"),
callback: function(aChecked) {
// If the user checked "Don't ask again", make a permanent exception
if (aChecked)
if (aChecked) {
Services.perms.addFromPrincipal(request.principal, request.type, Ci.nsIPermissionManager.ALLOW_ACTION);
} else if (entityName == "desktopNotification") {
// For notifications, it doesn't make sense to grant permission once. So when the user clicks allow,
// we let the requestor create notifications for the session.
Services.perms.addFromPrincipal(request.principal, request.type, Ci.nsIPermissionManager.ALLOW_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION);
}
request.allow();
}

View File

@ -88,6 +88,7 @@ NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const nsAString & aImageUrl
}
#ifdef MOZ_WIDGET_ANDROID
mozilla::AndroidBridge::Bridge()->CloseNotification(aAlertName);
mozilla::AndroidBridge::Bridge()->ShowAlertNotification(aImageUrl, aAlertTitle, aAlertText, aAlertCookie,
aAlertListener, aAlertName);
return NS_OK;
@ -201,7 +202,7 @@ NS_IMETHODIMP nsAlertsService::OnProgress(const nsAString & aAlertName,
NS_IMETHODIMP nsAlertsService::OnCancel(const nsAString & aAlertName)
{
#ifdef MOZ_WIDGET_ANDROID
mozilla::AndroidBridge::Bridge()->AlertsProgressListener_OnCancel(aAlertName);
mozilla::AndroidBridge::Bridge()->CloseNotification(aAlertName);
return NS_OK;
#else
return NS_ERROR_NOT_IMPLEMENTED;

View File

@ -131,7 +131,7 @@ AndroidBridge::Init(JNIEnv *jEnv,
jUnlockProfile = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "unlockProfile", "()Z");
jKillAnyZombies = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "killAnyZombies", "()V");
jAlertsProgressListener_OnProgress = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "alertsProgressListener_OnProgress", "(Ljava/lang/String;JJLjava/lang/String;)V");
jAlertsProgressListener_OnCancel = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "alertsProgressListener_OnCancel", "(Ljava/lang/String;)V");
jCloseNotification = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "closeNotification", "(Ljava/lang/String;)V");
jGetDpi = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getDpi", "()I");
jSetFullScreen = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "setFullScreen", "(Z)V");
jShowInputMethodPicker = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "showInputMethodPicker", "()V");
@ -741,9 +741,9 @@ AndroidBridge::AlertsProgressListener_OnProgress(const nsAString& aAlertName,
}
void
AndroidBridge::AlertsProgressListener_OnCancel(const nsAString& aAlertName)
AndroidBridge::CloseNotification(const nsAString& aAlertName)
{
ALOG_BRIDGE("AlertsProgressListener_OnCancel");
ALOG_BRIDGE("CloseNotification");
JNIEnv *env = GetJNIEnv();
if (!env)
@ -752,7 +752,7 @@ AndroidBridge::AlertsProgressListener_OnCancel(const nsAString& aAlertName)
AutoLocalJNIFrame jniFrame(env);
jstring jstrName = NewJavaString(&jniFrame, aAlertName);
env->CallStaticVoidMethod(mGeckoAppShellClass, jAlertsProgressListener_OnCancel, jstrName);
env->CallStaticVoidMethod(mGeckoAppShellClass, jCloseNotification, jstrName);
}

View File

@ -222,7 +222,7 @@ public:
int64_t aProgressMax,
const nsAString& aAlertText);
void AlertsProgressListener_OnCancel(const nsAString& aAlertName);
void CloseNotification(const nsAString& aAlertName);
int GetDPI();
@ -431,7 +431,7 @@ protected:
jmethodID jUnlockProfile;
jmethodID jKillAnyZombies;
jmethodID jAlertsProgressListener_OnProgress;
jmethodID jAlertsProgressListener_OnCancel;
jmethodID jCloseNotification;
jmethodID jGetDpi;
jmethodID jSetFullScreen;
jmethodID jShowInputMethodPicker;