summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/api/notifications.idl
blob: f916f01500017241e8b3609254937e24281d5168 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Use the <code>chrome.notifications</code> API to create rich notifications
// using templates and show these notifications to users in the system tray.
namespace notifications {
  [noinline_doc] enum TemplateType {
    // icon, title, message, expandedMessage, up to two buttons
    basic,

    // icon, title, message, expandedMessage, image, up to two buttons
    image,

    // icon, title, message, items, up to two buttons
    list,

    // icon, title, message, progress, up to two buttons
    progress
  };

  enum PermissionLevel {
    // User has elected to show notifications from the app or extension.
    // This is the default at install time.
    granted,

    // User has elected not to show notifications from the app or extension.
    denied
  };

  dictionary NotificationItem {
    // Title of one item of a list notification.
    DOMString title;

    // Additional details about this item.
    DOMString message;
  };

  [nodoc] dictionary NotificationBitmap {
    long width;
    long height;
    ArrayBuffer? data;
  };

  dictionary NotificationButton {
    DOMString title;
    DOMString? iconUrl;
    [nodoc] NotificationBitmap? iconBitmap;
  };

  dictionary NotificationOptions {
    // Which type of notification to display.
    // <em>Required for $ref:notifications.create</em> method.
    TemplateType? type;

    // Sender's avatar, app icon, or a thumbnail for image notifications.
    // <em>Required for $ref:notifications.create</em> method.
    DOMString? iconUrl;
    [nodoc] NotificationBitmap? iconBitmap;

    // Title of the notification (e.g. sender name for email).
    // <em>Required for $ref:notifications.create</em> method.
    DOMString? title;

    // Main notification content.
    // <em>Required for $ref:notifications.create</em> method.
    DOMString? message;

    // Alternate notification content with a lower-weight font.
    DOMString? contextMessage;

    // Priority ranges from -2 to 2. -2 is lowest priority. 2 is highest. Zero
    // is default.
    long? priority;

    // A timestamp associated with the notification, in milliseconds past the
    // epoch (e.g. <code>Date.now() + n</code>).
    double? eventTime;

    // Text and icons for up to two notification action buttons.
    NotificationButton[]? buttons;

    // Secondary notification content.
    [nodoc] DOMString? expandedMessage;

    // Image thumbnail for image-type notifications.
    DOMString? imageUrl;
    [nodoc] NotificationBitmap? imageBitmap;

    // Items for multi-item notifications.
    NotificationItem[]? items;

    // Current progress ranges from 0 to 100.
    long? progress;

    // Whether to show UI indicating that the app will visibly respond to
    // clicks on the body of a notification.
    boolean? isClickable;
  };

  callback CreateCallback = void (DOMString notificationId);

  callback UpdateCallback = void (boolean wasUpdated);

  callback ClearCallback = void (boolean wasCleared);

  callback GetAllCallback = void (object notifications);

  callback PermissionLevelCallback = void (PermissionLevel level);

  interface Functions {
    // Creates and displays a notification.
    // |notificationId|: Identifier of the notification. If it is empty, this
    // method generates an id. If it matches an existing notification, this
    // method first clears that notification before proceeding with the create
    // operation.
    // |options|: Contents of the notification.
    // |callback|: Returns the notification id (either supplied or generated)
    // that represents the created notification.
    static void create(DOMString notificationId,
                       NotificationOptions options,
                       CreateCallback callback);

    // Updates an existing notification.
    // |notificationId|: The id of the notification to be updated. This is
    // returned by $ref:notifications.create method.
    // |options|: Contents of the notification to update to.
    // |callback|: Called to indicate whether a matching notification existed.
    static void update(DOMString notificationId,
                       NotificationOptions options,
                       UpdateCallback callback);

    // Clears the specified notification.
    // |notificationId|: The id of the notification to be cleared. This is
    // returned by $ref:notifications.create method.
    // |callback|: Called to indicate whether a matching notification existed.
    static void clear(DOMString notificationId, ClearCallback callback);

    // Retrieves all the notifications.
    // |callback|: Returns the set of notification_ids currently in the system.
    static void getAll(GetAllCallback callback);

    // Retrieves whether the user has enabled notifications from this app
    // or extension.
    // |callback|: Returns the current permission level.
    static void getPermissionLevel(PermissionLevelCallback callback);
  };

  interface Events {
    // The notification closed, either by the system or by user action.
    static void onClosed(DOMString notificationId, boolean byUser);

    // The user clicked in a non-button area of the notification.
    static void onClicked(DOMString notificationId);

    // The user pressed a button in the notification.
    static void onButtonClicked(DOMString notificationId, long buttonIndex);

    // The user changes the permission level.
    static void onPermissionLevelChanged(PermissionLevel level);
  };

};