Skip to content

Commit 9a8242e

Browse files
authored
Editorial: prepare create a notification for Declarative Web Push
This makes the following changes: - Instead of making create a notification deal directly with a service worker registration, we leave that to the callers. We also make service worker registration always present on a notification as "can have" fields are confusing and buggy. - Stop requiring an environment settings object for create a notification as that won't necessarily be around for Declarative Web Push. - Sprinkle some `<div algorithm>` around to reduce variable errors and make variables easier to track in user agents with JavaScript enabled.
1 parent bd0b2dc commit 9a8242e

File tree

1 file changed

+76
-44
lines changed

1 file changed

+76
-44
lines changed

notifications.bs

Lines changed: 76 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ IDL, Service Workers, URL, and Vibration API Standards.
4242
<p>A <dfn id=concept-notification>notification</dfn> is an abstract
4343
representation of something that happened, such as the delivery of a message.
4444

45-
<p>A <a>notification</a> <em>can</em> have an associated
46-
<dfn for=notification id=service-worker-registration>service worker registration</dfn>.
45+
<p>A <a>notification</a> has an associated
46+
<dfn for=notification id=service-worker-registration>service worker registration</dfn> (null
47+
or a <a for=/>service worker registration</a>). It is initially null.
4748

4849
<p>A <a>notification</a> has an associated
4950
<dfn for=notification id=concept-title>title</dfn> which is a string.
@@ -156,35 +157,45 @@ corners or painting it in a specific color. Developers are encouraged to use an
156157
such cases gracefully and does not lose important information through, e.g., loss of color or
157158
clipped corners.
158159

159-
<p>A <dfn>non-persistent notification</dfn> is a
160-
<a>notification</a> without an associated
161-
<a for=notification>service worker registration</a>.
160+
<p>A <dfn>non-persistent notification</dfn> is a <a>notification</a> whose
161+
<a for=notification>service worker registration</a> is null.
162162

163-
<p>A <dfn>persistent notification</dfn> is a
164-
<a>notification</a> with an associated
165-
<a for=notification>service worker registration</a>.
163+
<p>A <dfn>persistent notification</dfn> is a <a>notification</a> whose
164+
<a for=notification>service worker registration</a> is non-null.
166165

167166
<!-- XXX https://html.spec.whatwg.org/#fingerprinting-vector -->
168167

169168
<hr>
170169

171-
<p>To <dfn lt="create a notification|creating a notification">create a notification</dfn>, given a
172-
string <var>title</var>, {{NotificationOptions}} <a for=/>dictionary</a> <var>options</var>,
173-
<a for=/>environment settings object</a> <var>settings</var>, and optionally a
174-
{{ServiceWorkerRegistration}} object <var>serviceWorkerRegistration</var>, run these steps:
170+
<div algorithm>
171+
<p>To <dfn>create a notification with a settings object</dfn>, given a string <var>title</var>,
172+
{{NotificationOptions}} <a for=/>dictionary</a> <var>options</var>, and
173+
<a for=/>environment settings object</a> <var>settings</var>:
175174

176175
<ol>
177-
<li><p>Let <var>notification</var> be a new <a>notification</a>.
176+
<li><p>Let <var>origin</var> be <var>settings</var>'s
177+
<a for="environment settings object">origin</a>.
178+
179+
<li><p>Let <var>baseURL</var> be <var>settings</var>'s
180+
<a for="environment settings object">API base URL</a>.
178181

179-
<li><p>If a <var>serviceWorkerRegistration</var> was provided, then set <var>notification</var>'s
180-
<a for=notification>service worker registration</a> to <var>serviceWorkerRegistration</var>.
182+
<li><p>Let <var>fallbackTimestamp</var> be the number of milliseconds from the <a>Unix epoch</a> to
183+
<var>settings</var>'s <a for="environment settings object">current wall time</a>, rounded to the
184+
nearest integer.
181185

182-
<li>
183-
<p>If a <var>serviceWorkerRegistration</var> was not provided and
184-
<var>options</var>["{{NotificationOptions/actions}}"] is not <a for=list>empty</a>, then
185-
<a>throw</a> a {{TypeError}}.
186+
<li><p>Return the result of <a>creating a notification</a> given <var>title</var>,
187+
<var>options</var>, <var>origin</var>, <var>baseURL</var>, and <var>fallbackTimestamp</var>.
188+
</ol>
189+
</div>
186190

187-
<p class=note><a>Actions</a> are only currently supported for <a>persistent notifications</a>.
191+
<div algorithm>
192+
<p>To <dfn export>create a notification</dfn>, given a string <var>title</var>,
193+
{{NotificationOptions}} <a for=/>dictionary</a> <var>options</var>, an <a for=/>origin</a>
194+
<var>origin</var>, a <a for=/>URL</a> <var>baseURL</var>, and an {{EpochTimeStamp}}
195+
<var>fallbackTimestamp</var>:
196+
197+
<ol>
198+
<li><p>Let <var>notification</var> be a new <a>notification</a>.
188199

