michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: const Cu = Components.utils; michael@0: michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: Cu.import("resource://gre/modules/AddonManager.jsm"); michael@0: michael@0: var gAddon = null; michael@0: michael@0: // If the user enables the add-on through some other UI close this window michael@0: var EnableListener = { michael@0: onEnabling: function EnableListener_onEnabling(aAddon) { michael@0: if (aAddon.id == gAddon.id) michael@0: window.close(); michael@0: } michael@0: } michael@0: AddonManager.addAddonListener(EnableListener); michael@0: michael@0: function initialize() { michael@0: // About URIs don't implement nsIURL so we have to find the query string michael@0: // manually michael@0: let spec = document.location.href; michael@0: let pos = spec.indexOf("?"); michael@0: let query = ""; michael@0: if (pos >= 0) michael@0: query = spec.substring(pos + 1); michael@0: michael@0: // Just assume the query is "id=" michael@0: let id = query.substring(3); michael@0: if (!id) { michael@0: window.location = "about:blank"; michael@0: return; michael@0: } michael@0: michael@0: let bundle = Services.strings.createBundle("chrome://mozapps/locale/extensions/newaddon.properties"); michael@0: michael@0: AddonManager.getAddonByID(id, function initialize_getAddonByID(aAddon) { michael@0: // If the add-on doesn't exist or it is already enabled or it cannot be michael@0: // enabled then this UI is useless, just close it. This shouldn't normally michael@0: // happen unless session restore restores the tab michael@0: if (!aAddon || !aAddon.userDisabled || michael@0: !(aAddon.permissions & AddonManager.PERM_CAN_ENABLE)) { michael@0: window.close(); michael@0: return; michael@0: } michael@0: michael@0: gAddon = aAddon; michael@0: michael@0: document.getElementById("addon-info").setAttribute("type", aAddon.type); michael@0: michael@0: let icon = document.getElementById("icon"); michael@0: if (aAddon.icon64URL) michael@0: icon.src = aAddon.icon64URL; michael@0: else if (aAddon.iconURL) michael@0: icon.src = aAddon.iconURL; michael@0: michael@0: let name = bundle.formatStringFromName("name", [aAddon.name, aAddon.version], michael@0: 2); michael@0: document.getElementById("name").value = name; michael@0: michael@0: if (aAddon.creator) { michael@0: let creator = bundle.formatStringFromName("author", [aAddon.creator], 1); michael@0: document.getElementById("author").value = creator; michael@0: } else { michael@0: document.getElementById("author").hidden = true; michael@0: } michael@0: michael@0: let uri = "getResourceURI" in aAddon ? aAddon.getResourceURI() : null; michael@0: let locationLabel = document.getElementById("location"); michael@0: if (uri instanceof Ci.nsIFileURL) { michael@0: let location = bundle.formatStringFromName("location", [uri.file.path], 1); michael@0: locationLabel.value = location; michael@0: locationLabel.setAttribute("tooltiptext", location); michael@0: } else { michael@0: document.getElementById("location").hidden = true; michael@0: } michael@0: michael@0: var event = document.createEvent("Events"); michael@0: event.initEvent("AddonDisplayed", true, true); michael@0: document.dispatchEvent(event); michael@0: }); michael@0: } michael@0: michael@0: function unload() { michael@0: AddonManager.removeAddonListener(EnableListener); michael@0: } michael@0: michael@0: function continueClicked() { michael@0: AddonManager.removeAddonListener(EnableListener); michael@0: michael@0: if (document.getElementById("allow").checked) { michael@0: gAddon.userDisabled = false; michael@0: michael@0: if (gAddon.pendingOperations & AddonManager.PENDING_ENABLE) { michael@0: document.getElementById("allow").disabled = true; michael@0: document.getElementById("buttonDeck").selectedPanel = document.getElementById("restartPanel"); michael@0: return; michael@0: } michael@0: } michael@0: michael@0: window.close(); michael@0: } michael@0: michael@0: function restartClicked() { michael@0: let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"]. michael@0: createInstance(Ci.nsISupportsPRBool); michael@0: Services.obs.notifyObservers(cancelQuit, "quit-application-requested", michael@0: "restart"); michael@0: if (cancelQuit.data) michael@0: return; // somebody canceled our quit request michael@0: michael@0: window.close(); michael@0: michael@0: let appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"]. michael@0: getService(Components.interfaces.nsIAppStartup); michael@0: appStartup.quit(Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestart); michael@0: } michael@0: michael@0: function cancelClicked() { michael@0: gAddon.userDisabled = true; michael@0: AddonManager.addAddonListener(EnableListener); michael@0: michael@0: document.getElementById("allow").disabled = false; michael@0: document.getElementById("buttonDeck").selectedPanel = document.getElementById("continuePanel"); michael@0: }