Skip to content

Commit 1f0a264

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 221c867 commit 1f0a264

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
@@ -59,6 +59,9 @@ representing either a valid BCP 47 language tag or the empty string.
5959
<p>A <a>notification</a> has an associated <dfn for=notification id=body>body</dfn> which is a
6060
string.
6161

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

@@ -135,6 +138,9 @@ for an end user. Each <a for=/>action</a> has an associated:
135138
<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,11 @@ 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><p>If <var>options</var>["{{NotificationOptions/url}}"] <a for=map>exists</a>, then
221+
<a lt="URL parser">parse</a> it using <var>baseURL</var>, and if that does not return failure, set
222+
<var>notification</var>'s <a for=notification>URL</a> to the return value. (Otherwise
223+
<var>notification</var>'s <a for=notification>URL</a> remains null.)
224+
214225
<li><p>Set <var>notification</var>'s <a for=notification>tag</a> to
215226
<var>options</var>["{{NotificationOptions/tag}}"].
216227

@@ -266,6 +277,11 @@ string <var>title</var>, {{NotificationOptions}} <a for=/>dictionary</a> <var>op
266277
<li><p>Set <var>action</var>'s <a for=action>title</a> to
267278
<var>entry</var>["{{NotificationAction/title}}"].
268279

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

529545
<ol>
546+
<li><p>Let <var>action</var> be null.
547+
548+
<li><p>If one of <var>notification</var>'s <a for=notification>actions</a> was activated by the end
549+
user, then set <var>action</var> to that <a for=/>action</a>.
550+
551+
<li><p>Let <var>url</var> be <var>notification</var>'s <a for=notification>URL</a>.
552+
553+
<li>
554+
<p>If <var>action</var> is non-null, then set <var>url</var> to <var>action</var>'s
555+
<a for=action>URL</a>.
556+
557+
<p class=note>This intentionally makes it so that when an <a for=/>action</a>'s
558+
<a for=action>URL</a> is null, it falls through to the <code>click</code> event, providing more
559+
flexibility to the web developer.
560+
561+
<li>
562+
<p>If <var>url</var> is non-null:
563+
564+
<ol>
565+
<li><p><a>Create a fresh top-level traversable</a> given <var>url</var>.
566+
<!-- Should maybe set userInvolvement correctly here, even though it doesn't do anything today. -->
567+
568+
<li><p>Return.
569+
</ol>
570+
530571
<li>
531572
<p>If <var>notification</var> is a <a>persistent notification</a>, then:
532573

533574
<ol>
534-
<li><p>Let <var>action</var> be the empty string.
575+
<li><p>Let <var>actionName</var> be the empty string.
535576

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>.
577+
<li><p>If <var>action</var> is non-null, then set <var>actionName</var> to <var>action</var>'s
578+
<a for=action>name</a>.
538579

539580
<li><a>Fire a service worker notification event</a> named "<code>notificationclick</code>" given
540581
<var>notification</var> and <var>action</var>.
@@ -620,6 +661,7 @@ interface Notification : EventTarget {
620661
readonly attribute NotificationDirection dir;
621662
readonly attribute DOMString lang;
622663
readonly attribute DOMString body;
664+
readonly attribute USVString url;
623665
readonly attribute DOMString tag;
624666
readonly attribute USVString image;
625667
readonly attribute USVString icon;
@@ -639,6 +681,7 @@ dictionary NotificationOptions {
639681
NotificationDirection dir = "auto";
640682
DOMString lang = "";
641683
DOMString body = "";
684+
USVString url;
642685
DOMString tag = "";
643686
USVString image;
644687
USVString icon;
@@ -667,6 +710,7 @@ enum NotificationDirection {
667710
dictionary NotificationAction {
668711
required DOMString action;
669712
required DOMString title;
713+
USVString url;
670714
USVString icon;
671715
};
672716

@@ -820,6 +864,16 @@ return the <a>maximum number of actions</a> supported.
820864
<p>The <dfn attribute for=Notification><code>body</code></dfn> getter steps are to return
821865
<a>this</a>'s <a>notification</a>'s <a for=notification>body</a>.
822866

867+
<p>The <dfn attribute for=Notification><code>url</code></dfn> getter steps are:
868+
869+
<ol>
870+
<li><p>If <a>this</a>'s <a>notification</a>'s <a for=notification>URL</a> is null, then return the
871+
empty string.
872+
873+
<li><p>Return <a>this</a>'s <a>notification</a>'s <a for=notification>URL</a>,
874+
<a lt="URL serializer">serialized</a>.
875+
</ol>
876+
823877
<p>The <dfn attribute for=Notification><code>tag</code></dfn> getter steps are to return
824878
<a>this</a>'s <a>notification</a>'s <a for=notification>tag</a>.
825879

@@ -892,6 +946,10 @@ then return null.
892946
<li><p>Set <var>action</var>["{{NotificationAction/title}}"] to <var>entry</var>'s
893947
<a for=action>title</a>.
894948

949+
<li><p>If <var>entry</var>'s <a for=action>URL</a> is non-null, then set
950+
<var>action</var>["{{NotificationAction/url}}"] to <var>entry</var>'s <a for=action>URL</a>,
951+
<a lt="URL serializer">serialized</a>.
952+
895953
<li><p>If <var>entry</var>'s <a for=action>icon URL</a> is non-null, then set
896954
<var>action</var>["{{NotificationAction/icon}}"] to <var>entry</var>'s
897955
<a for=action>icon URL</a>, <a lt="URL serializer">serialized</a>.

0 commit comments

Comments
 (0)