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

Remove permission check #326

Closed
wants to merge 10 commits into from
Closed

Remove permission check #326

wants to merge 10 commits into from

Conversation

marcoscaceres
Copy link
Member

@marcoscaceres marcoscaceres commented Sep 9, 2021

Closes #324

Please see #324 for rationale and discussion.

The following tasks have been completed:

Implementation commitment:


Preview | Diff

Copy link
Member

@rakuco rakuco left a comment

Choose a reason for hiding this comment

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

Personally I'm still undecided about this one and would like to hear from @reillyeon, especially as I don't know if adapting the Chromium implementation to this change would count as breaking backward compatibility, or if there are plans to add a UI for this permission in the pipeline.

@@ -345,22 +287,6 @@ <h3>
</li>
<li>Run the following steps <a>in parallel</a>:
<ol>
<li>Let |state:PermissionState| be the result of <a>requesting
Copy link
Member

Choose a reason for hiding this comment

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

Without these steps, I think you can drop the "run the following steps in parallel above", as all the remaining sub-steps are run from a queued global task.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, good suggestion!

Copy link
Member Author

Choose a reason for hiding this comment

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

Acquiring the lock needs to happen in parallel.

index.html Show resolved Hide resolved
index.html Show resolved Hide resolved
index.html Show resolved Hide resolved
index.html Outdated
@@ -343,67 +285,49 @@ <h3>
</li>
<li>Let |promise:Promise| be [=a new promise=].
</li>
<li>Run the following steps <a>in parallel</a>:
<li>
<a>Queue a global task</a> on the <a>screen wake lock task
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need to queue a global task here? We're already in the main thread at this point.

Copy link
Member

Choose a reason for hiding this comment

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

We don't technically need to but this provides implementations with the freedom to not return a settled Promise synchronously from this method, as otherwise this method doesn't need to be Promise-returning at all.

Copy link
Member

Choose a reason for hiding this comment

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

as otherwise this method doesn't need to be Promise-returning at all.

Wouldn't this be a case of "we thought there should be async stuff happening, now there's not but we can't break backwards compatibility"? It's how we ended up with WakeLockSentinel.release() returning a resolved promise after #299, for example.

I'm not saying I'm in favor of doing that, at this point I'm more curious about whether this is standard practice, or even if I'm looking at it from the wrong perspective.

Copy link
Member

@rakuco rakuco left a comment

Choose a reason for hiding this comment

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

This was discussed at TPAC 2022: https://www.w3.org/2022/09/15-dap-minutes.html#t21

The consensus is that this PR should be merged, but the pending review comments still need to be addressed.

@marcoscaceres
Copy link
Member Author

marcoscaceres commented Sep 27, 2022

@rakuco, could we merge this and then revise the global task stuff above?... I think the visibility checks being done in parallel are also wrong (should be done sync I think, because the document could disappear by the time the check is done), so we might need to give the whole spec a once over.

However, what's more important now is to remove the permission check.

index.html Outdated Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
@marcoscaceres
Copy link
Member Author

Quick update... fixed the merge conflicts and fixed the broken cross reference to [=Document/visibility state=]

Copy link
Member

@rakuco rakuco left a comment

Choose a reason for hiding this comment

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

There are some issues with the latest merge commit that resulted in some wrong steps in request() that need to be fixed.

@rakuco, could we merge this and then revise the global task stuff above?... I think the visibility checks being done in parallel are also wrong (should be done sync I think, because the document could disappear by the time the check is done), so we might need to give the whole spec a once over.

Let's not block on the queue global task stuff then. With that said, I don't think the visibility checks are done in parallel, the idea behind queuing a global task while in parallel was to prevent that. We spent quite a lot of time in #299 trying to get this right, so I was hoping that the current version already made sense.

I'm also curious about WebKit/WebKit#4733 -- the PR mentions there's a pending discussion about prompts, so I wonder (or would like to double check) if we may end up having to revert this PR not too far in the future.

Finally: can you also send a WPT pull request removing the permission-related bits from the tests?

index.html Outdated Show resolved Hide resolved
index.html Outdated
</li>
<li data-tests="wakelock-request-denied.https.html">If |state| is
{{PermissionState/"denied"}}, then:
<li>If |document|'s [=Document/visibility state=] is "hidden", then:
Copy link
Member

Choose a reason for hiding this comment

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

Something went wrong with the merge in these steps too: all the main substeps within the "Queue a global task" step have been duplicated inside the If document.[[ActiveLocks]]["screen"] is empty substep (see the Preview link).

index.html Outdated
@@ -343,67 +285,49 @@ <h3>
</li>
<li>Let |promise:Promise| be [=a new promise=].
</li>
<li>Run the following steps <a>in parallel</a>:
<li>
<a>Queue a global task</a> on the <a>screen wake lock task
Copy link
Member

Choose a reason for hiding this comment

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

as otherwise this method doesn't need to be Promise-returning at all.

