Skip to content

Commit 01e8216

Browse files
miketaylrannevk
andauthored
Restrict the Notifications API to secure contexts
This also further improves the integration with Permissions, delegating most of the secure context logic to that specification. Tests: web-platform-tests/wpt#31495. Fixes #93. Co-authored-by: Anne van Kesteren <[email protected]>
1 parent df1b6db commit 01e8216

File tree

1 file changed

+17
-50
lines changed

1 file changed

+17
-50
lines changed

notifications.bs

Lines changed: 17 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -291,40 +291,21 @@ removed from the <a>list of notifications</a>.
291291
"notification center" (if available).
292292

293293

294-
<h3 id=permission-model>Permission model</h3>
295-
296-
<p><a>Notifications</a> can only be displayed if the
297-
user (or user agent on behalf of the user) has granted <dfn>permission</dfn>.
298-
The <a>permission</a> to show <a>notifications</a>
299-
for a given <a for=/>origin</a> is one of three strings:
300-
301-
<dl>
302-
<dt>"<code>default</code>"
303-
<dd><p>This is equivalent to "<code>denied</code>", but the user has made no
304-
explicit choice thus far.
305-
306-
<dt>"<code>denied</code>"
307-
<dd><p>This means the user does not want
308-
<a>notifications</a>.
294+
<h3 id="permissions-integration">Permissions integration</h3>
309295

310-
<dt>"<code>granted</code>"
311-
<dd><p>This means <a>notifications</a> can be
312-
displayed.
313-
</dl>
296+
<p>The Notifications API is a <a>powerful feature</a> which is identified by the
297+
<a for="powerful feature">name</a> "{{PermissionName/notifications}}". [[!Permissions]]
314298

315-
<p class=note>There is no equivalent to "<code>default</code>"
316-
meaning "<code>granted</code>". In that case
317-
"<code>granted</code>" is simply returned as there would be no reason
318-
for the application to ask for <a>permission</a>.
299+
<p>To <dfn>get the notifications permission state</dfn>, run these steps:
319300

320-
<h3 id="permissions-integration">Permissions integration</h3>
301+
<ol>
302+
<li><p>Let <var>permissionState</var> be the result of <a>getting the current permission state</a>
303+
with "{{PermissionName/notifications}}".
321304

322-
<p>The Notifications API is a <a>powerful feature</a> which is identified by the string
323-
"notifications" and has its <a for="powerful feature">allowed in non-secure contexts</a> flag set.
324-
[[!Permissions]]
305+
<li><p>If <var>permissionState</var> is "<code>prompt</code>", then return "<code>default</code>".
325306

326-
<p class="note">This specification's "<code>default</code>" <a>permission</a>
327-
state maps to the [=permission/prompt=] permission state in the Permissions API.
307+
<li><p>Return <var>permissionState</var>.
308+
</ol>
328309

329310

330311
<h3 id=direction>Direction</h3>
@@ -721,9 +702,9 @@ constructor steps are:
721702
<p>Run these steps <a>in parallel</a>:
722703

723704
<ol>
724-
<li><p>If <a>permission</a> for <var>notification</var>'s <a for=notification>origin</a> is not
725-
"<code>granted</code>", then <a>queue a task</a> to <a>fire an event</a> named <code>error</code>
726-
on <a>this</a>, and abort these steps.
705+
<li><p>If the result of <a>getting the notifications permission state</a> is not
706+
"<code>granted</code>", then <a>queue a task</a> to <a>fire an event</a> named
707+
<code>error</code> on <a>this</a>, and abort these steps.
727708

728709
<li><p>Run the <a>fetch steps</a> for <var>notification</var>.
729710

@@ -735,8 +716,7 @@ constructor steps are:
735716
<h3 id=static-members>Static members</h3>
736717

737718
<p>The static <dfn attribute for=Notification><code>permission</code></dfn> getter steps are to
738-
return the <a>permission</a> for the <a>current settings object</a>'s
739-
<a for="environment settings object">origin</a>.
719+
return the result of <a>getting the notifications permission state</a>.
740720

741721
<div class=note>
742722
<p>If you edit standards please refrain from copying the above. Synchronous permissions are like
@@ -760,27 +740,14 @@ method steps are:
760740
<ol>
761741
<li><p>Let <var>global</var> be the <a>current global object</a>.
762742

763-
<li><p>Let <var>permissionDescriptor</var> be the {{PermissionDescriptor}} with
764-
{{PermissionDescriptor/name}} set to "<code>notifications</code>".
765-
766-
<li><p>Let <var>permissionStatus</var> be the result of
767-
<a lt="create a PermissionStatus">creating a `PermissionStatus`</a> for
768-
<var>permissionDescriptor</var>.
769-
770743
<li><p>Let <var>promise</var> be <a for=/>a new promise</a> in <a>this</a>'s <a>relevant Realm</a>.
771744

772745
<li>
773746
<p>Run these steps <a>in parallel</a>:
774747

775748
<ol>
776-
<li><p>Run the <a for="powerful feature">permission query algorithm</a> with
777-
<var>permissionDescriptor</var> and <var>permissionStatus</var>.
778-
779-
<li><p>Let <var>permissionState</var> be <var>permissionStatus</var>'s
780-
{{PermissionStatus/state}}.
781-
782-
<li><p>If <var>permissionState</var> is {{PermissionState/"prompt"}}, then set
783-
<var>permissionState</var> to "<code>default</code>".
749+
<li><p>Let <var>permissionState</var> be the result of
750+
<a>requesting permission to use</a> "{{PermissionName/notifications}}".
784751

785752
<li>
786753
<p><a>Queue a global task</a> on the <a>DOM manipulation task source</a> given <var>global</var>
@@ -1083,7 +1050,7 @@ method steps are:
10831050
<p>Run these steps <a>in parallel</a>:
10841051

10851052
<ol>
1086-
<li><p>If <a>permission</a> for <var>notification</var>'s <a for=notification>origin</a> is not
1053+
<li><p>If the result of <a>getting the notifications permission state</a> is not
10871054
"<code>granted</code>", then <a>queue a global task</a> on the
10881055
<a>DOM manipulation task source</a> given <var>global</var> to <a for=/>reject</a>
10891056
<var>promise</var> with a {{TypeError}}, and abort these steps.

0 commit comments

Comments
 (0)