1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Use the <code>chrome.notifications</code> API to create rich notifications
6 // using templates and show these notifications to users in the system tray.
7 namespace notifications
{
8 [noinline_doc
] enum TemplateType
{
9 // icon, title, message, expandedMessage, up to two buttons
12 // icon, title, message, expandedMessage, image, up to two buttons
15 // icon, title, message, items, up to two buttons
18 // icon, title, message, progress, up to two buttons
22 enum PermissionLevel
{
23 // User has elected to show notifications from the app or extension.
24 // This is the default at install time.
27 // User has elected not to show notifications from the app or extension.
31 dictionary NotificationItem
{
32 // Title of one item of a list notification.
35 // Additional details about this item.
39 [nodoc
] dictionary NotificationBitmap
{
45 dictionary NotificationButton
{
48 [nodoc
] NotificationBitmap? iconBitmap
;
51 dictionary NotificationOptions
{
52 // Which type of notification to display.
53 // <em>Required for $(ref:notifications.create)</em> method.
56 // Sender's avatar, app icon, or a thumbnail for image notifications.
57 // <em>Required for $(ref:notifications.create)</em> method.
59 [nodoc
] NotificationBitmap? iconBitmap
;
61 // Title of the notification (e.g. sender name for email).
62 // <em>Required for $(ref:notifications.create)</em> method.
65 // Main notification content.
66 // <em>Required for $(ref:notifications.create)</em> method.
69 // Alternate notification content with a lower-weight font.
70 DOMString? contextMessage
;
72 // Priority ranges from -2 to 2. -2 is lowest priority. 2 is highest. Zero
76 // A timestamp associated with the notification, in milliseconds past the
77 // epoch (e.g. <code>Date.now() + n</code>).
80 // Text and icons for up to two notification action buttons.
81 NotificationButton
[]? buttons
;
83 // Secondary notification content.
84 [nodoc
] DOMString? expandedMessage
;
86 // Image thumbnail for image-type notifications.
88 [nodoc
] NotificationBitmap? imageBitmap
;
90 // Items for multi-item notifications.
91 NotificationItem
[]? items
;
93 // Current progress ranges from 0 to 100.
96 // Whether to show UI indicating that the app will visibly respond to
97 // clicks on the body of a notification.
101 callback CreateCallback
= void (DOMString notificationId
);
103 callback UpdateCallback
= void (boolean wasUpdated
);
105 callback ClearCallback
= void (boolean wasCleared
);
107 callback GetAllCallback
= void (object notifications
);
109 callback PermissionLevelCallback
= void (PermissionLevel level
);
111 interface Functions
{
112 // Creates and displays a notification.
113 // |notificationId|: Identifier of the notification. If it is empty, this
114 // method generates an id. If it matches an existing notification, this
115 // method first clears that notification before proceeding with the create
117 // |options|: Contents of the notification.
118 // |callback|: Returns the notification id (either supplied or generated)
119 // that represents the created notification.
120 static
void create
(DOMString notificationId
,
121 NotificationOptions options
,
122 CreateCallback
callback);
124 // Updates an existing notification.
125 // |notificationId|: The id of the notification to be updated. This is
126 // returned by $(ref:notifications.create) method.
127 // |options|: Contents of the notification to update to.
128 // |callback|: Called to indicate whether a matching notification existed.
129 static
void update
(DOMString notificationId
,
130 NotificationOptions options
,
131 UpdateCallback
callback);
133 // Clears the specified notification.
134 // |notificationId|: The id of the notification to be cleared. This is
135 // returned by $(ref:notifications.create) method.
136 // |callback|: Called to indicate whether a matching notification existed.
137 static
void clear
(DOMString notificationId
, ClearCallback
callback);
139 // Retrieves all the notifications.
140 // |callback|: Returns the set of notification_ids currently in the system.
141 static
void getAll
(GetAllCallback
callback);
143 // Retrieves whether the user has enabled notifications from this app
145 // |callback|: Returns the current permission level.
146 static
void getPermissionLevel
(PermissionLevelCallback
callback);
150 // The notification closed, either by the system or by user action.
151 static
void onClosed
(DOMString notificationId
, boolean byUser
);
153 // The user clicked in a non-button area of the notification.
154 static
void onClicked
(DOMString notificationId
);
156 // The user pressed a button in the notification.
157 static
void onButtonClicked
(DOMString notificationId
, long buttonIndex
);
159 // The user changes the permission level.
160 static
void onPermissionLevelChanged
(PermissionLevel level
);
162 // The user clicked on a link for the app's notification settings.
163 static
void onShowSettings
();