Wouldn't this be a case of "we thought there should be async stuff happening, now there's not but we can't break backwards compatibility"? It's how we ended up with WakeLockSentinel.release() returning a resolved promise after #299, for example.

I'm not saying I'm in favor of doing that, at this point I'm more curious about whether this is standard practice, or even if I'm looking at it from the wrong perspective.

index.html Outdated Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
@marcoscaceres
Copy link
Member Author

Sent PR to remove test web-platform-tests/wpt#36121

Will start working on the other tests as part of #351

@marcoscaceres
Copy link
Member Author

@rakuco wrote:

Wouldn't this be a case of "we thought there should be async stuff happening, now there's not but we can't break backwards compatibility"? It's how we ended up with WakeLockSentinel.release() returning a resolved promise after #299, for example.

Not exactly. This is just a defensive design strategy in case we need to reject the promise in the future for some reason.

I'm not saying I'm in favor of doing that, at this point I'm more curious about whether this is standard practice, or even if I'm looking at it from the wrong perspective.

(As a followup...)

It is. I think we should update release() to better reflect this. It should resolve the promise immediately if the ActiveLocks is not empty, but then should actually try to release at the OS level and then settle the final promise. Otherwise this could be racy.

@anssiko
Copy link
Member

anssiko commented Sep 28, 2022

I’m happy to see @marcoscaceres continue his substantial contributions (also in #351) in this WG. As the co-chair it is also my duty to remind you to either join this WG or use License Grants from Non-Participants mechanism.

@xfq can you enable https://github.com/w3c/ash-nazg for this repo?

@reillyeon
Copy link
Member

I think we should update release() to better reflect this. It should resolve the promise immediately if the ActiveLocks is not empty, but then should actually try to release at the OS level and then settle the final promise. Otherwise this could be racy.

I don't think this is racy. Firstly, it never makes sense to tell the site that it failed to release a lock, if there were even possible. The site has successfully expressed its desire to release the lock and it is up to the user agent to convey that to the underlying platform. There may be many other components of the system still holding the lock (including other sites, or other script on the same site) but that state is invisible to the current site.

@marcoscaceres
Copy link
Member Author

@anssiko, thanks for the reminder; I'll see what I can do about joining (though chances are low until objections are addressed). Just want to point out that this PR predates me joining Apple, so I'm just making an editorial contribution here.

For #351, I can close that and maybe get @rakuco or someone else to send a PR to address the corresponding issue (#350)?

(now regretting not making this also a join deliverable with WebAppsWG 😢)

@xfq
Copy link
Member

xfq commented Sep 29, 2022

@xfq can you enable https://github.com/w3c/ash-nazg for this repo?

Tracked in w3c/ash-nazg#252

@@ -309,11 +251,19 @@ <h3>
The <dfn>request()</dfn> method
</h3>
<p data-tests="wakelock-type.https.any.html">
The <code>request(|type:WakeLockType|)</code> method steps are:
The `request(|type:WakeLockType|)` method steps are:
Copy link
Member

Choose a reason for hiding this comment

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

ReSpec doesn't seem to like this change. request(|type:WakeLockType|) is being written literally like that in the page.

</p>
<ol class="algorithm">
<li>Let |document:Document| be [=this=]'s [=relevant global
object=]'s [=associated Document=].
object=]'s [=associated `Document`=].
Copy link
Member

Choose a reason for hiding this comment

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

The change in the order of steps here looks unrelated. They might even make sense, but I'd rather do this in another PR.

<li data-tests="wakelock-document-hidden-manual.https.html">If
|document|'s [=Document/visibility state=] is "`hidden`", return [=a
promise rejected with=] {{"NotAllowedError"}} {{DOMException}}.
</li>
<li>Let |promise:Promise| be [=a new promise=].
</li>
<li>Run the following steps <a>in parallel</a>:
<li>[=In parallel=]:
Copy link
Member

Choose a reason for hiding this comment

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

Was there a particular reason to change the original version? It's just saying the same thing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just reads better.

<ol>
<li>Let |state:PermissionState| be the result of <a>requesting
permission to use</a> "`screen-wake-lock`".
<li>Attempt to [=acquire a wake lock=] of type
Copy link
Member

Choose a reason for hiding this comment

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

The steps still look weird:

  • The check for whether document.[[ActiveLocks]]["screen"] is empty was dropped.
  • Only acquiring the wake lock happened in parallel, document.[[ActiveLocks]] was only read and manipulated from the the main thread to avoid races, but now all these steps are happening in parallel.

@@ -721,32 +624,29 @@ <h3>
<li>Remove |lock| from
|document|.{{Document/[[ActiveLocks]]}}[|type|].
</li>
<li>[=Queue a task=] on the [=screen wake lock task source=] to:
Copy link
Member

Choose a reason for hiding this comment

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

The changes to this section also look unrelated to permissions and should be sent in a separate PR.

@marcoscaceres
Copy link
Member Author

@rakuco could you take this over? (please remove the changes you don't agree with.) As I'm not a member of this group, I can't make any further changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should this prompt?
6 participants