189200
<li><p>If <var>options</var>["{{NotificationOptions/silent}}"] is true and
190201
<var>options</var>["{{NotificationOptions/vibrate}}"] <a for=map>exists</a>, then <a>throw</a> a
@@ -205,18 +216,14 @@ string <var>title</var>, {{NotificationOptions}} <a for=/>dictionary</a> <var>op
205216
<li><p>Set <var>notification</var>'s <a for=notification>language</a> to
206217
<var>options</var>["{{NotificationOptions/lang}}"].
207218

208-
<li><p>Set <var>notification</var>'s <a for=notification>origin</a> to <var>settings</var>'s
209-
<a for="environment settings object">origin</a>.
219+
<li><p>Set <var>notification</var>'s <a for=notification>origin</a> to <var>origin</var>.
210220

211221
<li><p>Set <var>notification</var>'s <a for=notification>body</a> to
212222
<var>options</var>["{{NotificationOptions/body}}"].
213223

214224
<li><p>Set <var>notification</var>'s <a for=notification>tag</a> to
215225
<var>options</var>["{{NotificationOptions/tag}}"].
216226

217-
<li><p>Let <var>baseURL</var> be <var>settings</var>'s
218-
<a for="environment settings object">API base URL</a>.
219-
220227
<li><p>If <var>options</var>["{{NotificationOptions/image}}"] <a for=map>exists</a>, then
221228
<a lt="URL parser">parse</a> it using <var>baseURL</var>, and if that does not return failure, set
222229
<var>notification</var>'s <a>image URL</a> to the return value. (Otherwise
@@ -238,9 +245,7 @@ string <var>title</var>, {{NotificationOptions}} <a for=/>dictionary</a> <var>op
238245

239246
<li><p>If <var>options</var>["{{NotificationOptions/timestamp}}"] <a for=map>exists</a>, then set
240247
<var>notification</var>'s <a for=notification>timestamp</a> to the value. Otherwise, set
241-
<var>notification</var>'s <a for=notification>timestamp</a> to the number of milliseconds from the
242-
<a>Unix epoch</a> to <var>settings</var>'s
243-
<a for="environment settings object">current wall time</a>, rounded to the nearest integer.
248+
<var>notification</var>'s <a for=notification>timestamp</a> to <var>fallbackTimestamp</var>.
244249

245250
<li><p>Set <var>notification</var>'s <a for=notification>renotify preference</a> to
246251
<var>options</var>["{{NotificationOptions/renotify}}"].
@@ -276,6 +281,7 @@ string <var>title</var>, {{NotificationOptions}} <a for=/>dictionary</a> <var>op
276281

277282
<li><p>Return <var>notification</var>.
278283
</ol>
284+
</div>
279285

280286

281287
<h3 id=lifetime-and-ui-integrations>Lifetime and UI integration</h3>
@@ -692,6 +698,7 @@ object and can be created through {{Notification}}'s
692698

693699
<h3 id=constructors>Constructors</h3>
694700

701+
<div algorithm>
695702
<p>The
696703
<dfn constructor for=Notification lt="Notification(title, options)"><code>new Notification(<var>title</var>, <var>options</var>)</code></dfn>
697704
constructor steps are:
@@ -700,8 +707,15 @@ constructor steps are:
700707
<li><p>If <a>this</a>'s <a>relevant global object</a> is a {{ServiceWorkerGlobalScope}} object,
701708
then <a>throw</a> a {{TypeError}}.
702709

703-
<li><p>Let <var>notification</var> be the result of <a>creating a notification</a> given
704-
<var>title</var>, <var>options</var>, and <a>this</a>'s <a>relevant settings object</a>.
710+
<li>
711+
<p>If <var>options</var>["{{NotificationOptions/actions}}"] is not <a for=list>empty</a>, then
712+
<a>throw</a> a {{TypeError}}.
713+
714+
<p class=note><a>Actions</a> are only supported for <a>persistent notifications</a>.
715+
716+
<li><p>Let <var>notification</var> be the result of
717+
<a>creating a notification with a settings object</a> given <var>title</var>, <var>options</var>,
718+
and <a>this</a>'s <a>relevant settings object</a>.
705719

706720
<li><p>Associate <a>this</a> with <var>notification</var>.
707721

@@ -718,12 +732,15 @@ constructor steps are:
718732
<li><p>Run the <a>show steps</a> for <var>notification</var>.
719733
</ol>
720734
</ol>
735+
</div>
721736

722737

723738
<h3 id=static-members>Static members</h3>
724739

740+
<div algorithm>
725741
<p>The static <dfn attribute for=Notification><code>permission</code></dfn> getter steps are to
726742
return the result of <a>getting the notifications permission state</a>.
743+
</div>
727744

728745
<div class=note>
729746
<p>If you edit standards please refrain from copying the above. Synchronous permissions are like
@@ -740,6 +757,7 @@ return the result of <a>getting the notifications permission state</a>.
740757
</pre>
741758
</div>
742759

