Skip to content
Permalink
Browse files

Trick to get addonFor() from XPIProvider.jsm

  • Loading branch information...
Infocatcher committed Oct 23, 2017
1 parent 5d2c2f4 commit 83afe891d63bbbc91eecb54489eaaf879e737d87
Showing with 23 additions and 4 deletions.
  1. +23 −4 Toggle_Restartless_Add-ons/toggleRestartlessAddons.js
@@ -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;
@@ -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;

0 comments on commit 83afe89

Please sign in to comment.
You can’t perform that action at this time.