Skip to content

Commit ea7ab70

Browse files
committed
Allow notifications and actions to specify a navigable URL
This makes notifications more declarative by not requiring explicit handling of the clicks by the web application.
1 parent 0fd4b82 commit ea7ab70

File tree

1 file changed

+93
-9
lines changed

1 file changed

+93
-9
lines changed

notifications.bs

Lines changed: 93 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ representation of something that happened, such as the delivery of a message.
4848
<p>A <a>notification</a> has an associated
4949
<dfn for=notification id=concept-title>title</dfn> which is a string.
5050

51-
<p>A <a>notification</a> has an associated
52-
<dfn for=notification id=body>body</dfn> which is a string.
53-
5451
<p>A <a>notification</a> has an associated
5552
<dfn for=notification id=concept-direction>direction</dfn> which is "<code>auto</code>",
5653
"<code>ltr</code>", or "<code>rtl</code>".
@@ -59,6 +56,12 @@ representation of something that happened, such as the delivery of a message.
5956
<dfn for=notification id=concept-language>language</dfn> which is a string
6057
representing either a valid BCP 47 language tag or the empty string.
6158

59+
<p>A <a>notification</a> has an associated <dfn for=notification id=body>body</dfn> which is a
60+
string.
61+
62+
<p>A <a>notification</a> has an associated <dfn for=notification>URL</dfn> which is null or a
63+
<a for=/>URL</a>. It is initially null.
64+
6265
<p>A <a>notification</a> has an associated
6366
<dfn for=notification id=tag>tag</dfn> which is a string.
6467

@@ -129,12 +132,15 @@ support these features might ignore them.
129132
for an end user. Each <a for=/>action</a> has an associated:
130133

131134
<dl>
132-
<dt><dfn for=action id=action-title>title</dfn>
135+
<dt><dfn for=action id=action-name>name</dfn>
133136
<dd>A string.
134137

135-
<dt><dfn for=action id=action-name>name</dfn>
138+
<dt><dfn for=action id=action-title>title</dfn>
136139
<dd>A string.
137140

141+
<dt><dfn for=action>URL</dfn>
142+
<dd>Null or a <a for=/>URL</a>. It is initially null.
143+
138144
<dt><dfn for=action>icon URL</dfn>
139145
<dd>Null or a <a for=/>URL</a>. It is initially null.
140146

@@ -211,6 +217,24 @@ string <var>title</var>, {{NotificationOptions}} <a for=/>dictionary</a> <var>op
211217
<li><p>Set <var>notification</var>'s <a for=notification>body</a> to
212218
<var>options</var>["{{NotificationOptions/body}}"].
213219

220+
<li>
221+
<p>If <var>options</var>["{{NotificationOptions/url}}"] <a for=map>exists</a>:
222+
223+
<ol>
224+
<li><p>Let <var>url</var> be the result of <a lt="URL parser">parsing</a>
225+
<var>options</var>["{{NotificationOptions/url}}"] using <var>baseURL</var>.
226+
227+
<li>
228+
<p>If <var>url</var> is not failure:
229+
230+
<ol>
231+
<li><p>If <var>url</var>'s <a for=url>origin</a> is not <a>same origin</a> with
232+
<var>notification</var>'s <a for=notification>origin</a>, then <a>throw</a> a {{TypeError}}.
233+
234+
<li><p>Set <var>notification</var>'s <a for=notification>URL</a> to <var>url</var>.
235+
</ol>
236+
</ol>
237+
214238
<li><p>Set <var>notification</var>'s <a for=notification>tag</a> to
215239
<var>options</var>["{{NotificationOptions/tag}}"].
216240

@@ -266,6 +290,24 @@ string <var>title</var>, {{NotificationOptions}} <a for=/>dictionary</a> <var>op
266290
<li><p>Set <var>action</var>'s <a for=action>title</a> to
267291
<var>entry</var>["{{NotificationAction/title}}"].
268292

