diff options
author | Moonchild <mcwerewolf@wolfbeast.com> | 2019-03-13 07:49:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-13 07:49:07 +0100 |
commit | bf0413359245579e9509146d42cd5547e35da695 (patch) | |
tree | 8218d4f60d9eccacbf42df8cb88094a082d401b4 /toolkit/components/webextensions/ext-management.js | |
parent | 51b821b3fdc5a7eab2369cb6a6680598a6264b08 (diff) | |
parent | 709bc24e9110eba12f94cfcb8db00a8338ac4098 (diff) | |
download | UXP-bf0413359245579e9509146d42cd5547e35da695.tar UXP-bf0413359245579e9509146d42cd5547e35da695.tar.gz UXP-bf0413359245579e9509146d42cd5547e35da695.tar.lz UXP-bf0413359245579e9509146d42cd5547e35da695.tar.xz UXP-bf0413359245579e9509146d42cd5547e35da695.zip |
Merge pull request #998 from MoonchildProductions/master
Merge master into Sync-weave
Diffstat (limited to 'toolkit/components/webextensions/ext-management.js')
-rw-r--r-- | toolkit/components/webextensions/ext-management.js | 109 |
1 files changed, 0 insertions, 109 deletions
diff --git a/toolkit/components/webextensions/ext-management.js b/toolkit/components/webextensions/ext-management.js deleted file mode 100644 index 59a7959d7..000000000 --- a/toolkit/components/webextensions/ext-management.js +++ /dev/null @@ -1,109 +0,0 @@ -/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */ -/* vim: set sts=2 sw=2 et tw=80: */ -"use strict"; - -const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; - -XPCOMUtils.defineLazyGetter(this, "strBundle", function() { - const stringSvc = Cc["@mozilla.org/intl/stringbundle;1"].getService(Ci.nsIStringBundleService); - return stringSvc.createBundle("chrome://global/locale/extensions.properties"); -}); -XPCOMUtils.defineLazyModuleGetter(this, "AddonManager", - "resource://gre/modules/AddonManager.jsm"); -XPCOMUtils.defineLazyServiceGetter(this, "promptService", - "@mozilla.org/embedcomp/prompt-service;1", - "nsIPromptService"); - -function _(key, ...args) { - if (args.length) { - return strBundle.formatStringFromName(key, args, args.length); - } - return strBundle.GetStringFromName(key); -} - -function installType(addon) { - if (addon.temporarilyInstalled) { - return "development"; - } else if (addon.foreignInstall) { - return "sideload"; - } else if (addon.isSystem) { - return "other"; - } - return "normal"; -} - -extensions.registerSchemaAPI("management", "addon_parent", context => { - let {extension} = context; - return { - management: { - getSelf: function() { - return new Promise((resolve, reject) => AddonManager.getAddonByID(extension.id, addon => { - try { - let m = extension.manifest; - let extInfo = { - id: extension.id, - name: addon.name, - shortName: m.short_name || "", - description: addon.description || "", - version: addon.version, - mayDisable: !!(addon.permissions & AddonManager.PERM_CAN_DISABLE), - enabled: addon.isActive, - optionsUrl: addon.optionsURL || "", - permissions: Array.from(extension.permissions).filter(perm => { - return !extension.whiteListedHosts.pat.includes(perm); - }), - hostPermissions: extension.whiteListedHosts.pat, - installType: installType(addon), - }; - if (addon.homepageURL) { - extInfo.homepageUrl = addon.homepageURL; - } - if (addon.updateURL) { - extInfo.updateUrl = addon.updateURL; - } - if (m.icons) { - extInfo.icons = Object.keys(m.icons).map(key => { - return {size: Number(key), url: m.icons[key]}; - }); - } - - resolve(extInfo); - } catch (err) { - reject(err); - } - })); - }, - - uninstallSelf: function(options) { - return new Promise((resolve, reject) => { - if (options && options.showConfirmDialog) { - let message = _("uninstall.confirmation.message", extension.name); - if (options.dialogMessage) { - message = `${options.dialogMessage}\n${message}`; - } - let title = _("uninstall.confirmation.title", extension.name); - let buttonFlags = promptService.BUTTON_POS_0 * promptService.BUTTON_TITLE_IS_STRING + - promptService.BUTTON_POS_1 * promptService.BUTTON_TITLE_IS_STRING; - let button0Title = _("uninstall.confirmation.button-0.label"); - let button1Title = _("uninstall.confirmation.button-1.label"); - let response = promptService.confirmEx(null, title, message, buttonFlags, button0Title, button1Title, null, null, {value: 0}); - if (response == 1) { - return reject({message: "User cancelled uninstall of extension"}); - } - } - AddonManager.getAddonByID(extension.id, addon => { - let canUninstall = Boolean(addon.permissions & AddonManager.PERM_CAN_UNINSTALL); - if (!canUninstall) { - return reject({message: "The add-on cannot be uninstalled"}); - } - try { - addon.uninstall(); - } catch (err) { - return reject(err); - } - }); - }); - }, - }, - }; -}); |