summaryrefslogtreecommitdiffstats
path: root/toolkit/components/alerts/nsIAlertsService.idl
blob: 5629dabc938205791ef3beeec9d230201eedbe49 (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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsISupports.idl"
#include "nsIObserver.idl"

interface imgIRequest;
interface nsICancelable;
interface nsIPrincipal;
interface nsIURI;

%{C++
#define ALERT_NOTIFICATION_CONTRACTID "@mozilla.org/alert-notification;1"
%}

[scriptable, uuid(a71a637d-de1d-47c6-a8d2-c60b2596f471)]
interface nsIAlertNotificationImageListener : nsISupports
{
  /**
   * Called when the image finishes loading.
   *
   * @param aUserData An opaque parameter passed to |loadImage|.
   * @param aRequest  The image request.
   */
  void onImageReady(in nsISupports aUserData, in imgIRequest aRequest);

  /**
   * Called if the alert doesn't have an image, or if the image request times
   * out or fails.
   *
   * @param aUserData An opaque parameter passed to |loadImage|.
   */
  void onImageMissing(in nsISupports aUserData);
};

[scriptable, uuid(cf2e4cb6-4b8f-4eca-aea9-d51a8f9f7a50)]
interface nsIAlertNotification : nsISupports
{
  /** Initializes an alert notification. */
  void init([optional] in AString aName,
            [optional] in AString aImageURL,
            [optional] in AString aTitle,
            [optional] in AString aText,
            [optional] in boolean aTextClickable,
            [optional] in AString aCookie,
            [optional] in AString aDir,
            [optional] in AString aLang,
            [optional] in AString aData,
            [optional] in nsIPrincipal aPrincipal,
            [optional] in boolean aInPrivateBrowsing,
            [optional] in boolean aRequireInteraction);

  /**
   * The name of the notification. On Android, the name is hashed and used as
   * a notification ID. Notifications will replace previous notifications with
   * the same name.
   */
  readonly attribute AString name;

  /**
   * A URL identifying the image to put in the alert. The OS X backend limits
   * the amount of time it will wait for the image to load to six seconds. After
   * that time, the alert will show without an image.
   */
  readonly attribute AString imageURL;

  /** The title for the alert. */
  readonly attribute AString title;

  /** The contents of the alert. */
  readonly attribute AString text;

  /**
   * Controls the click behavior. If true, the alert listener will be notified
   * when the user clicks on the alert.
   */
  readonly attribute boolean textClickable;

  /**
   * An opaque cookie that will be passed to the alert listener for each
   * callback.
   */
  readonly attribute AString cookie;

  /**
   * Bidi override for the title and contents. Valid values are "auto", "ltr",
   * or "rtl". Ignored if the backend doesn't support localization.
   */
  readonly attribute AString dir;

  /**
   * Language of the title and text. Ignored if the backend doesn't support
   * localization.
   */
  readonly attribute AString lang;

  /**
   * A Base64-encoded structured clone buffer containing data associated with
   * this alert. Only used for web notifications. Chrome callers should use a
   * cookie instead.
   */
  readonly attribute AString data;

  /**
   * The principal of the page that created the alert. Used for IPC security
   * checks, and to determine whether the alert is actionable.
   */
  readonly attribute nsIPrincipal principal;

  /**
   * The URI of the page that created the alert. |null| if the alert is not
   * actionable.
   */
  readonly attribute nsIURI URI;

  /**
   * Controls the image loading behavior. If true, the image request will be
   * loaded anonymously (without cookies or authorization tokens).
   */
  readonly attribute boolean inPrivateBrowsing;

  /**
   * Indicates that the notification should remain readily available until
   * the user activates or dismisses the notification.
   */
  readonly attribute boolean requireInteraction;

  /**
   * Indicates whether this alert should show the source string and action
   * buttons. False for system alerts (which can omit the principal), or
   * expanded, system, and null principals.
   */
  readonly attribute boolean actionable;

  /**
   * The host and port of the originating page, or an empty string if the alert
   * is not actionable.
   */
  readonly attribute AString source;

  /**
   * Loads the image associated with this alert.
   *
   * @param aTimeout  The number of milliseconds to wait before cancelling the
   *                  image request. If zero, there is no timeout.
   * @param aListener An |nsIAlertNotificationImageListener| implementation,
   *                  notified when the image loads. The listener is kept alive
   *                  until the request completes.
   * @param aUserData An opaque parameter passed to the listener's methods.
   *                  Not used by the libnotify backend, but the OS X backend
   *                  passes the pending notification.
   */
  nsICancelable loadImage(in unsigned long aTimeout,
                          in nsIAlertNotificationImageListener aListener,
                          [optional] in nsISupports aUserData);
};

[scriptable, uuid(f7a36392-d98b-4141-a7d7-4e46642684e3)]
interface nsIAlertsService : nsISupports
{
  void showPersistentNotification(in AString aPersistentData,
                                  in nsIAlertNotification aAlert,
                                  [optional] in nsIObserver aAlertListener);

  void showAlert(in nsIAlertNotification aAlert,
                 [optional] in nsIObserver aAlertListener);
  /**
   * Initializes and shows an |nsIAlertNotification| with the given parameters.
   *
   * @param aAlertListener Used for callbacks. May be null if the caller
   *                       doesn't care about callbacks.
   * @see nsIAlertNotification for descriptions of all other parameters.
   * @throws NS_ERROR_NOT_AVAILABLE If the notification cannot be displayed.
   *
   * The following arguments will be passed to the alertListener's observe()
   * method:
   *   subject - null
   *   topic   - "alertfinished" when the alert goes away
   *             "alertdisablecallback" when alerts should be disabled for the principal
   *             "alertsettingscallback" when alert settings should be opened
   *             "alertclickcallback" when the text is clicked
   *             "alertshow" when the alert is shown
   *   data    - the value of the cookie parameter passed to showAlertNotification.
   *
   * @note Depending on current circumstances (if the user's in a fullscreen
   *       application, for instance), the alert might not be displayed at all.
   *       In that case, if an alert listener is passed in it will receive the
   *       "alertfinished" notification immediately.
   */
  void showAlertNotification(in AString aImageURL,
                             in AString aTitle,
                             in AString aText,
                             [optional] in boolean aTextClickable,
                             [optional] in AString aCookie,
                             [optional] in nsIObserver aAlertListener,
                             [optional] in AString aName,
                             [optional] in AString aDir,
                             [optional] in AString aLang,
                             [optional] in AString aData,
                             [optional] in nsIPrincipal aPrincipal,
                             [optional] in boolean aInPrivateBrowsing,
                             [optional] in boolean aRequireInteraction);

  /**
   * Close alerts created by the service.
   *
   * @param aName          The name of the notification to close. If no name
   *                       is provided then only a notification created with
   *                       no name (if any) will be closed.
   */
  void closeAlert([optional] in AString aName,
                  [optional] in nsIPrincipal aPrincipal);

};

[scriptable, uuid(c5d63e3a-259d-45a8-b964-8377967cb4d2)]
interface nsIAlertsDoNotDisturb : nsISupports
{
  /**
   * Toggles a manual Do Not Disturb mode for the service to reduce the amount
   * of disruption that alerts cause the user.
   * This may mean only displaying them in a notification tray/center or not
   * displaying them at all. If a system backend already supports a similar
   * feature controlled by the user, enabling this may not have any impact on
   * code to show an alert. e.g. on OS X, the system will take care not
   * disrupting a user if we simply create a notification like usual.
   */
  attribute bool manualDoNotDisturb;
};

[scriptable, uuid(fc6d7f0a-0cf6-4268-8c71-ab640842b9b1)]
interface nsIAlertsIconData : nsISupports
{
  /**
   * Shows an alert with an icon. Web notifications use the favicon of the
   * page that created the alert. If the favicon is not in the Places database,
   * |aIconSize| will be zero.
  */
  void showAlertWithIconData(in nsIAlertNotification aAlert,
                             [optional] in nsIObserver aAlertListener,
                             [optional] in uint32_t aIconSize,
                             [const, array, size_is(aIconSize)] in uint8_t
                                                                aIconData);
};

[scriptable, uuid(f3c82915-bf60-41ea-91ce-6c46b22e381a)]
interface nsIAlertsIconURI : nsISupports
{
  /**
   * Shows an alert with an icon URI. Web notifications use |moz-anno:|
   * URIs to reference favicons from Places. If the page doesn't have a
   * favicon, |aIconURI| will be |null|.
   */
  void showAlertWithIconURI(in nsIAlertNotification aAlert,
                            [optional] in nsIObserver aAlertListener,
                            [optional] in nsIURI aIconURI);
};