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. 4 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 10 basic, 11 12 // icon, title, message, expandedMessage, image, up to two buttons 13 image, 14 15 // icon, title, message, items, up to two buttons 16 list, 17 18 // icon, title, message, progress, up to two buttons 19 progress 20 }; 21 22 dictionary NotificationItem { 23 // Title of one item of a list notification. 24 DOMString title; 25 26 // Additional details about this item. 27 DOMString message; 28 }; 29 30 [nodoc] dictionary NotificationBitmap { 31 long width; 32 long height; 33 ArrayBuffer? data; 34 }; 35 36 dictionary NotificationButton { 37 DOMString title; 38 DOMString? iconUrl; 39 [nodoc] NotificationBitmap? iconBitmap; 40 }; 41 42 dictionary NotificationOptions { 43 // Which type of notification to display. 44 TemplateType? type; 45 46 // Sender's avatar, app icon, or a thumbnail for image notifications. 47 DOMString? iconUrl; 48 [nodoc] NotificationBitmap? iconBitmap; 49 50 // Title of the notification (e.g. sender name for email). 51 DOMString? title; 52 53 // Main notification content. 54 DOMString? message; 55 56 // Priority ranges from -2 to 2. -2 is lowest priority. 2 is highest. Zero 57 // is default. 58 long? priority; 59 60 // A timestamp associated with the notification, in milliseconds past the 61 // epoch (e.g. <code>Date.now() + n</code>). 62 double? eventTime; 63 64 // Text and icons for up to two notification action buttons. 65 NotificationButton[]? buttons; 66 67 // Secondary notification content. 68 [nodoc] DOMString? expandedMessage; 69 70 // Image thumbnail for image-type notifications. 71 DOMString? imageUrl; 72 [nodoc] NotificationBitmap? imageBitmap; 73 74 // Items for multi-item notifications. 75 NotificationItem[]? items; 76 77 // Current progress ranges from 0 to 100. 78 long? progress; 79 }; 80 81 callback CreateCallback = void (DOMString notificationId); 82 83 callback UpdateCallback = void (boolean wasUpdated); 84 85 callback ClearCallback = void (boolean wasCleared); 86 87 callback GetAllCallback = void (object notifications); 88 89 interface Functions { 90 // Creates and displays a notification having the contents in |options|, 91 // identified by the id |notificationId|. If |notificationId| is empty, 92 // |create| generates an id. If |notificationId| matches an existing 93 // notification, |create| first clears that notification before proceeding 94 // with the create operation. |callback| returns the notification id 95 // (either supplied or generated) that represents the created notification. 96 static void create(DOMString notificationId, 97 NotificationOptions options, 98 CreateCallback callback); 99 100 // Updates an existing notification having the id |notificationId| and the 101 // options |options|. |callback| indicates whether a matching notification 102 // existed. 103 static void update(DOMString notificationId, 104 NotificationOptions options, 105 UpdateCallback callback); 106 107 // Given a |notificationId| returned by the |create| method, clears the 108 // corresponding notification. |callback| indicates whether a matching 109 // notification existed. 110 static void clear(DOMString notificationId, ClearCallback callback); 111 112 // |callback| is executed with the set of notification_ids currently in 113 // the system. 114 static void getAll(GetAllCallback callback); 115 }; 116 117 interface Events { 118 // The notification closed, either by the system or by user action. 119 static void onClosed(DOMString notificationId, boolean byUser); 120 121 // The user clicked in a non-button area of the notification. 122 static void onClicked(DOMString notificationId); 123 124 // The user pressed a button in the notification. 125 static void onButtonClicked(DOMString notificationId, long buttonIndex); 126 }; 127 128 }; 129