Skip to content

Commit

Permalink
Allow notifications and actions to specify a navigable URL
Browse files Browse the repository at this point in the history
This makes notifications more declarative by not requiring explicit handling of the clicks by the web application.
  • Loading branch information
annevk committed Jul 17, 2024
1 parent 221c867 commit 1f0a264
Showing 1 changed file with 61 additions and 3 deletions.
64 changes: 61 additions & 3 deletions notifications.bs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ representing either a valid BCP 47 language tag or the empty string.
<p>A <a>notification</a> has an associated <dfn for=notification id=body>body</dfn> which is a
string.

<p>A <a>notification</a> has an associated <dfn for=notification>URL</dfn> which is null or a
<a for=/>URL</a>. It is initially null.

<p>A <a>notification</a> has an associated
<dfn for=notification id=tag>tag</dfn> which is a string.

Expand Down Expand Up @@ -135,6 +138,9 @@ for an end user. Each <a for=/>action</a> has an associated:
<dt><dfn for=action id=action-title>title</dfn>
<dd>A string.

<dt><dfn for=action>URL</dfn>
<dd>Null or a <a for=/>URL</a>. It is initially null.

<dt><dfn for=action>icon URL</dfn>
<dd>Null or a <a for=/>URL</a>. It is initially null.

Expand Down Expand Up @@ -211,6 +217,11 @@ string <var>title</var>, {{NotificationOptions}} <a for=/>dictionary</a> <var>op
<li><p>Set <var>notification</var>'s <a for=notification>body</a> to
<var>options</var>["{{NotificationOptions/body}}"].

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

<li><p>Set <var>notification</var>'s <a for=notification>tag</a> to
<var>options</var>["{{NotificationOptions/tag}}"].

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

<li><p>If <var>entry</var>["{{NotificationAction/url}}"] <a for=map>exists</a>, then
<a lt="URL parser">parse</a> it using <var>baseURL</var>, and if that does not return failure,
set <var>action</var>'s <a for=action>URL</a> to the return value. (Otherwise <var>action</var>'s
<a for=action>URL</a> remains null.)

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

<ol>
<li><p>Let <var>action</var> be null.

<li><p>If one of <var>notification</var>'s <a for=notification>actions</a> was activated by the end
user, then set <var>action</var> to that <a for=/>action</a>.

<li><p>Let <var>url</var> be <var>notification</var>'s <a for=notification>URL</a>.

<li>
<p>If <var>action</var> is non-null, then set <var>url</var> to <var>action</var>'s
<a for=action>URL</a>.

<p class=note>This intentionally makes it so that when an <a for=/>action</a>'s
<a for=action>URL</a> is null, it falls through to the <code>click</code> event, providing more
flexibility to the web developer.

<li>
<p>If <var>url</var> is non-null:

<ol>
<li><p><a>Create a fresh top-level traversable</a> given <var>url</var>.
<!-- Should maybe set userInvolvement correctly here, even though it doesn't do anything today. -->

<li><p>Return.
</ol>

<li>
<p>If <var>notification</var> is a <a>persistent notification</a>, then:

<ol>
<li><p>Let <var>action</var> be the empty string.
<li><p>Let <var>actionName</var> be the empty string.

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

<li><a>Fire a service worker notification event</a> named "<code>notificationclick</code>" given
<var>notification</var> and <var>action</var>.
Expand Down Expand Up @@ -620,6 +661,7 @@ interface Notification : EventTarget {
readonly attribute NotificationDirection dir;
readonly attribute DOMString lang;
readonly attribute DOMString body;
readonly attribute USVString url;
readonly attribute DOMString tag;
readonly attribute USVString image;
readonly attribute USVString icon;
Expand All @@ -639,6 +681,7 @@ dictionary NotificationOptions {
NotificationDirection dir = "auto";
DOMString lang = "";
DOMString body = "";
USVString url;
DOMString tag = "";
USVString image;
USVString icon;
Expand Down Expand Up @@ -667,6 +710,7 @@ enum NotificationDirection {
dictionary NotificationAction {
required DOMString action;
required DOMString title;
USVString url;
USVString icon;
};

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

<p>The <dfn attribute for=Notification><code>url</code></dfn> getter steps are:

<ol>
<li><p>If <a>this</a>'s <a>notification</a>'s <a for=notification>URL</a> is null, then return the
empty string.

<li><p>Return <a>this</a>'s <a>notification</a>'s <a for=notification>URL</a>,
<a lt="URL serializer">serialized</a>.
</ol>

<p>The <dfn attribute for=Notification><code>tag</code></dfn> getter steps are to return
<a>this</a>'s <a>notification</a>'s <a for=notification>tag</a>.

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

<li><p>If <var>entry</var>'s <a for=action>URL</a> is non-null, then set
<var>action</var>["{{NotificationAction/url}}"] to <var>entry</var>'s <a for=action>URL</a>,
<a lt="URL serializer">serialized</a>.

<li><p>If <var>entry</var>'s <a for=action>icon URL</a> is non-null, then set
<var>action</var>["{{NotificationAction/icon}}"] to <var>entry</var>'s
<a for=action>icon URL</a>, <a lt="URL serializer">serialized</a>.
Expand Down

0 comments on commit 1f0a264

Please sign in to comment.