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