Skip to content

Commit

Permalink
Trick to get addonFor() from XPIProvider.jsm
Browse files Browse the repository at this point in the history
  • Loading branch information
Infocatcher committed Oct 23, 2017
1 parent 5d2c2f4 commit 83afe89
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions Toggle_Restartless_Add-ons/toggleRestartlessAddons.js
Expand Up @@ -186,10 +186,15 @@ function setNewDisabled(addon) {
_log("Let's try set addon.userDisabled using raw hack");
let g = Components.utils.import("resource://gre/modules/addons/XPIProvider.jsm", {});
// See "set userDisabled(val)"
let addonFor = g.eval("addonFor");
let rawAddon = addonFor(addon);
//rawAddon.userDisabled = newDis;
g.XPIProvider.updateAddonDisabledState(rawAddon, newDis);
if("eval" in g) {
let addonFor = g.eval("addonFor");
let rawAddon = addonFor(addon);
//rawAddon.userDisabled = newDis;
g.XPIProvider.updateAddonDisabledState(rawAddon, newDis);
}
else { // Firefox 57+? See https://forum.mozilla-russia.org/viewtopic.php?pid=745272#p745272
updateAddonDisabledState(addon, newDis);
}
}
}
var realDis = addon.userDisabled;
Expand Down Expand Up @@ -226,6 +231,20 @@ function getNewDisabled(addon) {
}
return newDis;
}
function updateAddonDisabledState(addon, newDis) {
var nsvo = Components.utils.import("resource://gre/modules/addons/XPIProvider.jsm", {});
var key = "_cbToggleRestartlessAddonsData";
var url = URL.createObjectURL(new Blob([
"XPIProvider.updateAddonDisabledState(addonFor(this." + key + "[0]), this." + key + "[1]); delete this." + key + ";"
]));
addDestructor(function() {
URL.revokeObjectURL(url);
});
(updateAddonDisabledState = function(addon, newDis) {
nsvo[key] = [addon, newDis];
Services.scriptloader.loadSubScript(url, nsvo);
})(addon, newDis);
}
function setDisabled(mi, disabled) {
var askToActivate = "STATE_ASK_TO_ACTIVATE" in AddonManager && disabled == AddonManager.STATE_ASK_TO_ACTIVATE;
var cl = mi.classList;
Expand Down

0 comments on commit 83afe89

Please sign in to comment.