Skip to content

Commit 6dd8319

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 7b0aee1 commit 6dd8319

File tree

1 file changed

+61
-3
lines changed

1 file changed

+61
-3
lines changed

notifications.bs

Lines changed: 61 additions & 3 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 for=notification>URL</dfn> (null or a
64+
<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
@@ -136,6 +139,9 @@ for an end user. Each <a for=/>action</a> has an associated:
136139
<dt><dfn for=action id=action-title>title</dfn>
137140
<dd>A string.
138141

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

@@ -219,6 +225,11 @@ clipped corners.
219225
<li><p>Set <var>notification</var>'s <a for=notification>body</a> to
220226
<var>options</var>["{{NotificationOptions/body}}"].
221227

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

@@ -269,6 +280,11 @@ clipped corners.
269280
<li><p>Set <var>action</var>'s <a for=action>title</a> to
270281
<var>entry</var>["{{NotificationAction/title}}"].
271282

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

541557
<ol>
558+
<li><p>Let <var>action</var> be null.
559+
560+
<li><p>If one of <var>notification</var>'s <a for=notification>actions</a> was activated by the end
561+
user, then set <var>action</var> to that <a for=/>action</a>.
562+
563+
<li><p>Let <var>url</var> be <var>notification</var>'s <a for=notification>URL</a>.
564+
565+
<li>
566+
<p>If <var>action</var> is non-null, then set <var>url</var> to <var>action</var>'s
567+
<a for=action>URL</a>.
568+
569+
<p class=note>This intentionally makes it so that when an <a for=/>action</a>'s
570+
<a for=action>URL</a> is null, it falls through to the <code>click</code> event, providing more
571+
flexibility to the web developer.
572+
573+
<li>
574+
<p>If <var>url</var> is non-null:
575+
576+
<ol>
577+
<li><p><a>Create a fresh top-level traversable</a> given <var>url</var>.
578+
<!-- Should maybe set userInvolvement correctly here, even though it doesn't do anything today. -->
579+
580+
<li><p>Return.
581+
</ol>
582+
542583
<li>
543584
<p>If <var>notification</var> is a <a>persistent notification</a>, then:
544585

545586
<ol>
546-
<li><p>Let <var>action</var> be the empty string.
587+
<li><p>Let <var>actionName</var> be the empty string.
547588

548-
<li><p>If one of <var>notification</var>'s <a for=notification>actions</a> was activated by the
549-
user, then set <var>action</var> to that <a for=/>action</a>'s <a for=action>name</a>.
589+
<li><p>If <var>action</var> is non-null, then set <var>actionName</var> to <var>action</var>'s
590+
<a for=action>name</a>.
550591

551592
<li><a>Fire a service worker notification event</a> named "<code>notificationclick</code>" given
552593
<var>notification</var> and <var>action</var>.
@@ -640,6 +681,7 @@ interface Notification : EventTarget {
640681
readonly attribute NotificationDirection dir;
641682
readonly attribute DOMString lang;
642683
readonly attribute DOMString body;
684+
readonly attribute USVString url;
643685
readonly attribute DOMString tag;
644686
readonly attribute USVString image;
645687
readonly attribute USVString icon;
@@ -659,6 +701,7 @@ dictionary NotificationOptions {
659701
NotificationDirection dir = "auto";
660702
DOMString lang = "";
661703
DOMString body = "";
704+
USVString url;
662705
DOMString tag = "";
663706
USVString image;
664707
USVString icon;
@@ -687,6 +730,7 @@ enum NotificationDirection {
687730
dictionary NotificationAction {
688731
required DOMString action;
689732
required DOMString title;
733+
USVString url;
690734
USVString icon;
691735
};
692736

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

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+
853907
<p>The <dfn attribute for=Notification><code>tag</code></dfn> getter steps are to return
854908
<a>this</a>'s <a for=/>notification</a>'s <a for=notification>tag</a>.
855909

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

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+
925983
<li><p>If <var>entry</var>'s <a for=action>icon URL</a> is non-null, then set
926984
<var>action</var>["{{NotificationAction/icon}}"] to <var>entry</var>'s
927985
<a for=action>icon URL</a>, <a lt="URL serializer">serialized</a>.

0 commit comments

Comments
 (0)