Bug 910915 - Add notification ID field to AppNotificationService; r=fabrice

This commit is contained in:
Kyle Machulis 2013-09-10 16:49:09 +02:00
parent 49bc3978b7
commit 0d4ff9dec8
3 changed files with 35 additions and 8 deletions

View File

@ -7,13 +7,14 @@
interface nsIObserver;
// Notification service that also provides the manifest URL
[scriptable, uuid(7fb4f0f9-ff5b-4620-8e1b-d82d723605af)]
[scriptable, uuid(61c4adf4-187d-4d18-937c-4df17bc01073)]
interface nsIAppNotificationService : nsISupports
{
void showAppNotification(in AString imageUrl,
in AString title,
in AString text,
[optional] in boolean textClickable,
[optional] in AString manifestURL,
[optional] in nsIObserver alertListener);
in AString title,
in AString text,
[optional] in boolean textClickable,
[optional] in AString manifestURL,
[optional] in nsIObserver alertListener,
[optional] in AString id);
};

View File

@ -92,7 +92,8 @@ DesktopNotification::PostDesktopNotification()
return appNotifier->ShowAppNotification(mIconURL, mTitle, mDescription,
true,
manifestUrl,
mObserver);
mObserver,
EmptyString());
}
}
#endif

View File

@ -17,6 +17,10 @@
#include "nsToolkitCompsCID.h"
#include "nsGlobalWindow.h"
#include "nsDOMJSUtils.h"
#ifdef MOZ_B2G
#include "nsIDOMDesktopNotification.h"
#include "nsIAppsService.h"
#endif
namespace mozilla {
namespace dom {
@ -353,15 +357,36 @@ Notification::ShowInternal()
}
}
nsCOMPtr<nsIObserver> observer = new NotificationObserver(this);
nsString alertName;
rv = GetAlertName(alertName);
NS_ENSURE_SUCCESS(rv, rv);
#ifdef MOZ_B2G
nsCOMPtr<nsIAppNotificationService> appNotifier =
do_GetService("@mozilla.org/system-alerts-service;1");
if (appNotifier) {
nsCOMPtr<nsPIDOMWindow> window = GetOwner();
uint32_t appId = (window.get())->GetDoc()->NodePrincipal()->GetAppId();
if (appId != nsIScriptSecurityManager::UNKNOWN_APP_ID) {
nsCOMPtr<nsIAppsService> appsService = do_GetService("@mozilla.org/AppsService;1");
nsString manifestUrl = EmptyString();
appsService->GetManifestURLByLocalId(appId, manifestUrl);
return appNotifier->ShowAppNotification(mIconUrl, mTitle, mBody,
true,
manifestUrl,
observer,
alertName);
}
}
#endif
// In the case of IPC, the parent process uses the cookie to map to
// nsIObserver. Thus the cookie must be unique to differentiate observers.
nsString uniqueCookie = NS_LITERAL_STRING("notification:");
uniqueCookie.AppendInt(sCount++);
nsCOMPtr<nsIObserver> observer = new NotificationObserver(this);
return alertService->ShowAlertNotification(absoluteUrl, mTitle, mBody, true,
uniqueCookie, observer, alertName,
DirectionToString(mDir), mLang);