Skip to content

Commit

Permalink
Editorial: cleanup requestPermission() algorithm (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoscaceres authored May 8, 2024
1 parent 0791720 commit bde4bc3
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -291,30 +291,28 @@ The <dfn attribute for="DeviceOrientationEvent">gamma</dfn> attribute must retur
The <dfn attribute for="DeviceOrientationEvent">absolute</dfn> attribute must return the value it was initialized to. It indicates whether <a>relative orientation</a> or <a>absolute orientation</a> data is being provided.

<div algorithm>
The <dfn method for="DeviceOrientationEvent">requestPermission(<var>absolute</var>)</dfn> method steps are:
The <dfn method for="DeviceOrientationEvent">requestPermission(|absolute|)</dfn> method steps are:

1. Let <var>global</var> be the <a>current global object</a>.
1. Let <var>hasTransientActivation</var> be true if <a>this</a>'s <a>relevant global object</a> has <a>transient activation</a>, and false otherwise.
1. Let <var>result</var> be <a>a new promise</a> in <a>this</a>'s <a>relevant Realm</a>.
1. Let |global| be the [=current global object=].
1. Let |hasTransientActivation| be true if [=this=]'s [=relevant global object=] has [=transient activation=], and false otherwise.
1. Let |promise| be [=a new promise=] in [=this=]'s [=relevant Realm=].
1. Let |permissions| be « <a permission>"accelerometer"</a>, <a permission>"gyroscope"</a> ».
1. If |absolute| is true, [=set/append=] <a permission>"magnetometer"</a> » to |permissions|.
1. Run these steps <a>in parallel</a>:
1. If <var>absolute</var> is true:
1. Let <var>permissions</var> be « "<a permission>accelerometer</a>", "<a permission>gyroscope</a>", "<a permission>magnetometer</a>" ».
1. Otherwise:
1. Let <var>permissions</var> be « "<a permission>accelerometer</a>", "<a permission>gyroscope</a>" ».
1. <a for="list">For each</a> <var>name</var> of <var>permissions</var>:
1. If <var>name</var>'s <a>permission state</a> is "{{PermissionState/prompt}}" and <var>hasTransientActivation</var> is false:
1. <a>Queue a global task</a> on the <a>device motion and orientation task source</a> given <var>global</var> to <a>reject</a> <var>result</var> with a "{{NotAllowedError}}" {{DOMException}}.
1. [=list/For each=] |name| of |permissions|:
1. If |name|'s [=permission state=] is "{{PermissionState/prompt}}" and |hasTransientActivation| is false:
1. [=Queue a global task=] on the [=device motion and orientation task source=] given |global| to [=reject=] |promise| with a "{{NotAllowedError}}" {{DOMException}}.
1. Return.
1. Let <var>permissionState</var> be "{{PermissionState/granted}}".
1. <a for="list">For each</a> <var>name</var> of <var>permissions</var>:
1. Let |permissionState| be "{{PermissionState/granted}}".
1. [=list/For each=] |name| of |permissions|:

Note: There is no algorithm for requesting multiple permissions at once. However, user agents are encouraged to bundle concurrent requests for different kinds of media into a single user-facing permission prompt.

1. If the result of <a>requesting permission to use</a> <var>name</var> is not "{{PermissionState/granted}}":
1. Set <var>permissionState</var> to "{{PermissionState/denied}}".
1. <a>Break</a>
1. <a>Queue a global task</a> on the <a>device motion and orientation task source</a> given <var>global</var> to <a>resolve</a> <var>result</var> with <var>permissionState</var>.</li>
1. Return <var>result</var>.
1. If the result of <a>requesting permission to use</a> |name| is not "{{PermissionState/granted}}":
1. Set |permissionState| to "{{PermissionState/denied}}".
1. [=Break=].
1. [=Queue a global task=] on the [=device motion and orientation task source=] given |global| to [=resolve=] |promise| with |permissionState|.
1. Return |promise|.

</div>

Expand Down

0 comments on commit bde4bc3

Please sign in to comment.