michael@0: // -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: 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: /*** =================== INITIALISATION CODE =================== ***/ michael@0: michael@0: var kObserverService; michael@0: michael@0: // interface variables michael@0: var passwordmanager = null; michael@0: michael@0: // password-manager lists michael@0: var signons = []; michael@0: var rejects = []; michael@0: var deletedSignons = []; michael@0: var deletedRejects = []; michael@0: michael@0: var signonsTree; michael@0: var rejectsTree; michael@0: michael@0: var showingPasswords = false; michael@0: michael@0: function Startup() { michael@0: // xpconnect to password manager interfaces michael@0: passwordmanager = Components.classes["@mozilla.org/login-manager;1"] michael@0: .getService(Components.interfaces.nsILoginManager); michael@0: michael@0: // be prepared to reload the display if anything changes michael@0: kObserverService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService); michael@0: kObserverService.addObserver(signonReloadDisplay, "passwordmgr-storage-changed", false); michael@0: michael@0: signonsTree = document.getElementById("signonsTree"); michael@0: rejectsTree = document.getElementById("rejectsTree"); michael@0: } michael@0: michael@0: function Shutdown() { michael@0: kObserverService.removeObserver(signonReloadDisplay, "passwordmgr-storage-changed"); michael@0: } michael@0: michael@0: var signonReloadDisplay = { michael@0: observe: function(subject, topic, data) { michael@0: if (topic == "passwordmgr-storage-changed") { michael@0: switch (data) { michael@0: case "addLogin": michael@0: case "modifyLogin": michael@0: case "removeLogin": michael@0: case "removeAllLogins": michael@0: if (!signonsTree) { michael@0: return; michael@0: } michael@0: signons.length = 0; michael@0: LoadSignons(); michael@0: // apply the filter if needed michael@0: if (document.getElementById("filter") && document.getElementById("filter").value != "") { michael@0: _filterPasswords(); michael@0: } michael@0: break; michael@0: case "hostSavingEnabled": michael@0: case "hostSavingDisabled": michael@0: if (!rejectsTree) { michael@0: return; michael@0: } michael@0: rejects.length = 0; michael@0: if (lastRejectSortColumn == "hostname") { michael@0: lastRejectSortAscending = !lastRejectSortAscending; // prevents sort from being reversed michael@0: } michael@0: LoadRejects(); michael@0: break; michael@0: } michael@0: kObserverService.notifyObservers(null, "passwordmgr-dialog-updated", null); michael@0: } michael@0: } michael@0: } michael@0: michael@0: /*** =================== GENERAL CODE =================== ***/ michael@0: michael@0: function DeleteAllFromTree(tree, view, table, deletedTable, removeButton, removeAllButton) { michael@0: michael@0: // remove all items from table and place in deleted table michael@0: for (var i=0; i= 0; s--) { michael@0: var i = selections[s]; michael@0: deletedTable[deletedTable.length] = table[i]; michael@0: table[i] = null; michael@0: } michael@0: michael@0: // collapse list by removing all the null entries michael@0: for (var j=0; j=0 && updateSelection) { michael@0: for (var s=0; s= 0) { michael@0: tree.treeBoxObject.ensureRowIsVisible(selectedRow) michael@0: } michael@0: michael@0: return ascending; michael@0: } michael@0: michael@0: /** michael@0: * Case insensitive string comparator. michael@0: */ michael@0: function CompareLowerCase(first, second) { michael@0: var firstLower, secondLower; michael@0: michael@0: // Are we sorting nsILoginInfo entries or just strings? michael@0: if (first.hostname) { michael@0: firstLower = first.hostname.toLowerCase(); michael@0: secondLower = second.hostname.toLowerCase(); michael@0: } else { michael@0: firstLower = first.toLowerCase(); michael@0: secondLower = second.toLowerCase(); michael@0: } michael@0: michael@0: if (firstLower < secondLower) { michael@0: return -1; michael@0: } michael@0: michael@0: if (firstLower > secondLower) { michael@0: return 1; michael@0: } michael@0: michael@0: return 0; michael@0: }