Merge pull request #7396 from Slowlife01/pipeligibility

refactor(MediaController): check pip eligibility in class
This commit is contained in:
mr. m 2025-04-07 02:02:33 -07:00 committed by GitHub
commit e06c20d2f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 497 additions and 501 deletions

View file

@ -1,3 +1,12 @@
{
const lazy = {};
XPCOMUtils.defineLazyPreferenceGetter(
lazy,
'RESPECT_PIP_DISABLED',
'media.videocontrols.picture-in-picture.respect-disablePictureInPicture',
true
);
class ZenMediaController { class ZenMediaController {
_currentMediaController = null; _currentMediaController = null;
_currentBrowser = null; _currentBrowser = null;
@ -13,8 +22,6 @@ class ZenMediaController {
mediaProgressBarContainer = null; mediaProgressBarContainer = null;
supportedKeys = ['playpause', 'previoustrack', 'nexttrack']; supportedKeys = ['playpause', 'previoustrack', 'nexttrack'];
pipEligibilityMap = new Map();
mediaControllersMap = new Map(); mediaControllersMap = new Map();
_tabTimeout = null; _tabTimeout = null;
@ -143,7 +150,6 @@ class ZenMediaController {
mediaController.removeEventListener('deactivated', this.onDeactivated); mediaController.removeEventListener('deactivated', this.onDeactivated);
this.mediaControllersMap.delete(mediaController.id); this.mediaControllersMap.delete(mediaController.id);
this.pipEligibilityMap.delete(retrievedMediaController?.browser?.browserId);
} }
if (shouldOverride) { if (shouldOverride) {
@ -289,10 +295,6 @@ class ZenMediaController {
mediaController.addEventListener('deactivated', this.onDeactivated); mediaController.addEventListener('deactivated', this.onDeactivated);
} }
updatePipEligibility(browser, isEligible) {
this.pipEligibilityMap.set(browser.browserId, isEligible);
}
_onDeactivated(event) { _onDeactivated(event) {
this.deinitMediaController(event.target, true, event.target.id === this._currentMediaController.id, true); this.deinitMediaController(event.target, true, event.target.id === this._currentMediaController.id, true);
this.switchController(); this.switchController();
@ -523,11 +525,13 @@ class ZenMediaController {
updatePipButton() { updatePipButton() {
if (!this._currentBrowser) return; if (!this._currentBrowser) return;
const { totalPipCount, totalPipDisabled } = PictureInPicture.getEligiblePipVideoCount(this._currentBrowser);
const isPipEligible = this.pipEligibilityMap.get(this._currentBrowser.browserId); if (totalPipCount === 1 || (totalPipDisabled > 0 && lazy.RESPECT_PIP_DISABLED))
if (isPipEligible) this.mediaControlBar.setAttribute('can-pip', ''); this.mediaControlBar.setAttribute('can-pip', '');
else this.mediaControlBar.removeAttribute('can-pip'); else this.mediaControlBar.removeAttribute('can-pip');
} }
} }
window.gZenMediaController = new ZenMediaController(); window.gZenMediaController = new ZenMediaController();
}

View file

@ -1,5 +1,5 @@
diff --git a/toolkit/components/pictureinpicture/PictureInPicture.sys.mjs b/toolkit/components/pictureinpicture/PictureInPicture.sys.mjs diff --git a/toolkit/components/pictureinpicture/PictureInPicture.sys.mjs b/toolkit/components/pictureinpicture/PictureInPicture.sys.mjs
index 5da0404b2672ba8cce7bcf808bf2373474776654..1405c53a927a64ecda8255d78d9aa5ddf8806685 100644 index 5da0404b2672ba8cce7bcf808bf2373474776654..3b93217b38f25f54d7ef44d151e314bc1c5e5ce3 100644
--- a/toolkit/components/pictureinpicture/PictureInPicture.sys.mjs --- a/toolkit/components/pictureinpicture/PictureInPicture.sys.mjs
+++ b/toolkit/components/pictureinpicture/PictureInPicture.sys.mjs +++ b/toolkit/components/pictureinpicture/PictureInPicture.sys.mjs
@@ -494,7 +494,7 @@ export var PictureInPicture = { @@ -494,7 +494,7 @@ export var PictureInPicture = {
@ -11,11 +11,3 @@ index 5da0404b2672ba8cce7bcf808bf2373474776654..1405c53a927a64ecda8255d78d9aa5dd
await this.closeSinglePipWindow({ reason: "Unpip", actorRef: pipActor }); await this.closeSinglePipWindow({ reason: "Unpip", actorRef: pipActor });
}, },
@@ -623,6 +623,7 @@ export var PictureInPicture = {
pipToggle.hidden = true;
}
+ win.gZenMediaController.updatePipEligibility(browser, !pipToggle.hidden);
let browserHasPip = !!this.browserWeakMap.get(browser);
if (browserHasPip) {
this.setUrlbarPipIconActive(browser.ownerGlobal);