From d273f04b01bf5bf72cceee9e5f74912258aec01c Mon Sep 17 00:00:00 2001
From: Domenic Denicola
Date: Wed, 24 Feb 2021 13:01:54 -0500
Subject: [PATCH] Clean up task queuing and document management
* Removes uses of "responsible document". This term is on its way out, per https://github.com/whatwg/html/issues/4335.
* The straightforward substitution of using the associated Document didn't always make sense, because in many cases there was no sensible settings object (e.g., the algorithms were consulting the "current settings object" but were in parallel, where there is no current settings object). So, this restructures the algorithms to be more clear about what work is done in parallel vs. what work is done in queued tasks.
* Similarly, a lot of work was done on main-thread data structures and objects while in parallel, e.g. creating WakeLockSentinel objects or consulting internal slots. That was moved to be done either up front, before the algorithms go in parallel, or in queued tasks. This includes user activation checking, which allows us to eliminate the wrapper "obtain permission" algorithm.
---
index.html | 157 ++++++++++++++++++++++-------------------------------
1 file changed, 66 insertions(+), 91 deletions(-)
diff --git a/index.html b/index.html
index 54d1b09..7320ccb 100644
--- a/index.html
+++ b/index.html
@@ -203,8 +203,8 @@
Wake Lock permission revocation algorithm, run these steps:
-
Let |document:Document| be the [=environment settings object /
- responsible document=] of the current settings object.
+
Let |document:Document| the [=current settings object=]'s
+ [=associated Document=].
- To obtain permission for wake lock type |name|, run
- these steps in parallel. This async algorithm returns either
- {{PermissionState/"granted"}} or {{PermissionState/"denied"}}.
-
-
-
-
Let |state:PermissionState| be permission state of the
- `"screen-wake-lock"` {{PermissionName}}.
-
-
If |state| is not {{PermissionState/"prompt"}}, return |state|.
-
-
If the current global object does not have [=transient
- activation=], return {{PermissionState/"denied"}}.
-
A list of {{WakeLockSentinel}} objects, representing
- active wake locks associated with the [=environment settings
- object / responsible document=].
+ active wake locks associated with the {{Document}}.
@@ -337,8 +310,8 @@
|type:WakeLockType|:
-
Let |document:Document| be the [=environment settings object /
- responsible document=] of the current settings object.
+
Let |document:Document| the [=current settings object=]'s
+ [=associated Document=].
Let |state:PermissionState| be the result of awaiting
- obtain permission steps with "`screen-wake-lock`":
+
Let |state:PermissionState| be the result of requesting
+ permission to use the `"screen-wake-lock"`
+ {{PermissionName}}.
+
+
If |state| is
+ {{PermissionState/"denied"}}, then:
-
If
- |state| is {{PermissionState/"denied"}}, then reject
- |promise| with a {{"NotAllowedError"}} {{DOMException}}, and
- abort these steps.
+
[=Queue a global task=] on the [=screen wake lock task
+ source=] given |document|'s [=relevant global object=] to
+ [=reject=] |promise| with a {{"NotAllowedError"}}
+ {{DOMException}}.
+
+
Abort these steps.
-
Let |lock:WakeLockSentinel| be a new {{WakeLockSentinel}}
- object with its {{WakeLockSentinel/type}} attribute set to
- |type|.
-
Run release a wake lock with |lock:WakeLockSentinel|
- set to this and |type:WakeLockType| set to the value of
- this' {{WakeLockSentinel/type}} attribute.
-
-
Resolve |promise|.
-
-
+
Run release a wake lock given the [=current global
+ object=]'s [=associated Document=], [=this=], and |promise|.
Return |promise|.
@@ -640,14 +612,10 @@
Handling document loss of full activity
- When the user agent determines that a [=environment settings object /
- responsible document=] of the current settings object is no
- longer [=Document/fully active=], it must run these steps:
+ When a {{Document}} |document:Document| becomes no longer
+ [=Document/fully active=], the user agent must run these steps:
-
Let |document:Document| be the [=environment settings object /
- responsible document=] of the current settings object.
-
- To acquire a wake lock for a given |lock:WakeLockSentinel|
- and |type:WakeLockType|, run these steps in parallel:
+ To acquire a wake lock given a |document:Document|, a
+ |type:WakeLockType|, and a |promise:Promise|:
If the wake lock for type |type| is not applicable, abort
@@ -719,13 +682,22 @@
Let |lock:WakeLockSentinel| be a new {{WakeLockSentinel}}
+ object with its {{WakeLockSentinel/type}} attribute set to
+ |type|.
+
+
Add |lock| to |record|.{{[[ActiveLocks]]}}.
+
+
[=Resolve=] |promise| with |lock|.
+
+
@@ -734,12 +706,12 @@
Release wake lock algorithm
- To release a wake lock for a given |lock:WakeLockSentinel|
- and |type:WakeLockType|, run these steps in parallel:
+ To release a wake lock given a |document:Document|, a
+ |lock:WakeLockSentinel|, and an optional |promise:Promise|:
-
Let |document:Document| be the [=environment settings object /
- responsible document=] of the current settings object.
+
Let |type:WakeLockType| be the value of |lock|'s
+ {{WakeLockSentinel/type}} attribute.