Skip to content

Commit 26605b7

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 37649c3 commit 26605b7

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
@@ -536,14 +552,39 @@ interpreted as a language tag. Validity or well-formedness are not enforced. [[!
536552
platform supports activation, the user agent must (unless otherwise specified) run these steps:
537553

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

542583
<ol>
543-
<li><p>Let <var>action</var> be the empty string.
584+
<li><p>Let <var>actionName</var> be the empty string.
544585

545-
<li><p>If one of <var>notification</var>'s <a for=notification>actions</a> was activated by the
546-
user, then set <var>action</var> to that <a for=/>action</a>'s <a for=action>name</a>.
586+
<li><p>If <var>action</var> is non-null, then set <var>actionName</var> to <var>action</var>'s
587+
<a for=action>name</a>.
547588

548589
<li><a>Fire a service worker notification event</a> named "<code>notificationclick</code>" given
549590
<var>notification</var> and <var>action</var>.
@@ -637,6 +678,7 @@ interface Notification : EventTarget {
637678
readonly attribute NotificationDirection dir;
638679
readonly attribute DOMString lang;
639680
readonly attribute DOMString body;
681+
readonly attribute USVString url;
640682
readonly attribute DOMString tag;
641683
readonly attribute USVString image;
642684
readonly attribute USVString icon;
@@ -656,6 +698,7 @@ dictionary NotificationOptions {
656698
NotificationDirection dir = "auto";
657699
DOMString lang = "";
658700
DOMString body = "";
701+
USVString url;
659702
DOMString tag = "";
660703
USVString image;
661704
USVString icon;
@@ -684,6 +727,7 @@ enum NotificationDirection {
684727
dictionary NotificationAction {
685728
required DOMString action;
686729
required DOMString title;
730+
USVString url;
687731
USVString icon;
688732
};
689733

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

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

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

978+
<li><p>If <var>entry</var>'s <a for=action>URL</a> is non-null, then set
979+
<var>action</var>["{{NotificationAction/url}}"] to <var>entry</var>'s <a for=action>URL</a>,
980+
<a lt="URL serializer">serialized</a>.
981+
924982
<li><p>If <var>entry</var>'s <a for=action>icon URL</a> is non-null, then set
925983
<var>action</var>["{{NotificationAction/icon}}"] to <var>entry</var>'s
926984
<a for=action>icon URL</a>, <a lt="URL serializer">serialized</a>.

0 commit comments

Comments
 (0)