Bug 1264815 - Add a 'showPersistentAlertNotification' method to GeckoAppShell. r=kcambridge
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "mozilla/dom/Notification.h"
|
#include "mozilla/dom/Notification.h"
|
||||||
|
|
||||||
|
#include "mozilla/JSONWriter.h"
|
||||||
#include "mozilla/Move.h"
|
#include "mozilla/Move.h"
|
||||||
#include "mozilla/OwningNonNull.h"
|
#include "mozilla/OwningNonNull.h"
|
||||||
#include "mozilla/Preferences.h"
|
#include "mozilla/Preferences.h"
|
||||||
@@ -1665,6 +1666,19 @@ Notification::IsInPrivateBrowsing()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
struct StringWriteFunc : public JSONWriteFunc
|
||||||
|
{
|
||||||
|
nsAString& mBuffer; // This struct must not outlive this buffer
|
||||||
|
explicit StringWriteFunc(nsAString& buffer) : mBuffer(buffer) {}
|
||||||
|
|
||||||
|
void Write(const char* aStr)
|
||||||
|
{
|
||||||
|
mBuffer.Append(NS_ConvertUTF8toUTF16(aStr));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Notification::ShowInternal()
|
Notification::ShowInternal()
|
||||||
{
|
{
|
||||||
@@ -1716,6 +1730,7 @@ Notification::ShowInternal()
|
|||||||
nsAutoString soundUrl;
|
nsAutoString soundUrl;
|
||||||
ResolveIconAndSoundURL(iconUrl, soundUrl);
|
ResolveIconAndSoundURL(iconUrl, soundUrl);
|
||||||
|
|
||||||
|
bool isPersistent = false;
|
||||||
nsCOMPtr<nsIObserver> observer;
|
nsCOMPtr<nsIObserver> observer;
|
||||||
if (mScope.IsEmpty()) {
|
if (mScope.IsEmpty()) {
|
||||||
// Ownership passed to observer.
|
// Ownership passed to observer.
|
||||||
@@ -1730,6 +1745,7 @@ Notification::ShowInternal()
|
|||||||
observer = new MainThreadNotificationObserver(Move(ownership));
|
observer = new MainThreadNotificationObserver(Move(ownership));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
isPersistent = true;
|
||||||
// This observer does not care about the Notification. It will be released
|
// This observer does not care about the Notification. It will be released
|
||||||
// at the end of this function.
|
// at the end of this function.
|
||||||
//
|
//
|
||||||
@@ -1813,6 +1829,7 @@ Notification::ShowInternal()
|
|||||||
nsCOMPtr<nsIAlertNotification> alert =
|
nsCOMPtr<nsIAlertNotification> alert =
|
||||||
do_CreateInstance(ALERT_NOTIFICATION_CONTRACTID);
|
do_CreateInstance(ALERT_NOTIFICATION_CONTRACTID);
|
||||||
NS_ENSURE_TRUE_VOID(alert);
|
NS_ENSURE_TRUE_VOID(alert);
|
||||||
|
nsIPrincipal* principal = GetPrincipal();
|
||||||
rv = alert->Init(alertName, iconUrl, mTitle, mBody,
|
rv = alert->Init(alertName, iconUrl, mTitle, mBody,
|
||||||
true,
|
true,
|
||||||
uniqueCookie,
|
uniqueCookie,
|
||||||
@@ -1822,7 +1839,29 @@ Notification::ShowInternal()
|
|||||||
GetPrincipal(),
|
GetPrincipal(),
|
||||||
inPrivateBrowsing);
|
inPrivateBrowsing);
|
||||||
NS_ENSURE_SUCCESS_VOID(rv);
|
NS_ENSURE_SUCCESS_VOID(rv);
|
||||||
|
|
||||||
|
if (isPersistent) {
|
||||||
|
nsAutoString persistentData;
|
||||||
|
|
||||||
|
JSONWriter w(MakeUnique<StringWriteFunc>(persistentData));
|
||||||
|
w.Start();
|
||||||
|
|
||||||
|
nsAutoString origin;
|
||||||
|
Notification::GetOrigin(principal, origin);
|
||||||
|
w.StringProperty("origin", NS_ConvertUTF16toUTF8(origin).get());
|
||||||
|
|
||||||
|
w.StringProperty("id", NS_ConvertUTF16toUTF8(mID).get());
|
||||||
|
|
||||||
|
nsAutoCString originSuffix;
|
||||||
|
principal->GetOriginSuffix(originSuffix);
|
||||||
|
w.StringProperty("originSuffix", originSuffix.get());
|
||||||
|
|
||||||
|
w.End();
|
||||||
|
|
||||||
|
alertService->ShowPersistentNotification(persistentData, alert, alertObserver);
|
||||||
|
} else {
|
||||||
alertService->ShowAlert(alert, alertObserver);
|
alertService->ShowAlert(alert, alertObserver);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ bool
|
/* static */ bool
|
||||||
|
|||||||
@@ -896,6 +896,19 @@ public class GeckoAppShell
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@WrapForJNI(stubName = "ShowPersistentAlertNotificationWrapper")
|
||||||
|
public static void showPersistentAlertNotification(
|
||||||
|
String aPersistentData,
|
||||||
|
String aImageUrl, String aAlertTitle, String aAlertText,
|
||||||
|
String aAlertCookie, String aAlertName, String aHost) {
|
||||||
|
Intent notificationIntent = GeckoService.getIntentToCreateServices(
|
||||||
|
getApplicationContext(), "persistent-notification-click", aPersistentData);
|
||||||
|
int notificationID = aAlertName.hashCode();
|
||||||
|
PendingIntent contentIntent = PendingIntent.getService(
|
||||||
|
getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
notificationClient.add(notificationID, aImageUrl, aHost, aAlertTitle, aAlertText, contentIntent);
|
||||||
|
}
|
||||||
|
|
||||||
@WrapForJNI(stubName = "ShowAlertNotificationWrapper")
|
@WrapForJNI(stubName = "ShowAlertNotificationWrapper")
|
||||||
public static void showAlertNotification(String aImageUrl, String aAlertTitle, String aAlertText, String aAlertCookie, String aAlertName, String aHost) {
|
public static void showAlertNotification(String aImageUrl, String aAlertTitle, String aAlertText, String aAlertCookie, String aAlertName, String aHost) {
|
||||||
// The intent to launch when the user clicks the expanded notification
|
// The intent to launch when the user clicks the expanded notification
|
||||||
|
|||||||
@@ -252,8 +252,14 @@ NS_IMETHODIMP nsAlertsService::ShowPersistentNotification(const nsAString & aPer
|
|||||||
rv = aAlert->GetPrincipal(getter_AddRefs(principal));
|
rv = aAlert->GetPrincipal(getter_AddRefs(principal));
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
mozilla::AndroidBridge::Bridge()->ShowAlertNotification(imageUrl, title, text, cookie,
|
if (!aPersistentData.IsEmpty()) {
|
||||||
aAlertListener, name, principal);
|
mozilla::AndroidBridge::Bridge()->ShowPersistentAlertNotification
|
||||||
|
(aPersistentData, imageUrl, title, text, cookie, name, principal);
|
||||||
|
} else {
|
||||||
|
mozilla::AndroidBridge::Bridge()->ShowAlertNotification
|
||||||
|
(imageUrl, title, text, cookie, aAlertListener, name, principal);
|
||||||
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
#else
|
#else
|
||||||
// Check if there is an optional service that handles system-level notifications
|
// Check if there is an optional service that handles system-level notifications
|
||||||
|
|||||||
@@ -507,6 +507,22 @@ AndroidBridge::GetClipboardText(nsAString& aText)
|
|||||||
return !!text;
|
return !!text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
AndroidBridge::ShowPersistentAlertNotification(const nsAString& aPersistentData,
|
||||||
|
const nsAString& aImageUrl,
|
||||||
|
const nsAString& aAlertTitle,
|
||||||
|
const nsAString& aAlertText,
|
||||||
|
const nsAString& aAlertCookie,
|
||||||
|
const nsAString& aAlertName,
|
||||||
|
nsIPrincipal* aPrincipal)
|
||||||
|
{
|
||||||
|
nsAutoString host;
|
||||||
|
nsAlertsUtils::GetSourceHostPort(aPrincipal, host);
|
||||||
|
|
||||||
|
GeckoAppShell::ShowPersistentAlertNotificationWrapper
|
||||||
|
(aPersistentData, aImageUrl, aAlertTitle, aAlertText, aAlertCookie, aAlertName, host);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
AndroidBridge::ShowAlertNotification(const nsAString& aImageUrl,
|
AndroidBridge::ShowAlertNotification(const nsAString& aImageUrl,
|
||||||
const nsAString& aAlertTitle,
|
const nsAString& aAlertTitle,
|
||||||
|
|||||||
@@ -177,10 +177,18 @@ public:
|
|||||||
|
|
||||||
bool GetClipboardText(nsAString& aText);
|
bool GetClipboardText(nsAString& aText);
|
||||||
|
|
||||||
|
void ShowPersistentAlertNotification(const nsAString& aPersistentData,
|
||||||
|
const nsAString& aImageUrl,
|
||||||
|
const nsAString& aAlertTitle,
|
||||||
|
const nsAString& aAlertText,
|
||||||
|
const nsAString& aAlertCookie,
|
||||||
|
const nsAString& aAlertName,
|
||||||
|
nsIPrincipal* aPrincipal);
|
||||||
|
|
||||||
void ShowAlertNotification(const nsAString& aImageUrl,
|
void ShowAlertNotification(const nsAString& aImageUrl,
|
||||||
const nsAString& aAlertTitle,
|
const nsAString& aAlertTitle,
|
||||||
const nsAString& aAlertText,
|
const nsAString& aAlertText,
|
||||||
const nsAString& aAlertData,
|
const nsAString& aAlertCookie,
|
||||||
nsIObserver *aAlertListener,
|
nsIObserver *aAlertListener,
|
||||||
const nsAString& aAlertName,
|
const nsAString& aAlertName,
|
||||||
nsIPrincipal* aPrincipal);
|
nsIPrincipal* aPrincipal);
|
||||||
|
|||||||
@@ -685,6 +685,14 @@ auto GeckoAppShell::ShowAlertNotificationWrapper(mozilla::jni::String::Param a0,
|
|||||||
return mozilla::jni::Method<ShowAlertNotificationWrapper_t>::Call(GeckoAppShell::Context(), nullptr, a0, a1, a2, a3, a4, a5);
|
return mozilla::jni::Method<ShowAlertNotificationWrapper_t>::Call(GeckoAppShell::Context(), nullptr, a0, a1, a2, a3, a4, a5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr char GeckoAppShell::ShowPersistentAlertNotificationWrapper_t::name[];
|
||||||
|
constexpr char GeckoAppShell::ShowPersistentAlertNotificationWrapper_t::signature[];
|
||||||
|
|
||||||
|
auto GeckoAppShell::ShowPersistentAlertNotificationWrapper(mozilla::jni::String::Param a0, mozilla::jni::String::Param a1, mozilla::jni::String::Param a2, mozilla::jni::String::Param a3, mozilla::jni::String::Param a4, mozilla::jni::String::Param a5, mozilla::jni::String::Param a6) -> void
|
||||||
|
{
|
||||||
|
return mozilla::jni::Method<ShowPersistentAlertNotificationWrapper_t>::Call(GeckoAppShell::Context(), nullptr, a0, a1, a2, a3, a4, a5, a6);
|
||||||
|
}
|
||||||
|
|
||||||
constexpr char GeckoAppShell::StartMonitoringGamepad_t::name[];
|
constexpr char GeckoAppShell::StartMonitoringGamepad_t::name[];
|
||||||
constexpr char GeckoAppShell::StartMonitoringGamepad_t::signature[];
|
constexpr char GeckoAppShell::StartMonitoringGamepad_t::signature[];
|
||||||
|
|
||||||
|
|||||||
@@ -1430,6 +1430,28 @@ public:
|
|||||||
|
|
||||||
static auto ShowAlertNotificationWrapper(mozilla::jni::String::Param, mozilla::jni::String::Param, mozilla::jni::String::Param, mozilla::jni::String::Param, mozilla::jni::String::Param, mozilla::jni::String::Param) -> void;
|
static auto ShowAlertNotificationWrapper(mozilla::jni::String::Param, mozilla::jni::String::Param, mozilla::jni::String::Param, mozilla::jni::String::Param, mozilla::jni::String::Param, mozilla::jni::String::Param) -> void;
|
||||||
|
|
||||||
|
struct ShowPersistentAlertNotificationWrapper_t {
|
||||||
|
typedef GeckoAppShell Owner;
|
||||||
|
typedef void ReturnType;
|
||||||
|
typedef void SetterType;
|
||||||
|
typedef mozilla::jni::Args<
|
||||||
|
mozilla::jni::String::Param,
|
||||||
|
mozilla::jni::String::Param,
|
||||||
|
mozilla::jni::String::Param,
|
||||||
|
mozilla::jni::String::Param,
|
||||||
|
mozilla::jni::String::Param,
|
||||||
|
mozilla::jni::String::Param,
|
||||||
|
mozilla::jni::String::Param> Args;
|
||||||
|
static constexpr char name[] = "showPersistentAlertNotification";
|
||||||
|
static constexpr char signature[] =
|
||||||
|
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V";
|
||||||
|
static const bool isStatic = true;
|
||||||
|
static const mozilla::jni::ExceptionMode exceptionMode =
|
||||||
|
mozilla::jni::ExceptionMode::ABORT;
|
||||||
|
};
|
||||||
|
|
||||||
|
static auto ShowPersistentAlertNotificationWrapper(mozilla::jni::String::Param, mozilla::jni::String::Param, mozilla::jni::String::Param, mozilla::jni::String::Param, mozilla::jni::String::Param, mozilla::jni::String::Param, mozilla::jni::String::Param) -> void;
|
||||||
|
|
||||||
struct StartMonitoringGamepad_t {
|
struct StartMonitoringGamepad_t {
|
||||||
typedef GeckoAppShell Owner;
|
typedef GeckoAppShell Owner;
|
||||||
typedef void ReturnType;
|
typedef void ReturnType;
|
||||||
|
|||||||
Reference in New Issue
Block a user