forked from mirrors/gecko-dev
Bug 1551570 - Ensure Picture-in-Picture player window is closed before updating internal state. r=JSON_voorhees
Differential Revision: https://phabricator.services.mozilla.com/D31081 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
86bff4d747
commit
36f892f546
2 changed files with 12 additions and 7 deletions
|
|
@ -52,25 +52,28 @@ var PictureInPicture = {
|
|||
}
|
||||
},
|
||||
|
||||
focusTabAndClosePip() {
|
||||
async focusTabAndClosePip() {
|
||||
let gBrowser = this.browser.ownerGlobal.gBrowser;
|
||||
let tab = gBrowser.getTabForBrowser(this.browser);
|
||||
gBrowser.selectedTab = tab;
|
||||
this.unload();
|
||||
this.closePipWindow();
|
||||
await this.closePipWindow();
|
||||
},
|
||||
|
||||
/**
|
||||
* Find and close any pre-existing Picture in Picture windows.
|
||||
*/
|
||||
closePipWindow() {
|
||||
async closePipWindow() {
|
||||
// This uses an enumerator, but there really should only be one of
|
||||
// these things.
|
||||
for (let win of Services.wm.getEnumerator(WINDOW_TYPE)) {
|
||||
if (win.closed) {
|
||||
continue;
|
||||
}
|
||||
let closedPromise = new Promise(resolve => {
|
||||
win.addEventListener("unload", resolve, {once: true});
|
||||
});
|
||||
win.close();
|
||||
await closedPromise;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -95,9 +98,11 @@ var PictureInPicture = {
|
|||
* the player component inside it has finished loading.
|
||||
*/
|
||||
async handlePictureInPictureRequest(browser, videoData) {
|
||||
this.browser = browser;
|
||||
// If there's a pre-existing PiP window, close it first.
|
||||
await this.closePipWindow();
|
||||
|
||||
let parentWin = browser.ownerGlobal;
|
||||
this.closePipWindow();
|
||||
this.browser = browser;
|
||||
let win = await this.openPipWindow(parentWin, videoData);
|
||||
let controls = win.document.getElementById("controls");
|
||||
this.weakPipControls = Cu.getWeakReference(controls);
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ async function setupPlayer(originatingBrowser, videoData) {
|
|||
window.close();
|
||||
});
|
||||
|
||||
browser.addEventListener("unload", () => {
|
||||
window.addEventListener("unload", () => {
|
||||
PictureInPicture.unload();
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue