Skip to content

Commit

Permalink
editorial: Improve references to terms from the Page Visibility spec. (
Browse files Browse the repository at this point in the history
…w3c#306)

* @annevk says in w3c#299 that, as a general rule, invoking IDL members from
  algorithms, like we were doing with `document.hidden`, is not recommended.
  Instead, invoke the "determine the visibility state" steps defined in the
  Page Visibility spec directly.

* Clean up the "Dependencies" section; for now we only need one term that is
  not exported by the latest Page Visibility TR (this is fixed in the ED):
  the "now hidden algorithm". The steps described in the "Handling document
  loss of visibility" steps now explicitly run after that algorithm, which
  runs when the top-level browsing context's Document becomes hidden.

More generally, these changes should also make it more clear that the
visibility state checks only apply to the top-level browsing
context (according to the Page Visibility spec itself). Although we were
previously checking if a given `Document` was `hidden` even if it did not
belong to a top-level browsing context, that was simply invalid.
  • Loading branch information
Raphael Kubo da Costa authored Feb 24, 2021
1 parent 895be5a commit 54f520c
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
xref: {
profile: "web-platform",
specs: [
"page-visibility",
"permissions",
"permissions-policy",
]
Expand Down Expand Up @@ -361,16 +362,18 @@ <h3>
|document| is not [=Document/fully active=], return [=a promise
rejected with=] with a {{"NotAllowedError"}} {{DOMException}}.
</li>
<li data-tests="wakelock-document-hidden-manual.https.html">If
|document| is <a>hidden</a>, return [=a promise rejected with=]
{{"NotAllowedError"}} {{DOMException}}.
<li data-tests="wakelock-document-hidden-manual.https.html">If the
steps to <a>determine the visibility state</a> return `hidden`,
return [=a promise rejected with=] {{"NotAllowedError"}}
{{DOMException}}.
</li>
<li>Let |promise:Promise| be [=a new promise=].
</li>
<li>Return |promise| and run the following steps <a>in parallel</a>:
<ol>
<li>
<a>Abort when</a> |document| is <a>hidden</a>.
<a>Abort when</a> the steps to <a>determine the visibility
state</a> return `hidden`.
</li>
<li>Let |state:PermissionState| be the result of awaiting
<a>obtain permission</a> steps with "`screen-wake-lock`":
Expand Down Expand Up @@ -667,19 +670,19 @@ <h3>
<section>
<h3>
<dfn>Handling document loss of visibility</dfn>
</h3>
</h3><!-- Note: https://github.com/w3c/page-visibility/pull/47 formally
defines external hooks we can use here, but they are not part of
the latest TR, so we cannot reference them yet. -->
<p data-tests="wakelock-document-hidden-manual.https.html">
When the user agent determines that the <a>visibility state</a> of
the [=environment settings object / responsible document=] of the
<a>current settings object</a> changes, it must run these steps:
When the user agent determines that the [=Document/visibility state=]
of the <a>Document</a> of the <a>top-level browsing context</a> has
become `hidden`, the user agent MUST run the following steps after
the <a>now hidden algorithm</a>:
</p>
<ol class="algorithm">
<li>Let |document:Document| be the [=environment settings object /
responsible document=] of the <a>current settings object</a>.
</li>
<li>If |document|'s <a>visibility state</a> is `"visible"`, abort
these steps.
</li>
<li>Let |screenRecord| be the <a>platform wake lock</a>'s <a>state
record</a> associated with |document| and <a>wake lock type</a>
{{WakeLockType/"screen"}}.
Expand All @@ -694,7 +697,8 @@ <h3>
</li>
</ol>
<aside class="note">
The <a>visibility state</a> is only exposed on the {{Window}} object.
The [=Document/visibility state=] is only exposed on the {{Window}}
object.
</aside>
</section>
<section>
Expand Down Expand Up @@ -837,14 +841,16 @@ <h2>
</pre>
</section>
<section>
<!-- Note: https://github.com/w3c/page-visibility/pull/47 formally
defines external hooks we can use here, but they are not part of
the latest TR, so we cannot reference them yet. Once we can, this
whole section can be removed. -->
<h2>
Dependencies
</h2>
<p>
Document's <code><dfn data-cite=
"PAGE-VISIBILITY#dom-document-hidden">hidden</dfn></code> attribute,
and <dfn data-cite="PAGE-VISIBILITY#dfn-visibility-states">visibility
state</dfn> are defined in [[PAGE-VISIBILITY]].
The following is defined in [[PAGE-VISIBILITY]]: <dfn data-cite=
"PAGE-VISIBILITY#dfn-now-hidden-algorithm">now hidden algorithm</dfn>.
</p>
</section>
<section id="conformance">
Expand Down

0 comments on commit 54f520c

Please sign in to comment.