1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/content/list.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,165 @@ 1.4 +// -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; 1.11 +const kDialog = "dialog"; 1.12 + 1.13 +/** 1.14 + * This dialog can be initialized from parameters supplied via window.arguments 1.15 + * or it can be used to display blocklist notification and blocklist blocked 1.16 + * installs via nsIDialogParamBlock as is done by nsIExtensionManager. 1.17 + * 1.18 + * When using this dialog with window.arguments it must be opened modally, the 1.19 + * caller can inspect the user action after the dialog closes by inspecting the 1.20 + * value of the |result| parameter on this object which is set to the dlgtype 1.21 + * of the button used to close the dialog. 1.22 + * 1.23 + * window.arguments[0] is an array of strings to display in the tree. If the 1.24 + * array is empty the tree will not be displayed. 1.25 + * window.arguments[1] a JS Object with the following properties: 1.26 + * 1.27 + * title: A title string, to be displayed in the title bar of the dialog. 1.28 + * message1: A message string, displayed above the addon list 1.29 + * message2: A message string, displayed below the addon list 1.30 + * message3: A bolded message string, displayed below the addon list 1.31 + * moreInfoURL: An url for displaying more information 1.32 + * iconClass : Can be one of the following values (default is alert-icon) 1.33 + * alert-icon, error-icon, or question-icon 1.34 + * 1.35 + * If no value is supplied for message1, message2, message3, or moreInfoURL, 1.36 + * the element is not displayed. 1.37 + * 1.38 + * buttons: { 1.39 + * accept: { label: "A Label for the Accept button", 1.40 + * focused: true }, 1.41 + * cancel: { label: "A Label for the Cancel button" }, 1.42 + * ... 1.43 + * }, 1.44 + * 1.45 + * result: The dlgtype of button that was used to dismiss the dialog. 1.46 + */ 1.47 + 1.48 +"use strict"; 1.49 + 1.50 +var gButtons = { }; 1.51 + 1.52 +function init() { 1.53 + var de = document.documentElement; 1.54 + var items = []; 1.55 + if (window.arguments[0] instanceof Components.interfaces.nsIDialogParamBlock) { 1.56 + // This is a warning about a blocklisted item the user is trying to install 1.57 + var args = window.arguments[0]; 1.58 + var softblocked = args.GetInt(0) == 1 ? true : false; 1.59 + 1.60 + var extensionsBundle = document.getElementById("extensionsBundle"); 1.61 + try { 1.62 + var formatter = Components.classes["@mozilla.org/toolkit/URLFormatterService;1"] 1.63 + .getService(Components.interfaces.nsIURLFormatter); 1.64 + var url = formatter.formatURLPref("extensions.blocklist.detailsURL"); 1.65 + } 1.66 + catch (e) { } 1.67 + 1.68 + var params = { 1.69 + moreInfoURL: url, 1.70 + }; 1.71 + 1.72 + if (softblocked) { 1.73 + params.title = extensionsBundle.getString("softBlockedInstallTitle"); 1.74 + params.message1 = extensionsBundle.getFormattedString("softBlockedInstallMsg", 1.75 + [args.GetString(0)]); 1.76 + var accept = de.getButton("accept"); 1.77 + accept.label = extensionsBundle.getString("softBlockedInstallAcceptLabel"); 1.78 + accept.accessKey = extensionsBundle.getString("softBlockedInstallAcceptKey"); 1.79 + de.getButton("cancel").focus(); 1.80 + document.addEventListener("dialogaccept", allowInstall, false); 1.81 + } 1.82 + else { 1.83 + params.title = extensionsBundle.getString("blocklistedInstallTitle2"); 1.84 + params.message1 = extensionsBundle.getFormattedString("blocklistedInstallMsg2", 1.85 + [args.GetString(0)]); 1.86 + de.buttons = "accept"; 1.87 + de.getButton("accept").focus(); 1.88 + } 1.89 + } 1.90 + else { 1.91 + items = window.arguments[0]; 1.92 + params = window.arguments[1]; 1.93 + } 1.94 + 1.95 + var addons = document.getElementById("addonsChildren"); 1.96 + if (items.length > 0) 1.97 + document.getElementById("addonsTree").hidden = false; 1.98 + 1.99 + // Fill the addons list 1.100 + for (var item of items) { 1.101 + var treeitem = document.createElementNS(kXULNS, "treeitem"); 1.102 + var treerow = document.createElementNS(kXULNS, "treerow"); 1.103 + var treecell = document.createElementNS(kXULNS, "treecell"); 1.104 + treecell.setAttribute("label", item); 1.105 + treerow.appendChild(treecell); 1.106 + treeitem.appendChild(treerow); 1.107 + addons.appendChild(treeitem); 1.108 + } 1.109 + 1.110 + // Set the messages 1.111 + var messages = ["message1", "message2", "message3"]; 1.112 + for (let messageEntry of messages) { 1.113 + if (messageEntry in params) { 1.114 + var message = document.getElementById(messageEntry); 1.115 + message.hidden = false; 1.116 + message.appendChild(document.createTextNode(params[messageEntry])); 1.117 + } 1.118 + } 1.119 + 1.120 + document.getElementById("infoIcon").className = 1.121 + params["iconClass"] ? "spaced " + params["iconClass"] : "spaced alert-icon"; 1.122 + 1.123 + if ("moreInfoURL" in params && params["moreInfoURL"]) { 1.124 + message = document.getElementById("moreInfo"); 1.125 + message.value = extensionsBundle.getString("moreInfoText"); 1.126 + message.setAttribute("href", params["moreInfoURL"]); 1.127 + document.getElementById("moreInfoBox").hidden = false; 1.128 + } 1.129 + 1.130 + // Set the window title 1.131 + if ("title" in params) 1.132 + document.title = params.title; 1.133 + 1.134 + // Set up the buttons 1.135 + if ("buttons" in params) { 1.136 + gButtons = params.buttons; 1.137 + var buttonString = ""; 1.138 + for (var buttonType in gButtons) 1.139 + buttonString += "," + buttonType; 1.140 + de.buttons = buttonString.substr(1); 1.141 + for (buttonType in gButtons) { 1.142 + var button = de.getButton(buttonType); 1.143 + button.label = gButtons[buttonType].label; 1.144 + if (gButtons[buttonType].focused) 1.145 + button.focus(); 1.146 + document.addEventListener(kDialog + buttonType, handleButtonCommand, true); 1.147 + } 1.148 + } 1.149 +} 1.150 + 1.151 +function shutdown() { 1.152 + for (var buttonType in gButtons) 1.153 + document.removeEventListener(kDialog + buttonType, handleButtonCommand, true); 1.154 +} 1.155 + 1.156 +function allowInstall() { 1.157 + var args = window.arguments[0]; 1.158 + args.SetInt(1, 1); 1.159 +} 1.160 + 1.161 +/** 1.162 + * Watch for the user hitting one of the buttons to dismiss the dialog 1.163 + * and report the result back to the caller through the |result| property on 1.164 + * the arguments object. 1.165 + */ 1.166 +function handleButtonCommand(event) { 1.167 + window.arguments[1].result = event.type.substr(kDialog.length); 1.168 +}