Bug 1695266 - Create documentation for the Picture-in-Picture Overrides extension r=mtigley,mhowell

Differential Revision: https://phabricator.services.mozilla.com/D108073
This commit is contained in:
Oliver Pope 2021-03-22 22:50:52 +00:00
parent 4e512a5e67
commit 0fc5685f2c
3 changed files with 52 additions and 0 deletions

View File

@ -6,7 +6,15 @@
/* global ExtensionAPI, ExtensionCommon, Services, XPCOMUtils */
/**
* Class extending the ExtensionAPI, ensures we can set/get preferences
*/
this.aboutConfigPipPrefs = class extends ExtensionAPI {
/**
* Override ExtensionAPI with PiP override's specific preference API, prefixed by `disabled_picture_in_picture_overrides`
* @param {ExtensionContext} context the context of an extension
* @returns {Object} returns the necessary API structure required to manage prefs within this extension
*/
getAPI(context) {
const EventManager = ExtensionCommon.EventManager;
const extensionIDBase = context.extension.id.split("@")[0];
@ -28,6 +36,11 @@ this.aboutConfigPipPrefs = class extends ExtensionAPI {
};
},
}).api(),
/**
* Calls `Services.prefs.getBoolPref` to get a preference
* @param {String} name The name of the preference to get; will be prefixed with this extension's branch
* @returns the preference, or undefined
*/
async getPref(name) {
try {
return Services.prefs.getBoolPref(
@ -37,6 +50,12 @@ this.aboutConfigPipPrefs = class extends ExtensionAPI {
return undefined;
}
},
/**
* Calls `Services.prefs.setBoolPref` to set a preference
* @param {String} name the name of the preference to set; will be prefixed with this extension's branch
* @param {String} value the bool value to save in the pref
*/
async setPref(name, value) {
Services.prefs.setBoolPref(`${extensionPrefNameBase}${name}`, value);
},

View File

@ -25,6 +25,12 @@ const TOGGLE_ENABLED_PREF =
* This API is expected to be running in the parent process.
*/
this.pictureInPictureParent = class extends ExtensionAPI {
/**
* Override ExtensionAPI with PiP override's specific API
* Relays the site overrides to this extension's child process
* @param {ExtensionContext} context the context of our extension
* @returns {Object} returns the necessary API structure required to manage sharedData in PictureInPictureParent
*/
getAPI(context) {
return {
pictureInPictureParent: {
@ -52,6 +58,12 @@ this.pictureInPictureParent = class extends ExtensionAPI {
* background scripts.
*/
this.pictureInPictureChild = class extends ExtensionAPI {
/**
* Override ExtensionAPI with PiP override's specific API
* Clone constants into the Picture-in-Picture child process
* @param {ExtensionContext} context the context of our extension
* @returns returns the necessary API structure required to get data from PictureInPictureChild
*/
getAPI(context) {
return {
pictureInPictureChild: {

View File

@ -6,7 +6,14 @@
/* globals browser, module */
/**
* Picture-in-Picture Overrides
*/
class PictureInPictureOverrides {
/**
* Class constructor
* @param {Object} availableOverrides Contains all overrides provided in data/picture_in_picture_overrides.js
*/
constructor(availableOverrides) {
this.pref = "enable_picture_in_picture_overrides";
this._prefEnabledOverrides = new Set();
@ -14,6 +21,9 @@ class PictureInPictureOverrides {
this.policies = browser.pictureInPictureChild.getPolicies();
}
/**
* Ensures the "enable_picture_in_picture_overrides" pref is set; if it is undefined, sets the pref to true
*/
async _checkGlobalPref() {
await browser.aboutConfigPipPrefs.getPref(this.pref).then(value => {
if (value === false) {
@ -27,6 +37,11 @@ class PictureInPictureOverrides {
});
}
/**
* Checks the status of a specified override, and updates the set, `this._prefEnabledOverrides`, accordingly
* @param {String} id the id of the specific override contained in `this._availableOverrides`
* @param {String} pref the specific preference to check, in the form `disabled_picture_in_picture_overrides.${id}`
*/
async _checkSpecificOverridePref(id, pref) {
const isDisabled = await browser.aboutConfigPipPrefs.getPref(pref);
if (isDisabled === true) {
@ -36,6 +51,9 @@ class PictureInPictureOverrides {
}
}
/**
* The function that `run.js` calls to begin checking for changes to the PiP overrides
*/
bootup() {
const checkGlobal = async () => {
await this._checkGlobalPref();
@ -63,6 +81,9 @@ class PictureInPictureOverrides {
});
}
/**
* Sets pictureInPictureParent's overrides
*/
async _onAvailableOverridesChanged() {
const policies = await this.policies;
let enabledOverrides = {};