Skip to content

Commit ea03565

Browse files
committed
Add app badging to Declarative Web Push
1 parent 54d5cb1 commit ea03565

File tree

1 file changed

+82
-19
lines changed

1 file changed

+82
-19
lines changed

index.html

Lines changed: 82 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -392,14 +392,26 @@ <h3>
392392
</dd>
393393
</dl>
394394
</dd>
395+
<dt>
396+
<code>app_badge</code>
397+
</dt>
398+
<dd>
399+
<p>
400+
A [=/64-bit unsigned integer=].
401+
</p>
402+
<p class="note">
403+
Platform conventions are likely to impose a lower limit with regards to what is
404+
displayed to the end user. [[BADGING]]
405+
</p>
406+
</dd>
395407
<dt>
396408
<code>mutable</code>
397409
</dt>
398410
<dd>
399411
<p>
400412
A boolean. When true causes a <code>push</code> event to be dispatched to a service
401-
worker (if any) containing the {{Notification}} object described by the
402-
<a>declarative push message</a>.
413+
worker (if any) containing the {{Notification}} object and app badge number (if
414+
any) described by the <a>declarative push message</a>.
403415
</p>
404416
</dd>
405417
</dl>
@@ -411,7 +423,8 @@ <h3>
411423
<p>
412424
A <dfn>declarative push message parser result</dfn> is a [=/tuple=] consisting of a
413425
<dfn data-dfn-for="declarative push message parser result">notification</dfn> (a
414-
[=/notification=]) and a <dfn data-dfn-for=
426+
[=/notification=]), an <dfn data-dfn-for="declarative push message parser result">app
427+
badge</dfn> (null or an integer), and a <dfn data-dfn-for=
415428
"declarative push message parser result">mutable</dfn> (a boolean).
416429
</p>
417430
<p>
@@ -673,6 +686,18 @@ <h3>
673686
<var>notification</var>'s [=notification/actions=] is null, then return failure.
674687
</p>
675688
</li>
689+
<li>
690+
<p>
691+
Let <var>appBadge</var> be null.
692+
</p>
693+
</li>
694+
<li>
695+
<p>
696+
If <var>message</var>["`app_badge`"] [=map/exists=] and
697+
<var>message</var>["`app_badge`"] is a [=/64-bit unsigned integer=], then set
698+
<var>appBadge</var> to <var>message</var>["`app_badge`"].
699+
</p><!-- unsigned long long in Web IDL -->
700+
</li>
676701
<li>
677702
<p>
678703
Let <var>mutable</var> be false.
@@ -687,7 +712,7 @@ <h3>
687712
</li>
688713
<li>
689714
<p>
690-
Return (<var>notification</var>, <var>mutable</var>).
715+
Return (<var>notification</var>, <var>appBadge</var>, <var>mutable</var>).
691716
</p>
692717
</li>
693718
</ol>
@@ -1598,11 +1623,13 @@ <h2>
15981623
constructor(DOMString type, optional PushEventInit eventInitDict = {});
15991624
readonly attribute PushMessageData? data;
16001625
readonly attribute Notification? notification;
1626+
readonly attribute unsigned long long? appBadge;
16011627
};
16021628

16031629
dictionary PushEventInit : ExtendableEventInit {
16041630
PushMessageDataInit? data = null;
16051631
Notification? notification = null;
1632+
unsigned long long? appBadge = null;
16061633
};
16071634

