Re: [mediacapture-screen-share] A CaptureController object for getDisplayMedia() (#230)

@jan-ivar, if, [as you propose](https://github.com/w3c/mediacapture-screen-share/issues/230#issuecomment-1235982999), we specify that both getDisplayMedia() and getDisplayMedia({controller}) must have the same default unspecified behavior in the absence of a call to setFocusBehavior(), then it will effectively mean that the latter will focus by default. This means that for applications that don't call setFocusBehavior(), focus **always** changes after N milliseconds. Repeat - not just when the CPU is unusually busy, but always. That's not fun for the user, so I'd call this decision mutually-exclusive with the decision to rely solely on a timer.

### Proposal

I think we can avoid the shimming issues associated with a microtask if we go with a task instead. (I think @alvestrand and @youennf have both suggested that before.)

Precisely formulated, when `getDisplayMedia({controller})` is called, it returns a promise `p` as per the [getDisplayMedia algorithm](https://w3c.github.io/mediacapture-screen-share/#dom-mediadevices-getdisplaymedia). The normal steps execute, with the following additions:
* Define as WOO the "window of opportunity" for calling `setFocusBehavior`.
* At the point where getDisplayMedia's algorithm resolves `p`, instead:
   * Schedule a microtask to resolve `p`.
   * Schedule a task (not microtask) to close the WOO.
   * Declare the WOO open.
* Calling `setFocusBehavior()` from inside the WOO has the expected effects discussed elsewhere.
* Calling outside of the WOO raise a synchronous exception.
* The WOO closes when the **earlist** of these happens:
   * Application calls `setFocusBehavior()`.
   * The task to close the WOO executes.
   * All tracks of the MediaSream are closed. (Or maybe the video track is enough?)
   * The document that called getDisplayMedia loses activation/focus. (See open questions below, btw.)
* To defend against timing issues described earlier on both #190 and #230, we also specify a timer (or just allow it - see below). Calls to `setFocusBehavior()` when the WOO is still open, but after the timer elapses, are no-op (no exception). Rationale:
   * Timer + exception becomes a bad mix once we introduce IPC. And we have to account for the possibility of IPC. E.g. in Chrome, the timer will be on the trusted browser process, not in the content process, so as to avoid compromised content processes from being able to focus at an arbitrary time.
   * This uncommon edge-case is mostly inactionable for the application.

### Open questions

* What happens when the controller and/or tracks are transferred? Should we still tie WOO to the activation/focus of the document which originally called getDisplayMedia?
   * Possibly the simplest solution is to close WOO as soon as **either** track or controller is transfered?
* Should the timer be specified, or should it be left up to the UA?
   * I would prefer specifying.

-- 
GitHub Notification of comment by eladalon1983
Please view or discuss this issue at https://github.com/w3c/mediacapture-screen-share/issues/230#issuecomment-1238184221 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Tuesday, 6 September 2022 13:53:25 UTC