From 5f0548b07b105618c7dfd8f55f576cc6c7c377aa Mon Sep 17 00:00:00 2001 From: Marcos Caceres Date: Fri, 25 Nov 2022 16:53:24 +1300 Subject: [PATCH] Integrate "request permission to use" with user activation Allows "request permission to use" to accept an optional promise. The promise gets rejected if the page doesn't have transient activation. Also, when the promise is passed, the algorithm now consumes the user activation. If passed, the promise is resolved with the user's choice. --- index.html | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/index.html b/index.html index 79a7308..9fdbf33 100644 --- a/index.html +++ b/index.html @@ -650,33 +650,52 @@

To request permission to use 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 a |descriptor:PermissionDescriptor|, with + optionally a |promise:Promise|:

    +
  1. If |promise| was passed: +
      +
    1. Let |global:Window| be |promise|'s [=relevant global object=]. +
    2. +
    3. Let |document:Document| be |global|'s [=associated `Document`=]. +
    4. +
    5. 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. +
    6. +
    7. Otherwise, [=consume user activation=] of |global|. +
    8. +
    +
  2. Let current state be the |descriptor|'s permission state.
  3. If current state is not {{PermissionState/"prompt"}}, return current state and abort these steps.
  4. -
  5. Ask the user for express permission for the calling algorithm to use the - powerful feature described by |descriptor|. -
  6. -
  7. If the user gives [=express permission=] to use the powerful feature, return - {{PermissionState/"granted"}}; otherwise return {{PermissionState/"denied"}}. The user's - interaction may provide new information about the user's intent for this [=global - object/realm=] and other [=global object/realms=] with the same origin. +
  8. 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 new information about the user's intent for this [=global object/realm=] + and other [=global object/realms=] with the same origin.

    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.

  9. +
  10. Let |result:PermissionState| be the {{PermissionState}} value that reflects the + choice in the previous step. +
  11. +
  12. If |promise| was not passed, return |result|. +
  13. +
  14. Otherwise, [=queue a global task=] on the [=user interaction task source=] with + |promise|'s [=relevant global object=] to [=resolve=] |promise| with |result|. +

- As a shorthand, requesting permission to use a {{DOMString}} |name|, is the same - as requesting permission to use a {{PermissionDescriptor}} with its + As a shorthand, requesting permission to use a {{DOMString}} |name| and |promise|, + is the same as requesting permission to use a {{PermissionDescriptor}} with its {{PermissionDescriptor/name}} member set to |name|.