16081635
typedef (BufferSource or USVString) PushMessageDataInit;
@@ -1629,6 +1656,9 @@ <h2>
16291656
<p>
16301657
The <dfn>notification</dfn> attribute must return the value it was initialized with.
16311658
</p>
1659+
<p>
1660+
The <dfn>appBadge</dfn> attribute must return the value it was initialized with.
1661+
</p>
16321662
</section>
16331663
<section>
16341664
<h2>
@@ -1715,6 +1745,11 @@ <h2>
17151745
Let |notificationShown| be false.
17161746
</p>
17171747
</li>
1748+
<li>
1749+
<p>
1750+
Let |appBadgeSet| be false.
1751+
</p>
1752+
</li>
17181753
<li>
17191754
<p>
17201755
If |declarativeResult|'s [=declarative push message parser result/mutable=]
@@ -1724,14 +1759,16 @@ <h2>
17241759
<li>
17251760
<p>
17261761
Let |result| be the result of [=fire a push event|firing a push event=]
1727-
given |registration|, null, and a new {{Notification}} object
1728-
representing |notification|.
1762+
given |registration|, null, a new {{Notification}} object representing
1763+
|notification|, and |declarativeResult|'s [=declarative push message
1764+
parser result/app badge=].
17291765
</p>
17301766
</li>
17311767
<li>
17321768
<p>
17331769
If |result| is not failure, then set |notificationShown| to |result|'s
1734-
[=push event result/notification shown=].
1770+
[=push event result/notification shown=] and |appBadgeSet| to |result|'s
1771+
[=push event result/app badge set=].
17351772
</p>
17361773
</li>
17371774
</ol>
@@ -1742,6 +1779,12 @@ <h2>
17421779
given |notification|.
17431780
</p>
17441781
</li>
1782+
<li>
1783+
<p>
1784+
If |appBadgeSet| is false, then <a href=
1785+
"https://github.com/w3c/badging/issues/111">w3c/badging #111</a>...
1786+
</p>
1787+
</li>
17451788
<li>
17461789
<p>
17471790
[=acknowledge a push message|Acknowledge=] the <a>push message</a> and abort
@@ -1761,7 +1804,7 @@ <h2>
17611804
<li>
17621805
<p>
17631806
Let |result| be the result of [=fire a push event|firing a push event=] given
1764-
|registration|, |data|, and null.
1807+
|registration|, |data|, null, and null.
17651808
</p>
17661809
</li>
17671810
<li>
@@ -1779,20 +1822,27 @@ <h2>
17791822
</li>
17801823
</ol>
17811824
<p>
1782-
A <dfn>push event result</dfn> is a [=/tuple=] consisting of a <dfn data-dfn-for=
1783-
"push event result">notification shown</dfn> (a [=/boolean=]).
1825+
A <dfn>push event result</dfn> is a [=/tuple=] consisting of a <dfn for=
1826+
"push event result">notification shown</dfn> (a [=/boolean=]) and an <dfn for=
1827+
"push event result">app badge set</dfn> (a [=/boolean=]).
17841828
</p>
17851829
<p>
17861830
To <dfn>fire a push event</dfn> given a [=/service worker registration=] |registration|,
1787-
{{PushMessageData}} object or null |data|, and a [=/notification=] or null
1788-
|notification|, run these steps. They return failure or a [=/push event result=].
1831+
{{PushMessageData}} object or null |data|, a [=/notification=] or null |notification|,
1832+
and an integer or null |appBadge|, run these steps. They return failure or a [=/push
1833+
event result=].
17891834
</p>
17901835
<ol>
17911836
<li>
17921837
<p>
17931838
Let |notificationResult| be null.
17941839
</p>
17951840
</li>
1841+
<li>
1842+
<p>
1843+
Let |appBadgeResult| be null.
1844+
</p>
1845+
</li>
17961846
<li>
17971847
<p>
17981848
Set |registration|'s [=service worker registration/has shownotification() been
@@ -1817,6 +1867,12 @@ <h2>
18171867
<dd>
18181868
|notification|
18191869
</dd>
1870+
<dt>
1871+
{{PushEvent/appBadge}}
1872+
</dt>
1873+
<dd>
1874+
|appBadge|
1875+
</dd>
18201876
</dl>
18211877
<p>
18221878
Then run the following steps in parallel, with |dispatchedEvent|:
@@ -1830,21 +1886,28 @@ <h2>
18301886
</li>
18311887
<li>
18321888
<p>
1833-
If they do not resolve successfully, then set |notificationResult| to failure.
1889+
If they do not resolve successfully, then set |notificationResult| and
1890+
|appBadgeResult| to failure and abort these steps.
1891+
</p>
1892+
</li>
1893+
<li>
1894+
<p>
1895+
Set |notificationResult| to |registration|'s [=service worker registration/has
1896+
shownotification() been successfully invoked|has `showNotification()` been
1897+
successfully invoked=].
18341898
</p>
18351899
</li>
18361900
<li>
18371901
<p>
1838-
Otherwise, set |notificationResult| to |registration|'s [=service worker
1839-
registration/has shownotification() been successfully invoked|has
1840-
`showNotification()` been successfully invoked=].
1902+
Set |appBadgeResult| to true if {{NavigatorBadge/setAppBadge()}} has been
1903+
invoked; otherwise false.
18411904
</p>
18421905
</li>
18431906
</ol>
18441907
</li>
18451908
<li>
18461909
<p>
1847-
Wait for |notificationResult| to be non-null.
1910+
Wait for |notificationResult| and |appBadgeResult| to be non-null.
18481911
</p>
18491912
</li>
18501913
<li>
@@ -1854,12 +1917,12 @@ <h2>
18541917
</li>
18551918
<li>
18561919
<p>
1857-
[=/Assert=]: |notificationResult| is a [=/boolean=].
1920+
[=/Assert=]: |notificationResult| and |appBadgeResult| are [=/booleans=].
18581921
</p>
18591922
</li>
18601923
<li>
18611924
<p>
1862-
Return (|notificationResult|).
1925+
Return (|notificationResult|, |appBadgeResult|).
18631926
</p>
18641927
</li>
18651928
</ol>

0 commit comments

Comments
 (0)