W3C Candidate Recommendation 19 May 2015
[Constructor(DOMString title, optional NotificationOptions options)]
interface Notification : EventTarget {
static readonly attribute NotificationPermission permission;
static void requestPermission(optional NotificationPermissionCallback callback);
attribute EventHandler onclick;
attribute EventHandler onshow;
attribute EventHandler onerror;
attribute EventHandler onclose;
readonly attribute DOMString title;
readonly attribute NotificationDirection dir;
readonly attribute DOMString lang;
readonly attribute DOMString body;
readonly attribute DOMString tag;
readonly attribute DOMString icon;
void close();
};
dictionary NotificationOptions {
NotificationDirection dir = "auto";
DOMString lang = "";
DOMString body;
DOMString tag;
DOMString icon;
};
enum NotificationPermission {
"default",
"denied",
"granted"
};
callback NotificationPermissionCallback = void (NotificationPermission permission);
enum NotificationDirection {
"auto",
"ltr",
"rtl"
};
[Exposed=(Window,Worker)]
interface EventTarget {
void addEventListener(DOMString type, EventListener? callback, optional boolean capture = false);
void removeEventListener(DOMString type, EventListener? callback, optional boolean capture = false);
boolean dispatchEvent(Event event);
};
callback interface EventListener {
void handleEvent(Event event);
};
[TreatNonObjectAsNull]
callback EventHandlerNonNull = any (Event event);
typedef EventHandlerNonNull? EventHandler;
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
} else if (Notification.permission === "granted") {
var notification = new Notification("Hi there!");
} else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
if (permission === "granted") {
var notification = new Notification("Hi there!");
}
});
}
Living Standard — Last Updated 1 May 2015
[Constructor(DOMString title, optional NotificationOptions options),
Exposed=(Window,Worker)]
interface Notification : EventTarget {
static readonly attribute NotificationPermission permission;
[Exposed=Window] static void requestPermission(optional NotificationPermissionCallback callback);
attribute EventHandler onclick;
attribute EventHandler onerror;
readonly attribute DOMString title;
readonly attribute NotificationDirection dir;
readonly attribute DOMString lang;
readonly attribute DOMString body;
readonly attribute DOMString tag;
readonly attribute USVString icon;
readonly attribute USVString sound;
// vibrate not exposed for now; see bug 23682
readonly attribute boolean renotify;
readonly attribute boolean silent;
readonly attribute boolean noscreen;
readonly attribute boolean sticky;
[SameObject] readonly attribute any data;
void close();
};
dictionary NotificationOptions {
NotificationDirection dir = "auto";
DOMString lang = "";
DOMString body = "";
DOMString tag = "";
USVString icon;
USVString sound;
VibratePattern vibrate;
boolean renotify = false;
boolean silent = false;
boolean noscreen = false;
boolean sticky = false;
any data = null;
};
typedef (unsigned long or sequence<unsigned long>) VibratePattern;
partial interface Navigator {
boolean vibrate (VibratePattern pattern);
};
DOMString lang = "";
DOMString body = "";
DOMString tag = "";
USVString icon;
USVString sound;
[SameObject] readonly attribute any data;
var notify = function() {
var options = {
body: "Click me please!",
icon: "../../../img/tizen-profiles-small.png",
sound: "../../../sound/greeting.m4a",
tag: "whatwg",
};
var n = new Notification('Greetings from Zhiqiang!', options);
n.onclick = function() {
alert("You have clicked the notification!");
};
};
dictionary GetNotificationOptions {
DOMString tag = "";
};
partial interface ServiceWorkerRegistration {
Promise<void> showNotification(DOMString title, optional NotificationOptions options);
Promise<sequence<Notification>> getNotifications(optional GetNotificationOptions filter);
};
[Constructor(DOMString type, optional NotificationEventInit eventInitDict),
Exposed=ServiceWorker]
interface NotificationEvent : ExtendableEvent {
readonly attribute Notification notification;
};
dictionary NotificationEventInit : ExtendableEventInit {
required Notification notification;
};
partial interface ServiceWorkerGlobalScope {
attribute EventHandler onnotificationclick;
};
[Constructor(DOMString type, optional ExtendableEventInit eventInitDict),
Exposed=ServiceWorker]
interface ExtendableEvent : Event {
void waitUntil(Promise<any> f);
};
dictionary ExtendableEventInit : EventInit {
// Defined for the forward compatibility across the derived events
};
dictionary identifier {
required type identifier;
};
typedef DOMString NotificationId;
enum NotificationType { "STATUS" };
enum StatusNotificationType { "SIMPLE", "THUMBNAIL", "ONGOING", "PROGRESS" };
enum NotificationProgressType { "PERCENTAGE", "BYTE" };
[NoInterfaceObject] interface NotificationObject {
readonly attribute NotificationManager notification;
};
Tizen implements NotificationObject;
[NoInterfaceObject] interface NotificationManager {
void post(Notification notification) raises(WebAPIException);
void update(Notification notification) raises(WebAPIException);
void remove(NotificationId id) raises(WebAPIException);
void removeAll() raises(WebAPIException);
Notification get(NotificationId id) raises(WebAPIException);
Notification[] getAll() raises(WebAPIException);
};
[NoInterfaceObject] interface Notification {
readonly attribute NotificationId id;
readonly attribute NotificationType type;
readonly attribute Date postedTime;
attribute DOMString title;
attribute DOMString? content;
};
[Constructor(StatusNotificationType statusType, DOMString title,
optional StatusNotificationInit? notificationInitDict)]
interface StatusNotification : Notification {
readonly attribute StatusNotificationType statusType;
attribute DOMString? iconPath;
attribute DOMString? subIconPath;
attribute long? number;
attribute NotificationDetailInfo[]? detailInfo;
attribute DOMString? ledColor;
attribute unsigned long ledOnPeriod;
attribute unsigned long ledOffPeriod;
attribute DOMString? backgroundImagePath;
attribute DOMString[]? thumbnails;
attribute DOMString? soundPath;
attribute boolean vibration;
attribute ApplicationControl? appControl;
attribute ApplicationId? appId;
attribute NotificationProgressType progressType;
attribute unsigned long? progressValue;
};
dictionary StatusNotificationInit {
DOMString? content;
DOMString? iconPath;
DOMString? soundPath;
boolean? vibration;
ApplicationControl? appControl;
ApplicationId? appId;
NotificationProgressType? progressType;
unsigned long? progressValue;
long? number;
DOMString? subIconPath;
NotificationDetailInfo[]? detailInfo;
DOMString? ledColor;
unsigned long ledOnPeriod;
unsigned long ledOffPeriod;
DOMString? backgroundImagePath;
DOMString[]? thumbnails;
};
[Constructor(DOMString mainText, optional DOMString? subText)]
interface NotificationDetailInfo {
attribute DOMString mainText;
attribute DOMString? subText;
};
See Tizen tutorial of notification, Notifying Users of Application Events
Item | W3C | WHATWG | Tizen |
---|---|---|---|
Constructor | new Notification(title, options) | new Notification(title, options) | new tizen.StatusNotification(type, title, options) |
Exposed | Window | Window, Worker, ServiceWorker | Tizen |
Permission | Need | Need | Privilege: http://tizen.org/privilege/notification |
Progress Notification | Yes | ||
Item | W3C | WHATWG | Tizen |
---|---|---|---|
onclick | yes | yes | |
onclose | yes | ||
onerror | yes | yes | |
onshow | yes | ||
close() | yes | yes | remove() |
Item | W3C | WHATWG | Tizen |
---|---|---|---|
title | yes | yes | yes |
dir | yes | yes | |
lang | yes | yes | |
body | yes | yes | content |
tag | yes | yes | |
icon | yes | yes | iconPath/subIconPath |
sound | yes | soundPath | |
vibrate | yes | vibration | |
renotify | yes | ||
silent | yes | ||
noscreen | yes | ||
sticky | yes | ||
data | yes | ||
#if defined(OS_ANDROID)
return blink::WebNotificationPermissionAllowed;
#elif defined(OS_LINUX) && defined(USE_LIBNOTIFY)
return blink::WebNotificationPermissionAllowed;
#else
return blink::WebNotificationPermissionDenied;
#endif