Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate "request permission to use" with user activation #401

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -650,33 +650,52 @@ <h3 id="requesting-more-permission">
</h3>
<p>
To <dfn data-lt="request permission to use|requesting permission to use" class=
"export">request permission to use</dfn> a |descriptor:PermissionDescriptor|, the user
agent must perform the following steps. This algorithm returns either
{{PermissionState/"granted"}} or {{PermissionState/"denied"}}.
"export">request permission to use</dfn> a |descriptor:PermissionDescriptor|, with
optionally a |promise:Promise|:
Comment on lines +653 to +654
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to make call sites easy to read, and I don't think "request permission to use |descriptor| with |promise|" explains to readers what the promise is going to mean. Readers shouldn't need to click through in order to read the call site, which means the call site needs to mention [=transient activation=]. I think something like

Suggested change
"export">request permission to use</dfn> a |descriptor:PermissionDescriptor|, with
optionally a |promise:Promise|:
"export">request permission to use</dfn> a |descriptor:PermissionDescriptor|, optionally
with [=transient activation=] consumed through a |promise:Promise|:

would be somewhat better, although "consumed through" is still obscure, and you might come up with better ideas.

Copy link
Member

@annevk annevk Dec 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case you should define a named parameter: https://infra.spec.whatwg.org/#algorithm-params. (It's not clear to me how a caller would invoke the suggestion. Transient activation is also a property of a Window object.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm... I wonder then if we should define an entirely new algorithm that returns a promise (is not passed one), then see how many specs we can migrate over.

That would allow geolocation (and maybe other specs) to keep working, but provide the right infra for this.

</p>
<ol class="algorithm">
<li>If |promise| was passed:
<ol>
<li>Let |global:Window| be |promise|'s [=relevant global object=].
</li>
<li>Let |document:Document| be |global|'s [=associated `Document`=].
</li>
<li>If |global| does not have [=transient activation=], [=queue a global task=] on
the [=user interaction task source=] given |global| to [=reject=] |promise| with a
"{{NotAllowedError}}" {{DOMException}} and abort these steps.
</li>
<li>Otherwise, [=consume user activation=] of |global|.
Comment on lines +663 to +667
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this really works if "requesting permission to use" is called while in parallel as the transient activation check really has to happen in the main thread.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, true...

</li>
</ol>
</li>
<li>Let <var>current state</var> be the |descriptor|'s <a>permission state</a>.
</li>
<li>If <var>current state</var> is not {{PermissionState/"prompt"}}, return <var>current
state</var> and abort these steps.
</li>
<li>Ask the user for <a>express permission</a> for the calling algorithm to use the
<a>powerful feature</a> described by |descriptor|.
</li>
<li>If the user gives [=express permission=] to use the powerful feature, return
{{PermissionState/"granted"}}; otherwise return {{PermissionState/"denied"}}. The user's
interaction may provide <a>new information about the user's intent</a> for this [=global
object/realm=] and other [=global object/realms=] with the <a>same origin</a>.
<li>Ask the user to choose whether they give [=express permission=] for the [=environment
settings object/origin=] to use the [=powerful feature=] described by |descriptor| for
some [=implementation-defined=] [=permission/lifetime=]. The user's interaction may
provide <a>new information about the user's intent</a> for this [=global object/realm=]
and other [=global object/realms=] with the <a>same origin</a>.
<p class="note">
This is intentionally vague about the details of the permission UI and how the user
agent infers user intent. User agents should be able to explore lots of UI within
this framework.
</p>
</li>
<li>Let |result:PermissionState| be the {{PermissionState}} value that reflects the
choice in the previous step.
</li>
<li>If |promise| was not passed, return |result|.
</li>
<li>Otherwise, [=queue a global task=] on the [=user interaction task source=] with
|promise|'s [=relevant global object=] to [=resolve=] |promise| with |result|.
</li>
</ol>
<p>
As a shorthand, <a>requesting permission to use</a> a {{DOMString}} |name|, is the same
as <a>requesting permission to use</a> a {{PermissionDescriptor}} with its
As a shorthand, <a>requesting permission to use</a> a {{DOMString}} |name| and |promise|,
is the same as <a>requesting permission to use</a> a {{PermissionDescriptor}} with its
Copy link
Member

@miketaylr miketaylr Dec 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give an example of using this shorthand? Looking at https://notifications.spec.whatwg.org/#dom-notification-requestpermission... is it something like requesting permission to use "notifications" with |promise|? If so, s/and/with/?

(And probably {{PermissionDescriptor/name}} member set to |name| with |promise| below?)

{{PermissionDescriptor/name}} member set to |name|.
</p>
</section>
Expand Down