Skip to content

Commit df1b6db

Browse files
authored
Integrate with Permissions
Fixes #71.
1 parent e0cadb2 commit df1b6db

File tree

1 file changed

+40
-15
lines changed

1 file changed

+40
-15
lines changed

notifications.bs

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,15 @@ meaning "<code>granted</code>". In that case
317317
"<code>granted</code>" is simply returned as there would be no reason
318318
for the application to ask for <a>permission</a>.
319319

320+
<h3 id="permissions-integration">Permissions integration</h3>
321+
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]]
325+
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.
328+
320329

321330
<h3 id=direction>Direction</h3>
322331

@@ -729,8 +738,20 @@ constructor steps are:
729738
return the <a>permission</a> for the <a>current settings object</a>'s
730739
<a for="environment settings object">origin</a>.
731740

732-
<p class=note>If you edit standards please refrain from copying the above. Synchronous
733-
permissions are like synchronous IO, a bad idea.
741+
<div class=note>
742+
<p>If you edit standards please refrain from copying the above. Synchronous permissions are like
743+
synchronous IO, a bad idea.
744+
745+
<p>Developers are encouraged to use the Permissions {{Permissions/query()}} method
746+
instead. [[Permissions]]
747+
748+
<pre class="example" id="permissions-query-example">
749+
const permission = await navigator.permissions.query({name: "notifications"});
750+
if (permission.state === "granted") {
751+
// We have permission to use the API…
752+
}
753+
</pre>
754+
</div>
734755

735756
<p>The static
736757
<dfn method for=Notification><code>requestPermission(<var>deprecatedCallback</var>)</code></dfn>
@@ -739,35 +760,38 @@ method steps are:
739760
<ol>
740761
<li><p>Let <var>global</var> be the <a>current global object</a>.
741762

742-
<li><p>Let <var>origin</var> be the <a>current settings object</a>'s
743-
<a for="environment settings object">origin</a>.
744-
<!-- Arguably this should snapshot origin somehow so that changes to it do not impact the
745-
in parallel part. -->
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>.
746769

747770
<li><p>Let <var>promise</var> be <a for=/>a new promise</a> in <a>this</a>'s <a>relevant Realm</a>.
748771

749772
<li>
750773
<p>Run these steps <a>in parallel</a>:
751774

752775
<ol>
753-
<li><p>Let <var>permission</var> be <a>permission</a> for <var>origin</var>.
776+
<li><p>Run the <a for="powerful feature">permission query algorithm</a> with
777+
<var>permissionDescriptor</var> and <var>permissionStatus</var>.
754778

755-
<li><p>If <var>permission</var> is "<code>default</code>", then ask the user whether showing
756-
notifications for <var>origin</var> is acceptable. If it is, then set <var>permission</var> to
757-
"<code>granted</code>"; otherwise "<code>denied</code>".
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>".
758784

759785
<li>
760786
<p><a>Queue a global task</a> on the <a>DOM manipulation task source</a> given <var>global</var>
761787
to run these steps:
762788

763789
<ol>
764-
<li><p>Set <a>permission</a> for <var>origin</var> to <var>permission</var>.
765-
766790
<li><p>If <var>deprecatedCallback</var> is given, then <a for=/>invoke</a>
767-
<var>deprecatedCallback</var> with « <var>permission</var> ». If this throws an exception, then
768-
<a>report the exception</a>.
791+
<var>deprecatedCallback</var> with « <var>permissionState</var> ». If this throws an
792+
exception, then <a>report the exception</a>.
769793

770-
<li><p><a for=/>Resolve</a> <var>promise</var> with <var>permission</var>.
794+
<li><p><a for=/>Resolve</a> <var>promise</var> with <var>permissionState</var>.
771795
</ol>
772796
</ol>
773797

@@ -1186,6 +1210,7 @@ Michael Cooper,
11861210
Michael Henretty,
11871211
Michael™ Smith,
11881212
Michael van Ouwerkerk,
1213+
Mike Taylor,
11891214
Nicolás Satragno,
11901215
Olli Pettay,
11911216
Peter Beverloo,

0 commit comments

Comments
 (0)