293+
<li>
294+
<p>If <var>entry</var>["{{NotificationAction/url}}"] <a for=map>exists</a>,
295+
296+
<ol>
297+
<li><p>Let <var>url</var> be the result of <a lt="URL parser">parsing</a>
298+
<var>entry</var>["{{NotificationAction/url}}"] using <var>baseURL</var>.
299+
300+
<li>
301+
<p>If <var>url</var> is not failure:
302+
303+
<ol>
304+
<li><p>If <var>url</var>'s <a for=url>origin</a> is not <a>same origin</a> with
305+
<var>notification</var>'s <a for=notification>origin</a>, then <a>throw</a> a {{TypeError}}.
306+
307+
<li><p>Set <var>action</var>'s <a for=action>URL</a> to <var>url</var>.
308+
</ol>
309+
</ol>
310+
269311
<li><p>If <var>entry</var>["{{NotificationAction/icon}}"] <a for=map>exists</a>, then
270312
<a lt="url parser">parse</a> it using <var>baseURL</var>, and if that does not return failure,
271313
set <var>action</var>'s <a for=action>icon URL</a> to the return value. (Otherwise
@@ -527,14 +569,39 @@ interpreted as a language tag. Validity or well-formedness are not enforced. [[!
527569
platform supports activation, the user agent must (unless otherwise specified) run these steps:
528570

529571
<ol>
572+
<li><p>Let <var>action</var> be null.
573+
574+
<li><p>If one of <var>notification</var>'s <a for=notification>actions</a> was activated by the end
575+
user, then set <var>action</var> to that <a for=/>action</a>.
576+
577+
<li><p>Let <var>url</var> be <var>notification</var>'s <a for=notification>URL</a>.
578+
579+
<li>
580+
<p>If <var>action</var> is non-null, then set <var>url</var> to <var>action</var>'s
581+
<a for=action>URL</a>.
582+
583+
<p class=note>This intentionally makes it so that when an <a for=/>action</a>'s
584+
<a for=action>URL</a> is null, it falls through to the <code>click</code> event, providing more
585+
flexibility to the web developer.
586+
587+
<li>
588+
<p>If <var>url</var> is non-null:
589+
590+
<ol>
591+
<li><p><a>Create a fresh top-level traversable</a> given <var>url</var>.
592+
<!-- XXX Should maybe set userInvolvement correctly here? -->
593+
594+
<li><p>Return.
595+
</ol>
596+
530597
<li>
531598
<p>If <var>notification</var> is a <a>persistent notification</a>, then:
532599

533600
<ol>
534-
<li><p>Let <var>action</var> be the empty string.
601+
<li><p>Let <var>actionName</var> be the empty string.
535602

536-
<li><p>If one of <var>notification</var>'s <a for=notification>actions</a> was activated by the
537-
user, then set <var>action</var> to that <a for=/>action</a>'s <a for=action>name</a>.
603+
<li><p>If <var>action</var> is non-null, then set <var>actionName</var> to <var>action</var>'s
604+
<a for=action>name</a>.
538605

539606
<li><a>Fire a service worker notification event</a> named "<code>notificationclick</code>" given
540607
<var>notification</var> and <var>action</var>.
@@ -622,6 +689,7 @@ interface Notification : EventTarget {
622689
readonly attribute NotificationDirection dir;
623690
readonly attribute DOMString lang;
624691
readonly attribute DOMString body;
692+
readonly attribute USVString url;
625693
readonly attribute DOMString tag;
626694
readonly attribute USVString image;
627695
readonly attribute USVString icon;
@@ -641,6 +709,7 @@ dictionary NotificationOptions {
641709
NotificationDirection dir = "auto";
642710
DOMString lang = "";
643711
DOMString body = "";
712+
USVString url;
644713
DOMString tag = "";
645714
USVString image;
646715
USVString icon;
@@ -669,6 +738,7 @@ enum NotificationDirection {
669738
dictionary NotificationAction {
670739
required DOMString action;
671740
required DOMString title;
741+
USVString url;
672742
USVString icon;
673743
};
674744

@@ -824,6 +894,16 @@ return the <a>maximum number of actions</a> supported.
824894
<p>The <dfn attribute for=Notification><code>body</code></dfn> getter steps are to return
825895
<a>this</a>'s <a>notification</a>'s <a for=notification>body</a>.
826896

897+
<p>The <dfn attribute for=Notification><code>url</code></dfn> getter steps are:
898+
899+
<ol>
900+
<li><p>If <a>this</a>'s <a>notification</a>'s <a for=notification>URL</a> is null, then return the
901+
empty string.
902+
903+
<li><p>Return <a>this</a>'s <a>notification</a>'s <a for=notification>URL</a>,
904+
<a lt="URL serializer">serialized</a>.
905+
</ol>
906+
827907
<p>The <dfn attribute for=Notification><code>tag</code></dfn> getter steps are to return
828908
<a>this</a>'s <a>notification</a>'s <a for=notification>tag</a>.
829909

@@ -896,6 +976,10 @@ then return null.
896976
<li><p>Set <var>action</var>["{{NotificationAction/title}}"] to <var>entry</var>'s
897977
<a for=action>title</a>.
898978

979+
<li><p>If <var>entry</var>'s <a for=action>URL</a> is non-null, then set
980+
<var>action</var>["{{NotificationAction/url}}"] to <var>entry</var>'s <a for=action>URL</a>,
981+
<a lt="URL serializer">serialized</a>.
982+
899983
<li><p>If <var>entry</var>'s <a for=action>icon URL</a> is non-null, then set
900984
<var>action</var>["{{NotificationAction/icon}}"] to <var>entry</var>'s
901985
<a for=action>icon URL</a>, <a lt="URL serializer">serialized</a>.
@@ -937,7 +1021,7 @@ not.onclick = function() { displaySong(this); };</pre>
9371021

9381022
<p>Here a service worker shows a notification with a single "Archive" <a for=/>action</a>, allowing
9391023
users to perform this common task from the notification without having to open the website (for
940-
example the, notification platform might show a button on the notification). The user can also
1024+
example, the notification platform might show a button on the notification). The user can also
9411025
activate the main body of the notification to open their inbox.
9421026

9431027
<pre class=example id=example-50e7c86c>

0 commit comments

Comments
 (0)