Skip to content

Commit

Permalink
editorial: Simplify the "obtain permission" algorithm.
Browse files Browse the repository at this point in the history
Conceptually, the steps remain the same:
1. Return "granted" or "denied" if the permission state is set to either
   value.
2. Otherwise, return "denied" if there is no user activation.
3. Call the "request permission to use" algorithm from the Permissions spec
   in case there is user activation.

The difference is that we now do it in 4 steps rather than 10 by 1) using
the shorthands provided by the Permissions spec that allow us to use a
PermissionName rather than having to create a PermissionDescriptor in the
algorithms and 2) checking the "permission state" directly rather than
invoking Permissions.query() and manipulating a promise.

Ideally, we would remove this algorithm altogether in favor of the "request
permission to use" algorithm from the Permissions spec, but we need to keep
it in order to check for user activation in case we are in a "prompt"
state (see the discussion in w3c#298).

By not manipulating promises anymore, this incidentally fixes w3c#187.
  • Loading branch information
Raphael Kubo da Costa committed Feb 10, 2021
1 parent 01c2064 commit 0e53a1c
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,33 +217,24 @@ <h2>
these steps <a>in parallel</a>. This async algorithm returns either
{{PermissionState/"granted"}} or {{PermissionState/"denied"}}.
</p>
<aside class="note">
The following algorithm is defined in this specification because the
Permissions specification currently lacks integration with the
concept of user activation from [[HTML]]. See <a href=
"https://github.com/w3c/permissions/issues/194">this issue for more
information</a>.
</aside>
<ol class="algorithm">
<li>Let |permissionDesc:PermissionDescriptor| be a newly created
{{PermissionDescriptor}}.
</li>
<li>Set |permissionDesc|'s {{PermissionDescriptor/name}} member to
"`screen-wake-lock`".
</li>
<li>Let |resultPromise:Promise| be the result of running <a>query a
permission</a> with |permissionDesc|.
</li>
<li>Await |resultPromise| to settle.
</li>
<li>If |resultPromise| rejects, return {{PermissionState/"denied"}}.
</li>
<li>Otherwise, let |status:PermissionStatus| be the result of
|resultPromise|.
</li>
<li>Let |state:PermissionState| be the value of
|status|.{{PermissionStatus/state}}.
<li>Let |state:PermissionState| be <a>permission state</a> of the
`"screen-wake-lock"` {{PermissionName}}.
</li>
<li>If |state| is not {{PermissionState/"prompt"}}, return |state|.
</li>
<li>If the <a>current global object</a> does not have [=transient
activation=], return {{PermissionState/"denied"}}.
</li>
<li>Otherwise, return the result of <a>requesting permission to
use</a> with |permissionDesc|.
use</a> the `"screen-wake-lock"` {{PermissionName}}.
</li>
</ol>
</section>
Expand Down

0 comments on commit 0e53a1c

Please sign in to comment.