Skip to content

Commit 7942ccc

Browse files
authored
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 da830b4 commit 7942ccc

File tree

1 file changed

+74
-4
lines changed

1 file changed

+74
-4
lines changed

notifications.bs

Lines changed: 74 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,53 @@ 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=/>notification 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 a <a for=/>notification 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>
581+
<p>Select one of the following two options in an <a>implementation-defined</a> manner:
582+
583+
<ul>
584+
<li><p><a for=/>Navigate</a> an existing <a for=/>top-level traversable</a> within the user
585+
agent's <a for="user agent">top-level traversable set</a> to <var>navigationURL</var>.
586+
<!-- Should maybe set userInvolvement to "browser UI" here and below. -->
587+
588+
<li><p><a>Create a fresh top-level traversable</a> given <var>navigationURL</var>.
589+
</ul>
590+
591+
<p class=note>User agents are strongly encouraged to match platform conventions.
592+
593+
<li><p>Return.
594+
</ol>
595+
544596
<li>
545597
<p>If <var>notification</var> is a <a>persistent notification</a>, then:
546598

547599
<ol>
548-
<li><p>Let <var>action</var> be the empty string.
600+
<li><p>Let <var>actionName</var> be the empty string.
549601

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
602+
<li><p>If <var>action</var> is non-null, then set <var>actionName</var> to <var>action</var>'s
552603
<a for="notification action">name</a>.
553604

554605
<li><a>Fire a service worker notification event</a> named "<code>notificationclick</code>" given
555-
<var>notification</var> and <var>action</var>.
606+
<var>notification</var> and <var>actionName</var>.
556607
</ol>
557608

558609
<li>
@@ -643,6 +694,7 @@ interface Notification : EventTarget {
643694
readonly attribute NotificationDirection dir;
644695
readonly attribute DOMString lang;
645696
readonly attribute DOMString body;
697+
readonly attribute USVString navigate;
646698
readonly attribute DOMString tag;
647699
readonly attribute USVString image;
648700
readonly attribute USVString icon;
@@ -662,6 +714,7 @@ dictionary NotificationOptions {
662714
NotificationDirection dir = "auto";
663715
DOMString lang = "";
664716
DOMString body = "";
717+
USVString navigate;
665718
DOMString tag = "";
666719
USVString image;
667720
USVString icon;
@@ -690,6 +743,7 @@ enum NotificationDirection {
690743
dictionary NotificationAction {
691744
required DOMString action;
692745
required DOMString title;
746+
USVString navigate;
693747
USVString icon;
694748
};
695749

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

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

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

992+
<li><p>If <var>entry</var>'s <a for="notification action">navigation URL</a> is non-null, then
993+
set <var>action</var>["{{NotificationAction/navigate}}"] to <var>entry</var>'s
994+
<a for="notification action">navigation URL</a>, <a lt="URL serializer">serialized</a>.
995+
928996
<li><p>If <var>entry</var>'s <a for="notification action">icon URL</a> is non-null, then set
929997
<var>action</var>["{{NotificationAction/icon}}"] to <var>entry</var>'s
930998
<a for="notification action">icon URL</a>, <a lt="URL serializer">serialized</a>.
@@ -1211,6 +1279,7 @@ Alex Russell,
12111279
Anssi Kostiainen,
12121280
Arkadiusz Michalski,
12131281
Boris Zbarsky,
1282+
Brady Eidson,
12141283
David Håsäther,
12151284
Doug Turner,
12161285
Drew Wilson,
@@ -1222,6 +1291,7 @@ James Graham,
12221291
John Mellor,
12231292
Jon Lee,
12241293
Jonas Sicking,
1294+
Kagami Sascha Rosylight<!-- saschanaz; GitHub -->,
12251295
Michael Cooper,
12261296
Michael Henretty,
12271297
Michael™ Smith,

0 commit comments

Comments
 (0)