Bug 230136 - Implement 'gamepad' Permissions Policy
Summary: Implement 'gamepad' Permissions Policy
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Marcos Caceres
URL: https://w3c.github.io/gamepad/#permis...
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-09-09 16:53 PDT by Marcos Caceres
Modified: 2023-12-17 19:40 PST (History)
12 users (show)

See Also:


Attachments
Patch (14.45 KB, patch)
2021-11-15 17:09 PST, Marcos Caceres
no flags Details | Formatted Diff | Diff
Patch (20.20 KB, patch)
2021-11-16 19:24 PST, Marcos Caceres
no flags Details | Formatted Diff | Diff
Patch (20.79 KB, patch)
2021-11-16 21:40 PST, Marcos Caceres
no flags Details | Formatted Diff | Diff
Patch (20.78 KB, patch)
2021-11-17 16:40 PST, Marcos Caceres
no flags Details | Formatted Diff | Diff
Patch (20.80 KB, patch)
2021-11-17 18:07 PST, Marcos Caceres
marcos: review?
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Marcos Caceres 2021-09-09 16:53:31 PDT
Gamepad defines has a "gamepad" permission, with an allow list of 'self'.
Comment 1 Radar WebKit Bug Importer 2021-09-16 16:54:15 PDT
<rdar://problem/83219098>
Comment 2 Marcos Caceres 2021-11-11 16:05:49 PST
We are changing it to "all" instead, as "self" turned out not to be web compatible. 

https://github.com/w3c/gamepad/pull/156
Comment 3 Marcos Caceres 2021-11-15 17:09:19 PST
Created attachment 444320 [details]
Patch
Comment 4 Marcos Caceres 2021-11-16 19:24:58 PST
Created attachment 444468 [details]
Patch
Comment 5 EWS Watchlist 2021-11-16 19:26:03 PST
This patch modifies the imported WPT tests. Please ensure that any changes on the tests (not coming from a WPT import) are exported to WPT. Please see https://trac.webkit.org/wiki/WPTExportProcess
Comment 6 Marcos Caceres 2021-11-16 21:40:36 PST
Created attachment 444478 [details]
Patch
Comment 7 Darin Adler 2021-11-17 09:07:29 PST
Comment on attachment 444478 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=444478&action=review

Feels like the test coverage is a bit light.

> Source/WebCore/Modules/gamepad/Navigator+Gamepad.idl:34
> +    [
> +      EnabledBySetting=GamepadsEnabled,
> +      CallWith=Document
> +    ] sequence<Gamepad> getGamepads();

I don’t think we have to break this out vertically just to fit one more attribute in. Unless this is copying and pasting directly from a specification or something.

    [EnabledBySetting=GamepadsEnabled, CallWith=Document] sequence<Gamepad> getGamepads();

> Source/WebCore/html/FeaturePolicy.cpp:53
> +        return "Gampad";

Typo: "Gamepad".

