Skip to content

setMediaKeys(): move state changes and promise resolution to queued t…#596

Open
xhwang-chromium wants to merge 1 commit into
w3c:mainfrom
xhwang-chromium:fix-issue-585
Open

setMediaKeys(): move state changes and promise resolution to queued t…#596
xhwang-chromium wants to merge 1 commit into
w3c:mainfrom
xhwang-chromium:fix-issue-585

Conversation

@xhwang-chromium
Copy link
Copy Markdown
Contributor

@xhwang-chromium xhwang-chromium commented May 13, 2026

Fixes #585.

The setMediaKeys() algorithm in Section 7.2 of the EME specification performed several state mutations while running "in parallel", which violates the standard web platform concurrency model.

This change moves observable state changes, internal flag updates, and promise resolution inside a queued task to ensure they are executed on the main thread.


Preview | Diff

@xhwang-chromium
Copy link
Copy Markdown
Contributor Author

@marcoscaceres Could you please take a look to see whether makes sense? I mechanically did this change (with the help of AI) to make sure matches the existing spec. Could you please take a look to see if it makes sense?

Here's a more readable summary for easier discussion:

   5. Run the following steps in parallel:
       1. If (CDM already in use or UA unable to use it):
           1. Queue a task to:
               1. Set attaching media keys to false.
               2. Reject promise with QuotaExceededError.
           2. Abort these steps.

       2. If (mediaKeys attribute is not null): [This is the existing association]
           1. If (Removal not supported):
               1. Queue a task to:
                   1. Set attaching media keys to false.
                   2. Reject promise with NotSupportedError.
               2. Abort these steps.
           2. If (Cannot be removed currently):
               1. Queue a task to:
                   1. Set attaching media keys to false.
                   2. Reject promise with InvalidStateError.
               2. Abort these steps.
           3. Stop using the CDM and remove the association.
           4. If (Preceding step failed):
               1. Queue a task to:
                   1. Set attaching media keys to false.
                   2. Reject promise with the appropriate error.
               2. Abort these steps.

       3. If (mediaKeys is not null): [This is the new association]
           1. Associate the CDM with the media element.
           2. If (Preceding step failed):
               1. Queue a task to:
                   1. Set mediaKeys attribute to null.
                   2. Set attaching media keys to false.
                   3. Reject promise with the appropriate error.
               2. Abort these steps.

       4. Queue a task to run the following steps: [Final Success Path]
           1. Set the mediaKeys attribute to mediaKeys.
           2. Set attaching media keys to false.
           3. Resolve promise with undefined.
           4. If mediaKeys is not null, run the Attempt to Resume Playback If Necessary algorithm.

@xhwang-chromium xhwang-chromium marked this pull request as draft May 13, 2026 03:37
…ask (w3c#585)

The setMediaKeys() algorithm in Section 7.2 of the EME specification performed
several state mutations while running "in parallel", which violates the
standard web platform concurrency model.

This change moves observable state changes, internal flag updates, and
promise resolution inside a queued task to ensure they are executed on the
main thread.
@xhwang-chromium xhwang-chromium marked this pull request as ready for review May 13, 2026 05:46
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.

setMediaKeys() modifies observable state and internal flags "in parallel"

2 participants