Skip to content

Commit 84723c1

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. This is part of the Declarative Web Push effort: w3c/push-api#360.
1 parent d7f3e1a commit 84723c1

File tree

1 file changed

+70
-4
lines changed

1 file changed

+70
-4
lines changed

notifications.bs

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ or "<code>rtl</code>").
6060
<p>A <a for=/>notification</a> has an associated <dfn for=notification id=body>body</dfn> (a
6161
string).
6262

63+
<p>A <a for=/>notification</a> has an associated <dfn export for=notification>navigation URL</dfn>
64+
(null or a <a for=/>URL</a>). It is initially null.
65+
6366
<p>A <a for=/>notification</a> has an associated <dfn for=notification id=tag>tag</dfn> (a string).
6467

6568
<p>A <a for=/>notification</a> has an associated <dfn for=notification id=data>data</dfn> (a
@@ -137,6 +140,9 @@ support these features might ignore them.
137140
<dt><dfn for="notification action" id=action-title>title</dfn>
138141
<dd>A string.
139142

143+
<dt><dfn export for="notification action">navigation URL</dfn>
144+
<dd>Null or a <a for=/>URL</a>. It is initially null.
145+
140146
<dt><dfn for="notification action" id=action-icon-url>icon URL</dfn>
141147
<dd>Null or a <a for=/>URL</a>. It is initially null.
142148

@@ -220,6 +226,11 @@ important information through, e.g., loss of color or clipped corners.
220226
<li><p>Set <var>notification</var>'s <a for=notification>body</a> to
221227
<var>options</var>["{{NotificationOptions/body}}"].
222228

229+
<li><p>If <var>options</var>["{{NotificationOptions/navigate}}"] <a for=map>exists</a>, then
230+
<a lt="URL parser">parse</a> it using <var>baseURL</var>, and if that does not return failure, set
231+
<var>notification</var>'s <a for=notification>navigation URL</a> to the return value. (Otherwise
232+
<var>notification</var>'s <a for=notification>navigation URL</a> remains null.)
233+
223234
<li><p>Set <var>notification</var>'s <a for=notification>tag</a> to
224235
<var>options</var>["{{NotificationOptions/tag}}"].
225236

@@ -270,6 +281,11 @@ important information through, e.g., loss of color or clipped corners.
270281
<li><p>Set <var>action</var>'s <a for="notification action">title</a> to
271282
<var>entry</var>["{{NotificationAction/title}}"].
272283

284+
<li><p>If <var>entry</var>["{{NotificationAction/navigate}}"] <a for=map>exists</a>, then
285+
<a lt="URL parser">parse</a> it using <var>baseURL</var>, and if that does not return failure,
286+
set <var>action</var>'s <a for="notification action">navigation URL</a> to the return value.
287+
(Otherwise <var>action</var>'s <a for="notification action">navigation URL</a> remains null.)
288+
273289
<li><p>If <var>entry</var>["{{NotificationAction/icon}}"] <a for=map>exists</a>, then
274290
<a lt="URL parser">parse</a> it using <var>baseURL</var>, and if that does not return failure,
275291
set <var>action</var>'s <a for="notification action">icon URL</a> to the return value. (Otherwise
@@ -541,18 +557,51 @@ interpreted as a language tag. Validity or well-formedness are not enforced. [[!
541557
platform supports activation, the user agent must (unless otherwise specified) run these steps:
542558

543559
<ol>
560+
<li><p>Let <var>action</var> be null.
561+
562+
<li><p>If one of <var>notification</var>'s <a for=notification>actions</a> was activated by the end
563+
user, then set <var>action</var> to that <a for=/>action</a>.
564+
565+
<li><p>Let <var>navigationURL</var> be <var>notification</var>'s
566+
<a for=notification>navigation URL</a>.
567+
568+
<li>
569+
<p>If <var>action</var> is non-null, then set <var>navigationURL</var> to <var>action</var>'s
570+
<a for="notification action">navigation URL</a>.
571+
572+
<p class=note>This intentionally makes it so that when an <a for=/>action</a>'s
573+
<a for="notification action">navigation URL</a> is null, it falls through to the
574+
<code>click</code> event, providing more flexibility to the web developer.
575+
576+
<li>
577+
<p>If <var>navigationURL</var> is non-null:
578+
579+
<ol>
580+
<li><p>If there is an existing <a for=/>top-level traversable</a> <var>traversable</var> within
581+
the user agent's <a for="user agent">top-level traversable set</a> whose
582+
<a for="navigable">active document</a>'s <a for=Document>URL</a> <a for=url>equals</a>
583+
<var>navigationURL</var> with <a for=url/equals><i>exclude fragments</i></a> set to true, then
584+
<a for=/>navigate</a> <var>traversable</var> to <var>navigationURL</var> and return. If there are
585+
multiple <a for=/>top-level traversables</a> that satisfy the condition the user agent has to
586+
pick one in an <a>implementation-defined</a> manner.
587+
<!-- Should maybe set userInvolvement correctly here and below. -->
588+
589+
<li><p><a>Create a fresh top-level traversable</a> given <var>navigationURL</var>.
590+
591+
<li><p>Return.
592+
</ol>
593+
544594
<li>
545595
<p>If <var>notification</var> is a <a>persistent notification</a>, then:
546596

547597
<ol>
548-
<li><p>Let <var>action</var> be the empty string.
598+
<li><p>Let <var>actionName</var> be the empty string.
549599

550-
<li><p>If one of <var>notification</var>'s <a for=notification>actions</a> was activated by the
551-
user, then set <var>action</var> to that <a for=/>notification action</a>'s
600+
<li><p>If <var>action</var> is non-null, then set <var>actionName</var> to <var>action</var>'s
552601
<a for="notification action">name</a>.
553602

554603
<li><a>Fire a service worker notification event</a> named "<code>notificationclick</code>" given
555-
<var>notification</var> and <var>action</var>.
604+
<var>notification</var> and <var>actionName</var>.
556605
</ol>
557606

558607
<li>
@@ -643,6 +692,7 @@ interface Notification : EventTarget {
643692
readonly attribute NotificationDirection dir;
644693
readonly attribute DOMString lang;
645694
readonly attribute DOMString body;
695+
readonly attribute USVString navigate;
646696
readonly attribute DOMString tag;
647697
readonly attribute USVString image;
648698
readonly attribute USVString icon;
@@ -662,6 +712,7 @@ dictionary NotificationOptions {
662712
NotificationDirection dir = "auto";
663713
DOMString lang = "";
664714
DOMString body = "";
715+
USVString navigate;
665716
DOMString tag = "";
666717
USVString image;
667718
USVString icon;
@@ -690,6 +741,7 @@ enum NotificationDirection {
690741
dictionary NotificationAction {
691742
required DOMString action;
692743
required DOMString title;
744+
USVString navigate;
693745
USVString icon;
694746
};
695747

@@ -853,6 +905,16 @@ return the <a>maximum number of actions</a> supported.
853905
<p>The <dfn attribute for=Notification><code>body</code></dfn> getter steps are to return
854906
<a>this</a>'s <a for=/>notification</a>'s <a for=notification>body</a>.
855907

908+
<p>The <dfn attribute for=Notification><code>navigate</code></dfn> getter steps are:
909+
910+
<ol>
911+
<li><p>If <a>this</a>'s <a>notification</a>'s <a for=notification>navigation URL</a> is null, then
912+
return the empty string.
913+
914+
<li><p>Return <a>this</a>'s <a>notification</a>'s <a for=notification>navigation URL</a>,
915+
<a lt="URL serializer">serialized</a>.
916+
</ol>
917+
856918
<p>The <dfn attribute for=Notification><code>tag</code></dfn> getter steps are to return
857919
<a>this</a>'s <a for=/>notification</a>'s <a for=notification>tag</a>.
858920

@@ -925,6 +987,10 @@ then return null.
925987
<li><p>Set <var>action</var>["{{NotificationAction/title}}"] to <var>entry</var>'s
926988
<a for="notification action">title</a>.
927989

990+
<li><p>If <var>entry</var>'s <a for="notification action">navigation URL</a> is non-null, then
991+
set <var>action</var>["{{NotificationAction/navigate}}"] to <var>entry</var>'s
992+
<a for="notification action">navigation URL</a>, <a lt="URL serializer">serialized</a>.
993+
928994
<li><p>If <var>entry</var>'s <a for="notification action">icon URL</a> is non-null, then set
929995
<var>action</var>["{{NotificationAction/icon}}"] to <var>entry</var>'s
930996
<a for="notification action">icon URL</a>, <a lt="URL serializer">serialized</a>.

0 commit comments

Comments
 (0)