> Source/WebCore/html/FeaturePolicy.cpp:215
> +        if (item.startsWith("gamepad")) {

Not new, but why all the startsWith in this function? Is it valid to write "gamepadnotreallyimeantsomethingelse"?

> LayoutTests/http/tests/gamepad/gamepad-allow-attribute.https-expected.txt:4
> +CONSOLE MESSAGE: Feature policy 'Gampad' check failed for iframe with origin 'https://localhost:8443' and allow attribute 'gamepad 'none''.
> +CONSOLE MESSAGE: Feature policy 'Gampad' check failed for iframe with origin 'https://127.0.0.1:8443' and allow attribute 'gamepad 'none''.
> +CONSOLE MESSAGE: Feature policy 'Gampad' check failed for iframe with origin 'https://localhost:8443' and allow attribute 'gamepad 'self''.
> +CONSOLE MESSAGE: Feature policy 'Gampad' check failed for iframe with origin 'https://127.0.0.1:8443' and allow attribute 'gamepad https://localhost:8443'.

Here we have "Gampad".
Comment 8 Marcos Caceres 2021-11-17 16:29:33 PST
> Typo: "Gamepad".

Programming for 20+ years... never gets better 🤪

> Not new, but why all the startsWith in this function? Is it valid to write "gamepadnotreallyimeantsomethingelse"?

Yeah, the Permissions Policy parser there is fairly simple... it just does a split on ";", trims, and then checks the "startWith". I agree that it should probably be a little bit more robust. I think the updated Permission Policy spec has further parsing requirements, so eventually the parser might need to be rewritten.
Comment 9 Marcos Caceres 2021-11-17 16:40:13 PST
Created attachment 444603 [details]
Patch
Comment 10 Marcos Caceres 2021-11-17 16:55:17 PST
> Feels like the test coverage is a bit light.

I'm open to suggestion to what else to test. 

We might want to eventually consolidate+improve all the Permission Policy tests, as they all basically test the same way as I did here (I just copy-pasted-modified an existing test in the tree).
Comment 11 Darin Adler 2021-11-17 17:35:03 PST
Comment on attachment 444603 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=444603&action=review

> Source/WebCore/Modules/gamepad/NavigatorGamepad.h:30
> +#include "ExceptionOr.h"

It’s fine to include ExceptionOr.h and we have been doing that in other headers. But I’ve been wondering lately if we could get away with forward declarations instead in a case like this one.

    template<typename> class ExceptionOr;

That typically works for other return values in other similar cases, but for some reason we haven’t done that for ExecptionOr.
Comment 12 Marcos Caceres 2021-11-17 18:05:36 PST
>     template<typename> class ExceptionOr;

Ah, good idea! will add.
Comment 13 Marcos Caceres 2021-11-17 18:07:06 PST
Created attachment 444622 [details]
Patch
Comment 14 Marcos Caceres 2021-11-25 21:26:29 PST
@Darin, just kindly checking if you could finish the review or if I should ping someone else? Really appreciate all the feedback thus far.
Comment 15 youenn fablet 2021-11-26 00:18:55 PST
Comment on attachment 444622 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=444622&action=review

> Source/WebCore/Modules/gamepad/NavigatorGamepad.cpp:84
> +    if (!isFeaturePolicyAllowedByDocumentAndAllOwners(FeaturePolicy::Type::Gamepad, document, LogFeaturePolicyFailure::Yes))

I am not sure this is correct to get the document from the execution state.
It seems to me getting it from the navigator is better.
This could be tested with the edge case of a document having a same origin iframe, the iframe being denied gamepad permission, then calling iframe.contentWindow...
Can you check this case?

> LayoutTests/imported/w3c/ChangeLog:9
> +        * web-platform-tests/not-fully-active.https.html: Added.

This does not seem to be the right folder.
This should probably be in web-platform-tests/gamepad folder.
Looking at wpt, I can see tests that would seem useful, in particular gamepad-supported-by-feature-policy.html, which might be a bit redundant with http/tests/gamepad/gamepad-allow-attribute.https.html.
Can we import wpt/gampepad test, either in this patch or as a preliminary patch?
You can use Tools/Scripts/import-w3c-tests -t web-platform-tests/gamepad to do the import.
Comment 16 Darin Adler 2021-11-29 09:55:12 PST
My single comment didn’t imply that I was going to review this.
Comment 17 Darin Adler 2021-11-29 09:55:48 PST
Well, no that’s not right. I could review it. But let’s deal with Youenn’s comments first.
Comment 18 Marcos Caceres 2021-11-30 10:18:02 PST
Thanks for the additional feedback and comments. I'm traveling this week, but hope to address the feedback next week.
Comment 19 Marcos Caceres 2023-12-14 16:26:43 PST
The permission policy was switched to "*".
Comment 20 Marcos Caceres 2023-12-14 22:58:20 PST
Pull request: https://github.com/WebKit/WebKit/pull/21851
Comment 21 EWS 2023-12-17 19:40:28 PST
Committed 272199@main (82e7a7f64764): <https://commits.webkit.org/272199@main>

Reviewed commits have been landed. Closing PR #21851 and removing active labels.