Skip to content

Instantly share code, notes, and snippets.

@Dither
Last active November 22, 2016 19:23
Show Gist options
  • Save Dither/6ac4720251ea7f2bb2aa9a197814e0e8 to your computer and use it in GitHub Desktop.
Save Dither/6ac4720251ea7f2bb2aa9a197814e0e8 to your computer and use it in GitHub Desktop.
Enable permanent loading of webextensions from sources in about:debugging of latest Firefox Nightly
diff --git a/devtools/modules/devtools/client/aboutdebugging/components/addons/controls.js b/devtools/modules/devtools/client/aboutdebugging/components/addons/controls.js
--- a/devtools/modules/devtools/client/aboutdebugging/components/addons/controls.js
+++ b/devtools/modules/devtools/client/aboutdebugging/components/addons/controls.js
@@ -9,6 +9,8 @@
loader.lazyImporter(this, "AddonManager",
"resource://gre/modules/AddonManager.jsm");
+loader.lazyImporter(this, "AppConstants",
+ "resource://gre/modules/AppConstants.jsm");
const { Cc, Ci } = require("chrome");
const { createFactory, createClass, DOM: dom, PropTypes } =
@@ -65,8 +67,39 @@ module.exports = createClass({
});
},
+ loadAddonFromSources() {
+ this.setState({ installError: null });
+ let fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
+ fp.init(window,
+ Strings.GetStringFromName("selectAddonFromSources"),
+ Ci.nsIFilePicker.modeGetFolder);
+ let res = fp.show();
+ if (res == Ci.nsIFilePicker.returnCancel || !fp.file ||
+ !fp.file.isDirectory()) {
+ return;
+ }
+
+ AddonManager.installAddonFromSources(fp.file)
+ .catch(e => {
+ console.error(e);
+ this.setState({ installError: e.message });
+ });
+ },
+
render() {
let { debugDisabled } = this.props;
+ let signRequired = Services.prefs.getBoolPref(
+ "xpinstall.signatures.required");
+ let loadFromSourcesTooltip;
+ if (signRequired) {
+ if (AppConstants.RELEASE_OR_BETA) {
+ loadFromSourcesTooltip = Strings.GetStringFromName(
+ "loadPermanentlyAddon.releaseTooltip");
+ } else {
+ loadFromSourcesTooltip = Strings.GetStringFromName(
+ "loadPermanentlyAddon.signature");
+ }
+ }
return dom.div({ className: "addons-top" },
dom.div({ className: "addons-controls" },
@@ -90,7 +123,13 @@ module.exports = createClass({
dom.button({
id: "load-addon-from-file",
onClick: this.loadAddonFromFile,
- }, Strings.GetStringFromName("loadTemporaryAddon"))
+ }, Strings.GetStringFromName("loadTemporaryAddon")),
+ dom.button({
+ id: "load-addon-from-sources",
+ onClick: this.loadAddonFromSources,
+ disabled: signRequired,
+ title: loadFromSourcesTooltip
+ }, Strings.GetStringFromName("loadPermanentlyAddon"))
),
AddonsInstallError({ error: this.state.installError }));
}
diff --git a/en-US/locale/en-US/devtools/client/aboutdebugging.properties b/en-US/locale/en-US/devtools/client/aboutdebugging.properties
--- a/en-US/locale/en-US/devtools/client/aboutdebugging.properties
+++ b/en-US/locale/en-US/devtools/client/aboutdebugging.properties
@@ -45,6 +45,23 @@ moreInfo = more info
# load additional add-ons.
loadTemporaryAddon = Load Temporary Add-on
+# LOCALIZATION NOTE (loadPermanentlyAddon):
+# This string is displayed as a label of a button that allows the user to
+# load additional add-ons.
+loadPermanentlyAddon = Load Unpackaged Add-on Permanently
+
+# LOCALIZATION NOTE (loadPermanentlyAddon.releaseTooltip):
+# This string is displayed as a tooltip of the 'Load Unpackaged Add-on
+# Permanently' button when running on release build where this button
+# is always disabled.
+loadPermanentlyAddon.releaseTooltip = This features only work on non-release build like Developer Edition or Nightly
+
+# LOCALIZATION NOTE (loadPermanentlyAddon.signature):
+# This string is displayed as a tooltip of the 'Load Unpackaged Add-on
+# Permanently' button when the signature preference is turned on and the button
+# is disabled.
+loadPermanentlyAddon.signature = 'xpinstall.signatures.required' preference needs to be toggled to false
+
# LOCALIZATION NOTE (extensions):
# This string is displayed as a header above the list of loaded add-ons.
extensions = Extensions
@@ -54,6 +71,11 @@ extensions = Extensions
# the user clicks the 'Load Temporary Add-on' button
selectAddonFromFile2 = Select Manifest File or Package (.xpi)
+# LOCALIZATION NOTE (selectAddonFromSources):
+# This string is displayed as the title of the file picker that appears when
+# the user clicks the 'Load Unpacked Add-on Permanently' button
+selectAddonFromSources = Select Add-on directory
+
# LOCALIZATION NOTE (reload):
# This string is displayed as a label of the button that reloads a given addon.
reload = Reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment