mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 1488971 Move logic for disabling screenshots out of the extension r=kmag,_6a68
Differential Revision: https://phabricator.services.mozilla.com/D5310 --HG-- extra : source : a8de31323a3b52d7f4d6abd9405ba64e2227a653 extra : intermediate-source : ef0c065ebe0fc1918816718d45dc7e2a42545b06 extra : histedit_source : 56ceab6060017e3c893a17f1cd9d885f97fb7c31%2Cb574ee4b673e9c7443d8318f147982fc07774a54
This commit is contained in:
parent
83a7068d62
commit
eac08444e3
@ -99,6 +99,15 @@ add_task(async function startup() {
|
||||
min: 7,
|
||||
max: 55,
|
||||
},
|
||||
|
||||
// Disabling screenshots in the default test profile triggers some
|
||||
// work in the chrome registry that reads this pref. This can be removed
|
||||
// when bootstrapped extensions are gone, or even when screenshots
|
||||
// moves away from bootstrap (bug 1422437)
|
||||
"chrome.override_package.global": {
|
||||
min: 0,
|
||||
max: 50,
|
||||
},
|
||||
};
|
||||
|
||||
let startupRecorder = Cc["@mozilla.org/test/startuprecorder;1"].getService().wrappedJSObject;
|
||||
|
@ -1401,6 +1401,22 @@ BrowserGlue.prototype = {
|
||||
Normandy.uninit();
|
||||
},
|
||||
|
||||
// Set up a listener to enable/disable the screenshots extension
|
||||
// based on its preference.
|
||||
_monitorScreenshotsPref() {
|
||||
const PREF = "extensions.screenshots.disabled";
|
||||
const ID = "screenshots@mozilla.org";
|
||||
Services.prefs.addObserver(PREF, async () => {
|
||||
let addon = await AddonManager.getAddonByID(ID);
|
||||
let disabled = Services.prefs.getBoolPref(PREF, false);
|
||||
if (disabled) {
|
||||
await addon.disable({allowSystemAddons: true});
|
||||
} else {
|
||||
await addon.enable({allowSystemAddons: true});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// All initial windows have opened.
|
||||
_onWindowsRestored: function BG__onWindowsRestored() {
|
||||
if (this._windowsWereRestored) {
|
||||
@ -1457,6 +1473,8 @@ BrowserGlue.prototype = {
|
||||
};
|
||||
this._idleService.addIdleObserver(
|
||||
this._lateTasksIdleObserver, LATE_TASKS_IDLE_TIME_SEC);
|
||||
|
||||
this._monitorScreenshotsPref();
|
||||
},
|
||||
|
||||
/**
|
||||
|
42
browser/extensions/screenshots/bootstrap.js
vendored
42
browser/extensions/screenshots/bootstrap.js
vendored
@ -25,25 +25,6 @@ let appStartupPromise = new Promise((resolve, reject) => {
|
||||
});
|
||||
|
||||
const prefs = Services.prefs;
|
||||
const prefObserver = {
|
||||
register() {
|
||||
prefs.addObserver(PREF_BRANCH, this, false); // eslint-disable-line mozilla/no-useless-parameters
|
||||
},
|
||||
|
||||
unregister() {
|
||||
prefs.removeObserver(PREF_BRANCH, this, false); // eslint-disable-line mozilla/no-useless-parameters
|
||||
},
|
||||
|
||||
observe(aSubject, aTopic, aData) {
|
||||
// aSubject is the nsIPrefBranch we're observing (after appropriate QI)
|
||||
// aData is the name of the pref that's been changed (relative to aSubject)
|
||||
if (aData === USER_DISABLE_PREF) {
|
||||
// eslint-disable-next-line promise/catch-or-return
|
||||
appStartupPromise = appStartupPromise.then(handleStartup);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const appStartupObserver = {
|
||||
register() {
|
||||
@ -119,6 +100,18 @@ const APP_SHUTDOWN = 2;
|
||||
let addonData, startupReason;
|
||||
|
||||
function startup(data, reason) { // eslint-disable-line no-unused-vars
|
||||
addonResourceURI = data.resourceURI;
|
||||
|
||||
if (Services.prefs.getBoolPref(USER_DISABLE_PREF, false)) {
|
||||
AddonManager.getActiveAddons().then(result => {
|
||||
let addon = result.addons.find(a => a.id == ADDON_ID);
|
||||
if (addon) {
|
||||
addon.disable({allowSystemAddons: true});
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
addonData = data;
|
||||
startupReason = reason;
|
||||
if (reason === APP_STARTUP) {
|
||||
@ -126,14 +119,11 @@ function startup(data, reason) { // eslint-disable-line no-unused-vars
|
||||
} else {
|
||||
appStartupDone();
|
||||
}
|
||||
prefObserver.register();
|
||||
addonResourceURI = data.resourceURI;
|
||||
// eslint-disable-next-line promise/catch-or-return
|
||||
appStartupPromise = appStartupPromise.then(handleStartup);
|
||||
}
|
||||
|
||||
function shutdown(data, reason) { // eslint-disable-line no-unused-vars
|
||||
prefObserver.unregister();
|
||||
const webExtension = LegacyExtensionsUtils.getEmbeddedExtensionFor({
|
||||
id: ADDON_ID,
|
||||
resourceURI: addonResourceURI
|
||||
@ -155,20 +145,14 @@ function getBoolPref(pref) {
|
||||
return prefs.getPrefType(pref) && prefs.getBoolPref(pref);
|
||||
}
|
||||
|
||||
function shouldDisable() {
|
||||
return getBoolPref(USER_DISABLE_PREF);
|
||||
}
|
||||
|
||||
function handleStartup() {
|
||||
const webExtension = LegacyExtensionsUtils.getEmbeddedExtensionFor({
|
||||
id: ADDON_ID,
|
||||
resourceURI: addonResourceURI
|
||||
});
|
||||
|
||||
if (!shouldDisable() && !webExtension.started) {
|
||||
if (!webExtension.started) {
|
||||
start(webExtension);
|
||||
} else if (shouldDisable()) {
|
||||
stop(webExtension, ADDON_DISABLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -579,7 +579,7 @@ class AddonInternal {
|
||||
}
|
||||
}
|
||||
|
||||
async setUserDisabled(val) {
|
||||
async setUserDisabled(val, allowSystemAddons = false) {
|
||||
if (val == (this.userDisabled || this.softDisabled)) {
|
||||
return;
|
||||
}
|
||||
@ -587,7 +587,7 @@ class AddonInternal {
|
||||
if (this.inDatabase) {
|
||||
// System add-ons should not be user disabled, as there is no UI to
|
||||
// re-enable them.
|
||||
if (this.location.isSystem) {
|
||||
if (this.location.isSystem && !allowSystemAddons) {
|
||||
throw new Error(`Cannot disable system add-on ${this.id}`);
|
||||
}
|
||||
await XPIDatabase.updateAddonDisabledState(this, val);
|
||||
@ -980,12 +980,14 @@ AddonWrapper = class {
|
||||
return addon.softDisabled || addon.userDisabled;
|
||||
}
|
||||
|
||||
enable() {
|
||||
return addonFor(this).setUserDisabled(false);
|
||||
enable(options = {}) {
|
||||
const {allowSystemAddons = false} = options;
|
||||
return addonFor(this).setUserDisabled(false, allowSystemAddons);
|
||||
}
|
||||
|
||||
disable() {
|
||||
return addonFor(this).setUserDisabled(true);
|
||||
disable(options = {}) {
|
||||
const {allowSystemAddons = false} = options;
|
||||
return addonFor(this).setUserDisabled(true, allowSystemAddons);
|
||||
}
|
||||
|
||||
set softDisabled(val) {
|
||||
|
Loading…
Reference in New Issue
Block a user