mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-25 03:05:34 +00:00
Bug 1382689 Fix "Remove" button on details page for a legacy extension r=rhelmer
Also updated addon listeners in extensions.js to use Set instead of arrays and added a way to listen to AddonListener events on any addon. MozReview-Commit-ID: Ev3kJgcr30G --HG-- extra : rebase_source : 1420093c1b69dccd4ff39cc3b0ede35cf9079efa
This commit is contained in:
parent
a8bd195a49
commit
f734dc2e06
@ -107,7 +107,7 @@ XPCOMUtils.defineLazyPreferenceGetter(this, "legacyWarningExceptions",
|
||||
raw => raw.split(","));
|
||||
XPCOMUtils.defineLazyPreferenceGetter(this, "legacyExtensionsEnabled",
|
||||
PREF_LEGACY_ENABLED, true,
|
||||
() => gLegacyView.refresh());
|
||||
() => gLegacyView.refreshVisibility());
|
||||
|
||||
document.addEventListener("load", initialize, true);
|
||||
window.addEventListener("unload", shutdown);
|
||||
@ -483,7 +483,7 @@ if (window.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
|
||||
var gEventManager = {
|
||||
_listeners: {},
|
||||
_installListeners: [],
|
||||
_installListeners: new Set(),
|
||||
|
||||
initialize() {
|
||||
const ADDON_EVENTS = ["onEnabling", "onEnabled", "onDisabling",
|
||||
@ -569,32 +569,22 @@ var gEventManager = {
|
||||
|
||||
registerAddonListener(aListener, aAddonId) {
|
||||
if (!(aAddonId in this._listeners))
|
||||
this._listeners[aAddonId] = [];
|
||||
else if (this._listeners[aAddonId].indexOf(aListener) != -1)
|
||||
return;
|
||||
this._listeners[aAddonId].push(aListener);
|
||||
this._listeners[aAddonId] = new Set();
|
||||
this._listeners[aAddonId].add(aListener);
|
||||
},
|
||||
|
||||
unregisterAddonListener(aListener, aAddonId) {
|
||||
if (!(aAddonId in this._listeners))
|
||||
return;
|
||||
var index = this._listeners[aAddonId].indexOf(aListener);
|
||||
if (index == -1)
|
||||
return;
|
||||
this._listeners[aAddonId].splice(index, 1);
|
||||
this._listeners[aAddonId].delete(aListener);
|
||||
},
|
||||
|
||||
registerInstallListener(aListener) {
|
||||
if (this._installListeners.indexOf(aListener) != -1)
|
||||
return;
|
||||
this._installListeners.push(aListener);
|
||||
this._installListeners.add(aListener);
|
||||
},
|
||||
|
||||
unregisterInstallListener(aListener) {
|
||||
var i = this._installListeners.indexOf(aListener);
|
||||
if (i == -1)
|
||||
return;
|
||||
this._installListeners.splice(i, 1);
|
||||
this._installListeners.delete(aListener);
|
||||
},
|
||||
|
||||
delegateAddonEvent(aEvent, aParams) {
|
||||
@ -602,10 +592,9 @@ var gEventManager = {
|
||||
if (!(addon.id in this._listeners))
|
||||
return;
|
||||
|
||||
var listeners = this._listeners[addon.id];
|
||||
for (let listener of listeners) {
|
||||
function tryListener(listener) {
|
||||
if (!(aEvent in listener))
|
||||
continue;
|
||||
return;
|
||||
try {
|
||||
listener[aEvent].apply(listener, aParams);
|
||||
} catch (e) {
|
||||
@ -613,6 +602,13 @@ var gEventManager = {
|
||||
Cu.reportError(e);
|
||||
}
|
||||
}
|
||||
|
||||
for (let listener of this._listeners[addon.id]) {
|
||||
tryListener(listener);
|
||||
}
|
||||
for (let listener of this._listeners["ANY"]) {
|
||||
tryListener(listener);
|
||||
}
|
||||
},
|
||||
|
||||
delegateInstallEvent(aEvent, aParams) {
|
||||
@ -2788,7 +2784,17 @@ var gLegacyView = {
|
||||
|
||||
document.getElementById("legacy-learnmore").href = SUPPORT_URL + "webextensions";
|
||||
|
||||
this.refresh();
|
||||
gEventManager.registerAddonListener(this, "ANY");
|
||||
|
||||
this.refreshVisibility();
|
||||
},
|
||||
|
||||
shutdown() {
|
||||
gEventManager.unregisterAddonListener(this, "ANY");
|
||||
},
|
||||
|
||||
onUninstalled() {
|
||||
this.refreshVisibility();
|
||||
},
|
||||
|
||||
async show(type, request) {
|
||||
@ -2824,7 +2830,7 @@ var gLegacyView = {
|
||||
return null;
|
||||
},
|
||||
|
||||
async refresh() {
|
||||
async refreshVisibility() {
|
||||
if (legacyExtensionsEnabled) {
|
||||
this._categoryItem.disabled = true;
|
||||
return;
|
||||
@ -2852,6 +2858,16 @@ var gLegacyView = {
|
||||
this._categoryItem.disabled = true;
|
||||
}
|
||||
},
|
||||
|
||||
getListItemForID(aId) {
|
||||
var listitem = this._listBox.firstChild;
|
||||
while (listitem) {
|
||||
if (listitem.getAttribute("status") == "installed" && listitem.mAddon.id == aId)
|
||||
return listitem;
|
||||
listitem = listitem.nextSibling;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
var gListView = {
|
||||
|
@ -111,7 +111,7 @@ add_task(async function() {
|
||||
// The legacy category does not watch for new installs since new
|
||||
// legacy extensions cannot be installed while legacy extensions
|
||||
// are disabled, so manually refresh it here.
|
||||
await mgrWin.gLegacyView.refresh();
|
||||
await mgrWin.gLegacyView.refreshVisibility();
|
||||
|
||||
// Make sure we re-render the extensions list, after that we should
|
||||
// still just have the original two entries.
|
||||
@ -156,7 +156,7 @@ add_task(async function() {
|
||||
});
|
||||
|
||||
// The entry on the left side should now read "Unsupported"
|
||||
await mgrWin.gLegacyView.refresh();
|
||||
await mgrWin.gLegacyView.refreshVisibility();
|
||||
is(catItem.disabled, false, "Legacy category is visible");
|
||||
is(catItem.getAttribute("name"), get_string("type.unsupported.name"),
|
||||
"Category label with unsigned extensions is correct");
|
||||
@ -186,7 +186,7 @@ add_task(async function() {
|
||||
});
|
||||
|
||||
// The name of the pane should go back to "Legacy Extensions"
|
||||
await mgrWin.gLegacyView.refresh();
|
||||
await mgrWin.gLegacyView.refreshVisibility();
|
||||
is(catItem.disabled, false, "Legacy category is visible");
|
||||
is(catItem.getAttribute("name"), get_string("type.legacy.name"),
|
||||
"Category label with no unsigned extensions is correct");
|
||||
|
Loading…
Reference in New Issue
Block a user