760+
<div algorithm>
743761
<p>The static
744762
<dfn method for=Notification><code>requestPermission(<var>deprecatedCallback</var>)</code></dfn>
745763
method steps are:
@@ -770,6 +788,7 @@ method steps are:
770788

771789
<li><p>Return <var>promise</var>.
772790
</ol>
791+
</div>
773792

774793
<p class="warning">Notifications are the one instance thus far where asking the end user upfront
775794
makes sense. Specifications for other APIs should not use this pattern and instead employ one of the
@@ -1029,7 +1048,9 @@ partial interface ServiceWorkerGlobalScope {
10291048
};
10301049
</pre>
10311050

1032-
<p>The <dfn method for=ServiceWorkerRegistration><code>showNotification(title, options)</code></dfn>
1051+
<div algorithm>
1052+
<p>The
1053+
<dfn method for=ServiceWorkerRegistration><code>showNotification(<var>title</var>, <var>options</var>)</code></dfn>
10331054
method steps are:
10341055

10351056
<ol>
@@ -1042,12 +1063,13 @@ method steps are:
10421063
<!-- We might have to throw directly here and below, see
10431064
https://github.com/web-platform-tests/wpt/pull/24601 -->
10441065

1045-
<li><p>Let <var>serviceWorkerRegistration</var> be <a>this</a>.
1066+
<li><p>Let <var>notification</var> be the result of
1067+
<a>creating a notification with a settings object</a> given <var>title</var>, <var>options</var>,
1068+
and <a>this</a>'s <a>relevant settings object</a>. If this threw an exception, then
1069+
<a for=/>reject</a> <var>promise</var> with that exception and return <var>promise</var>.
10461070

1047-
<li><p>Let <var>notification</var> be the result of <a>creating a notification</a> given
1048-
<var>title</var>, <var>options</var>, <a>this</a>'s <a>relevant settings object</a>, and
1049-
<var>serviceWorkerRegistration</var>. If this threw an exception, then <a for=/>reject</a>
1050-
<var>promise</var> with that exception and return <var>promise</var>.
1071+
<li><p>Set <var>notification</var>'s <a for=notification>service worker registration</a> to
1072+
<a>this</a>.
10511073

10521074
<li>
10531075
<p>Run these steps <a>in parallel</a>:
@@ -1068,7 +1090,9 @@ method steps are:
10681090

10691091
<li><p>Return <var>promise</var>.
10701092
</ol>
1093+
</div>
10711094

1095+
<div algorithm>
10721096
<p>The
10731097
<dfn method for=ServiceWorkerRegistration><code>getNotifications(<var>filter</var>)</code></dfn>
10741098
method steps are:
@@ -1116,26 +1140,34 @@ method steps are:
11161140

11171141
<p class=note>This method returns zero or more new {{Notification}} objects which might represent
11181142
the same underlying <a>notification</a> of {{Notification}} objects already in existence.
1143+
</div>
11191144

11201145
<hr>
11211146

1122-
<p>To <dfn>fire a service worker notification event</dfn> named <var>name</var> given
1123-
<var>notification</var> (a <a>notification</a>), and an optional <var>action</var> (a DOMString,
1124-
defaulting to the empty string), <a>Fire Functional Event</a> <var>name</var> using
1125-
{{NotificationEvent}} on <var>notification</var>'s
1126-
<a for=notification>service worker registration</a> with the following properties:
1147+
<div algorithm>
1148+
<p>To <dfn>fire a service worker notification event</dfn> named <var>name</var> given a
1149+
<a for=/>notification</a> <var>notification</var>, and an optional string <var>action</var> (default
1150+
the empty string): run <a>Fire Functional Event</a> given <var>name</var>, {{NotificationEvent}},
1151+
<var>notification</var>'s <a for=notification>service worker registration</a>, and the following
1152+
initialization:
11271153

11281154
<dl>
11291155
<dt>{{NotificationEvent/notification}}
11301156
<dd>A new {{Notification}} object representing <var>notification</var>.
11311157
<dt>{{NotificationEvent/action}}
11321158
<dd><var>action</var>
11331159
</dl>
1160+
</div>
11341161

1135-
<p>The {{NotificationEvent/notification}} getter steps are to return the value it was initialized
1136-
to.
1162+
<div algorithm>
1163+
<p>The <dfn attribute for=NotificationEvent><code>notification</code></dfn> getter steps are to
1164+
return the value it was initialized to.
1165+
</div>
11371166

1138-
<p>The {{NotificationEvent/action}} getter steps are to return the value it was initialized to.
1167+
<div algorithm>
1168+
<p>The <dfn attribute for=NotificationEvent><code>action</code></dfn> getter steps are to return the
1169+
value it was initialized to.
1170+
</div>
11391171

11401172
<p>The following is the <a>event handler</a> (and its corresponding
11411173
<a>event handler event type</a>) that must be supported as attribute by the

0 commit comments

Comments
 (0)