forked from w3c/badging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
441 lines (437 loc) · 17 KB
/
index.html
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>
Badging API
</title>
<script src="https://www.w3.org/Tools/respec/respec-w3c-common" class=
"remove"></script>
<script class='remove'>
var respecConfig = {
specStatus: "CG-DRAFT",
edDraftURI: "https://wicg.github.io/badging/",
github: {
repoURL: "https://github.com/WICG/badging/",
branch: "master"
},
shortName: "badging",
processVersion: 2018,
wg: "Web Incubator Community Group",
wgURI: "https://wicg.io",
editors: [{
name: "Matt Giuca",
company: "Google Inc.",
companyURL: "https://google.com"
}, {
name: "Jay Harris",
company: "Google Inc.",
companyURL: "https://google.com"
}],
otherLinks: [{
key: "Implementation status",
data: [{
value: "Chromium",
href: "https://www.chromestatus.com/features/6068482055602176"
}]
}],
xref: "web-platform"
};
</script>
</head>
<body>
<section id="abstract" class="informative">
<p>
This specification defines an API allowing web pages and [=web
applications=] to set a badge on the document, or an application-wide
badge, shown in an operating-system-specific place associated with the
application (such as the shelf or home screen), for the purpose of
notifying the user when the state of the page or application has
changed (e.g., when new messages have arrived), without showing a more
heavyweight notification.
</p>
</section>
<section id="sotd">
<p>
This is an early draft of the Badging API spec.
</p>
</section>
<section class="informative">
<h2>
Usage examples
</h2>
<p>
The following example shows how an email application might set a badge
showing the unread count associated with the current document, which is
updated whenever the client polls for mail from the server.
</p>
<pre class="example javascript" title=
"Showing unread count for this document">
function pollForMail() {
// ... Fetch unread mail from server. ...
// Set the document badge. If getUnreadCount() returns 0, this is
// equivalent to navigator.clearClientBadge().
navigator.setClientBadge(getUnreadCount());
}
</pre>
<p>
The next example shows how a game might show when it is the player's
turn. Again, this associates the badge with the current document.
</p>
<pre class="example javascript" title=
"Showing ready status for this document">
function showPlayerTurn(playerTurnId) {
if (playerTurnId === localPlayerId)
navigator.setClientBadge();
else
navigator.clearClientBadge();
}
</pre>
<p>
A separate set of methods set the badge on the installed [=web
application=], if any, whose [=navigation scope=] this document is
within. The badge might show up on the application's icon in the
operating system shelf. These examples work the same as above, except
that the badge has global scope (if multiple documents within the same
application set or clear a badge, the most recent one takes effect),
and can continue being seen even after the last document closes.
</p>
<pre class="example javascript" title=
"Showing unread count on the app icon">
function pollForMail() {
// ... Fetch unread mail from server. ...
// Set the app badge.
navigator.setAppBadge(getUnreadCount());
}
</pre>
<pre class="example javascript" title=
"Showing ready status on the app icon">
function showPlayerTurn(playerTurnId) {
if (playerTurnId === localPlayerId)
navigator.setAppBadge();
else
navigator.clearAppBadge();
}
</pre>
<p>
To show a badge on both the document(s) and app icon(s), use both APIs
together.
</p>
</section>
<section>
<h2>
Badge model
</h2>
<p>
A <dfn>badge</dfn> may be one of the following values:
</p>
<ul>
<li>The special value <dfn>nothing</dfn>, which indicates that there is
no badge currently set.
</li>
<li>The special value <dfn>flag</dfn>, which indicates that the badge
is set, but contains no specific data.
</li>
<li>An {{unsigned long long}} value, which MUST NOT be 0.
</li>
</ul>
<p>
Each [=document=] and each [=web application=] is associated with a
<a>badge</a> value, which is initialized to <a>nothing</a>.
</p>
<p>
The user agent MAY reset an application's badge to <a>nothing</a> at
its discretion (for example, when the system is restarted).
</p>
<p>
If a <a>badge</a> is <a>nothing</a>, it is said to be
"<dfn>cleared</dfn>". Otherwise, it is said to be "<dfn>set</dfn>".
</p>
</section>
<section>
<h2>
Badge display
</h2>
<p>
When a document's badge is <a>set</a>, if the <a data-cite=
"html#concept-document-bc">document's browsing context</a> is a
[=top-level browsing context=], the user agent SHOULD display the
document's badge value alongside the other identifying information for
that document (for example, on top of the document's icon or near its
title).
</p>
<p class="note">
The user agent is not expected to display a badge associated with a
document that is not a [=top-level browsing context=], although it is
allowed to. A user agent does not need to store the badge for a
non-top-level browsing context if it does not intend to display it.
</p>
<p>
When the application's badge is <a>set</a>, the user agent SHOULD
display the application's badge alongside any symbolic representations
of the application in the user's operating system (for example, as a
small overlay on top of the application's icon).
</p>
<p>
If the badge is set to special value <a>flag</a>, the user agent SHOULD
show an indicator with a non-specific symbol (such as a coloured
circle).
</p>
<p>
The user agent MAY simplify or degrade the data in any way. For
example, a large integer may be saturated (for example, as "99+"). The
font and formatting are entirely at the user agent's discretion. The
user agent MAY ignore the data, and merely show a marker when the
status is <a>set</a>.
</p>
<p>
When presenting a badge, it SHOULD be formatted according to the user's
<a data-cite="ltli/#locale">locale</a> settings. For example, the badge
content '7' should be displayed as '7' in the <a data-cite=
"ltli/#locale">locale</a> 'en-NZ' but as '٧' in 'ar-EG'.
</p>
</section>
<section>
<h2>
Extensions to the `Navigator` and `WorkerNavigator` interfaces
</h2>
<p>
The {{Navigator}} and {{WorkerNavigator}} interfaces are extended with
methods for setting and clearing both the document and application
badge indicators from documents and service workers, respectively.
</p>
<pre class="idl">
// Methods only exposed on documents.
[SecureContext]
partial interface Navigator {
Promise<void> setClientBadge(optional [EnforceRange] unsigned long long contents);
Promise<void> clearClientBadge();
};
// Methods exposed on both documents and service workers.
[SecureContext]
interface mixin NavigatorBadge {
Promise<void> setAppBadge(optional [EnforceRange] unsigned long long contents);
Promise<void> clearAppBadge();
};
Navigator includes NavigatorBadge;
WorkerNavigator includes NavigatorBadge;
</pre>
<p>
User agents that never display document badges SHOULD NOT expose the
{{Navigator/setClientBadge()}} and {{Navigator/clearClientBadge()}}
methods. Similarly, user agents that never display application badges
SHOULD NOT expose the {{NavigatorBadge/setAppBadge()}} and
{{NavigatorBadge/clearAppBadge()}} methods.
</p>
<p class="note">
This is important as a feature-detection mechanism to allow sites to
determine whether setting a badge will have any effect, based on the
presence of the methods. In particular, sites can use the absence of
{{Navigator/setClientBadge()}} as a condition for displaying a fallback
badge in the page's [^title^] or <a data-cite=
"html#rel-icon"><code>icon</code></a>.
</p>
<div class="issue" data-number="60"></div>
<div class="issue" data-number="61"></div>
<section>
<h3>
<dfn data-dfn-for="Navigator">setClientBadge()</dfn> method
</h3>
<p>
When the {{Navigator/setClientBadge()}} method is called on
|navigator:Navigator| with argument |contents:unsigned long long|:
</p>
<ol>
<li>Return [=a promise resolved with=] undefined, and [=in
parallel=]:
<ol>
<li>Let |document:Document| be |navigator|'s [=relevant settings
object=]'s [=environment settings object/responsible document=].
</li>
<li>If |contents| is omitted, set the badge associated with
|document| to <a>flag</a>.
</li>
<li>Else, if |contents| is 0, set the badge associated with
|document| to <a>nothing</a>.
</li>
<li>Else, set the badge associated with |document| to |contents|.
</li>
</ol>
</li>
</ol>
</section>
<section>
<h3>
<dfn data-dfn-for="Navigator">clearClientBadge()</dfn> method
</h3>
<p>
When the {{Navigator/clearClientBadge()}} method is called on
|navigator:Navigator|, return [=a promise resolved with=] undefined,
and [=in parallel=], set the the badge associated with |navigator|'s
[=relevant settings object=]'s [=environment settings
object/responsible document=] to <a>nothing</a>.
</p>
</section>
<section>
<h3>
<dfn data-dfn-for="NavigatorBadge">setAppBadge()</dfn> method
</h3>
<p>
When the {{NavigatorBadge/setAppBadge()}} method is called on
|navigator:Navigator| with argument |contents:unsigned long long|:
</p>
<ol>
<li>If |navigator|'s [=relevant settings object=] does not have a
[=environment settings object/responsible document=], and is not a
<a data-cite="service-workers">service worker client</a>, return [=a
promise rejected with=] a {{"NotSupportedError"}}.
</li>
<li>Otherwise, return [=a promise resolved with=] undefined, and [=in
parallel=]:
<ol>
<li>Let |result:set of applications| be the result of
<a>determining the matching applications</a> on |navigator|'s
[=relevant settings object=].
</li>
<li>For each |app:application| in |result|:
<ol>
<li>If |contents| is omitted, set the badge associated with
|app| to <a>flag</a>.
</li>
<li>Else, if |contents| is 0, set the badge associated with
|app| to <a>nothing</a>.
</li>
<li>Else, set the badge associated with |app| to |contents|.
</li>
</ol>
</li>
</ol>
</li>
</ol>
</section>
<section>
<h3>
<dfn data-dfn-for="NavigatorBadge">clearAppBadge()</dfn> method
</h3>
<p>
When the {{NavigatorBadge/clearAppBadge()}} method is called on
|navigator:Navigator|:
</p>
<ol>
<li>If |navigator|'s [=relevant settings object=] does not have a
[=environment settings object/responsible document=], and is not a
<a data-cite="service-workers">service worker client</a>, return [=a
promise rejected with=] a {{"NotSupportedError"}}.
</li>
<li>Otherwise, return [=a promise resolved with=] undefined, and [=in
parallel=]:
<ol>
<li>Let |result:set of applications| be the result of
<a>determining the matching applications</a> on |navigator|'s
[=relevant settings object=].
</li>
<li>Set the badge associated with each application in |result| to
<a>nothing</a>.
</li>
</ol>
</li>
</ol>
</section>
<section>
<h3>
Determining the set of matching applications
</h3>
<div class="note">
<p>
This algorithm is used to decide which app(s) receive a badge when
the {{NavigatorBadge/setAppBadge()}} method is called from either a
document or service worker context.
</p>
<p>
If called from a document context, the badge is applied to at most
one application: the one with the most specific scope whose scope
encloses this document URL.
</p>
<p>
If called from a service worker context, the badge is applied to
all applications whose scope sits within the service worker's
scope.
</p>
</div>
<p>
The steps to <dfn data-lt=
"determining the matching applications">determine the matching
applications</dfn> takes an [=environment settings object=]
|environment:environment settings object| that either has a
[=environment settings object/responsible document=], or is a
<a data-cite="service-workers">service worker client</a>, and returns
a <a data-cite="infra#ordered-set">set</a> of [=web applications=]:
</p>
<ol>
<li>If |environment| has a [=environment settings object/responsible
document=] |document:Document|:
<ol>
<li>Let |apps:set of applications| be the <a data-cite=
"infra#ordered-set">set</a> of installed [=web applications=]
such that |document|'s <a data-cite=
"dom#concept-document-url">URL</a> is <a data-cite=
"appmanifest#dfn-within-scope-manifest">within scope</a> of the
application's manifest. (Order is not important.)
</li>
<li>[=list/Remove=] all elements of |apps| other than the one
with the longest (i.e., most specific) [=navigation scope=].
</li>
<li>Return |apps|.
</li>
</ol>
</li>
<li>Otherwise (|environment| is a <a data-cite=
"service-workers">service worker client</a>):
<ol>
<li>Return the <a data-cite="infra#ordered-set">set</a> of
installed [=web applications=] whose [=navigation scope=] is
<a data-cite="appmanifest#dfn-within-scope-manifest">within
scope</a> (as defined in [[AppManifest]]) of |environment|'s
<a data-cite=
"service-workers-1#dfn-containing-service-worker-registration">containing
service worker registration</a>'s <a data-cite=
"service-workers-1#dfn-scope-url">scope url</a>. (Order is not
important.)
</li>
</ol>
</li>
</ol>
</section>
</section>
<section class="informative">
<h2>
Security and privacy considerations
</h2>
<p>
The API is write-only by design. There is no way for a site to read
back the value of a badge that was previously set, to ensure that the
application badge cannot be used as a storage or fingerprinting
mechanism.
</p>
<div class="issue" data-number="44"></div>
</section>
<section class="informative">
<h2>
Accessibility considerations
</h2>
<div class="issue" data-number="24"></div>
</section>
<section>
<h2>
Dependencies
</h2>
<p>
<dfn data-cite="appmanifest#installable-web-applications" data-lt=
"web application|web applications">Installable web applications</dfn>
and <dfn data-cite="appmanifest#dfn-navigation-scope">navigation
scope</dfn> are defined by [[appmanifest]].
</p>
</section>
<section id="conformance"></section>
</body>
</html>