Skip to content

Commit 12ed491

Browse files
committed
Fix 244: Address requestPictureInPicture() algorithm
The idea with the change is to have the step creating the PiP window in parallel: Let Picture-in-Picture window be a new instance of PictureInPictureWindow associated with pictureInPictureElement. And only after that, queueing the global task that does DOM mutations and what not. Because this creation of the Picture-in-picture can theoretically take forever.
1 parent f3ef898 commit 12ed491

1 file changed

Lines changed: 38 additions & 39 deletions

File tree

index.bs

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -183,36 +183,7 @@ are <a>same origin-domain</a> with origin.
183183

184184
## Request Picture-in-Picture ## {#request-pip}
185185

186-
When the <dfn>request Picture-in-Picture algorithm</dfn> with |video| is invoked,
187-
the user agent MUST run the following steps:
188-
189-
1. If <a>Picture-in-Picture support</a> is `false`, throw a
190-
{{NotSupportedError}} and abort these steps.
191-
2. If the document is not <a>allowed to use</a> the <a>policy-controlled feature</a>
192-
named `"picture-in-picture"`, throw a {{SecurityError}} and abort these
193-
steps.
194-
3. If |video|'s {{readyState}} attribute is {{HAVE_NOTHING}}, throw a
195-
{{InvalidStateError}} and abort these steps.
196-
4. If |video| has no video track, throw a {{InvalidStateError}} and abort
197-
these steps.
198-
5. If |video|'s {{HTMLVideoElement/disablePictureInPicture}} is true,
199-
the user agent MAY throw an {{InvalidStateError}} and abort these steps.
200-
6. If {{pictureInPictureElement}} is `null` and the <a>relevant global object</a>
201-
of <a>this</a> does not have <a>transient activation</a>, throw a
202-
{{NotAllowedError}} and abort these steps.
203-
7. If |video| is {{pictureInPictureElement}}, abort these steps.
204-
8. Set {{pictureInPictureElement}} to |video|.
205-
9. Let <dfn>Picture-in-Picture window</dfn> be a new instance of
206-
{{PictureInPictureWindow}} associated with {{pictureInPictureElement}}.
207-
10. Append <a>relevant settings object</a>'s <a>origin</a> to
208-
<a>initiators of active Picture-in-Picture sessions</a>.
209-
11. <a>Queue a task</a> to <a>fire an event</a> named
210-
{{enterpictureinpicture}} using {{PictureInPictureEvent}} at the
211-
|video| with its {{bubbles}} attribute initialized to `true` and its
212-
{{PictureInPictureEvent/pictureInPictureWindow}} attribute initialized to
213-
<a>Picture-in-Picture window</a>.
214-
12. If {{pictureInPictureElement}} is <a>fullscreenElement</a>, it is
215-
RECOMMENDED to <a>exit fullscreen</a>.
186+
See {{requestPictureInPicture()}} for API algorithm steps.
216187

217188
It is RECOMMENDED that video frames are not rendered in the page and in the
218189
Picture-in-Picture window at the same time but if they are, they MUST be kept
@@ -334,16 +305,44 @@ partial interface HTMLVideoElement {
334305
};
335306
</pre>
336307

337-
The {{requestPictureInPicture()}} method, when invoked, MUST
338-
return <a>a new promise</a> |promise| and run the following steps <a>in
339-
parallel</a>:
308+
The {{requestPictureInPicture()}} method steps are:
309+
310+
1. Let |p| be a new promise created in <a>this</a>'s relevant realm.
311+
2. Let |global| be <a>this</a>'s <a>relevant global object</a>.
312+
3. If <a>Picture-in-Picture support</a> is `false`, reject |p| with a
313+
{{NotSupportedError}} exception and return |p|.
314+
4. If <a>this</a>'s <a>node document</a> is not <a>allowed to use</a> the <a>policy-controlled feature</a>
315+
named `"picture-in-picture"`, reject |p| with a {{SecurityError}} exception and
316+
return |p|.
317+
5. If <a>this</a>'s {{readyState}} attribute is {{HAVE_NOTHING}}, reject |p| with an
318+
{{InvalidStateError}} exception and return |p|.
319+
6. If <a>this</a> has no video track, reject |p| with an {{InvalidStateError}} exception
320+
and return |p|.
321+
7. If <a>this</a>'s {{HTMLVideoElement/disablePictureInPicture}} is true,
322+
the user agent MAY reject |p| with an {{InvalidStateError}} exception and return |p|.
323+
8. If {{pictureInPictureElement}} is `null` and the <a>relevant global object</a>
324+
of <a>this</a> does not have <a>transient activation</a>, reject |p| with a
325+
{{NotAllowedError}} exception and return |p|.
326+
9. Return promise, and run the remaining steps in parallel:
327+
1. If <a>this</a> is {{pictureInPictureElement}}:
328+
1. Queue a global task on the DOM manipulation task source given global to [=/resolve=] the <a>Picture-in-Picture window</a> associated with
329+
{{pictureInPictureElement}}
330+
2. return
331+
2. Let <dfn>Picture-in-Picture window</dfn> be a new instance of
332+
{{PictureInPictureWindow}} associated with <a>this</a>.
333+
3. Queue a global task on the DOM manipulation task source given **global**, to perform the following steps:
334+
1. Set {{pictureInPictureElement}} to <a>this</a>.
335+
2. Append <a>relevant settings object</a>'s <a>origin</a> to
336+
<a>initiators of active Picture-in-Picture sessions</a>.
337+
3. If {{pictureInPictureElement}} is <a>fullscreenElement</a>, it is
338+
RECOMMENDED to <a>exit fullscreen</a>.
339+
4. <a>Fire an event</a> named {{enterpictureinpicture}} using {{PictureInPictureEvent}} at the
340+
|video| with its {{bubbles}} attribute initialized to `true` and its
341+
{{PictureInPictureEvent/pictureInPictureWindow}} attribute initialized to
342+
<a>Picture-in-Picture window</a>.
343+
5. [=/Resolve=] |p| with the <a>Picture-in-Picture window</a> associated with
344+
{{pictureInPictureElement}}.
340345

341-
1. Let |video| be the video element on which the method was invoked.
342-
2. Run the <a>request Picture-in-Picture algorithm</a> with |video|.
343-
3. If the previous step threw an exception, reject |promise| with that
344-
exception and abort these steps.
345-
4. [=/Resolve=] |promise| with the <a>Picture-in-Picture window</a> associated with
346-
{{pictureInPictureElement}}.
347346

348347
## Extensions to <code>Document</code> ## {#document-extensions}
349348

0 commit comments

Comments
 (0)