From c151888fe86213317cbf0ef06010c7d13840f62b Mon Sep 17 00:00:00 2001 From: Steve Chung Date: Mon, 5 Sep 2016 15:47:20 +0800 Subject: [PATCH] Bug 1288558 - Part 1: Simply move the functions/variables from passwordManagerCommon to passwordManager. r=MattN MozReview-Commit-ID: IbBu31XQjCB --HG-- extra : rebase_source : 0997f3410c15315dc2227f49294f7cb5b2e4175e --- .../passwordmgr/content/passwordManager.js | 226 ++++++++++++++++- .../passwordmgr/content/passwordManager.xul | 1 - .../content/passwordManagerCommon.js | 231 ------------------ toolkit/components/passwordmgr/jar.mn | 1 - 4 files changed, 223 insertions(+), 236 deletions(-) delete mode 100644 toolkit/components/passwordmgr/content/passwordManagerCommon.js diff --git a/toolkit/components/passwordmgr/content/passwordManager.js b/toolkit/components/passwordmgr/content/passwordManager.js index 8dc010d78117..88743526de23 100644 --- a/toolkit/components/passwordmgr/content/passwordManager.js +++ b/toolkit/components/passwordmgr/content/passwordManager.js @@ -3,9 +3,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /*** =================== SAVED SIGNONS CODE =================== ***/ +var { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components; Cu.import("resource://gre/modules/AppConstants.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm"); +Cu.import("resource://gre/modules/Services.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "DeferredTask", "resource://gre/modules/DeferredTask.jsm"); @@ -13,13 +15,78 @@ XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils", "resource://gre/modules/PlacesUtils.jsm"); var kSignonBundle; +var kObserverService; + +// interface variables +var passwordmanager = null; + var showingPasswords = false; + +// password-manager lists +var signons = []; +var deletedSignons = []; + +var signonsTree; +var signonReloadDisplay = { + observe: function(subject, topic, data) { + if (topic == "passwordmgr-storage-changed") { + switch (data) { + case "addLogin": + case "modifyLogin": + case "removeLogin": + case "removeAllLogins": + if (!signonsTree) { + return; + } + signons.length = 0; + LoadSignons(); + // apply the filter if needed + if (document.getElementById("filter") && document.getElementById("filter").value != "") { + _filterPasswords(); + } + break; + } + kObserverService.notifyObservers(null, "passwordmgr-dialog-updated", null); + } + } +} + +// Formatter for localization. var dateFormatter = new Intl.DateTimeFormat(undefined, { day: "numeric", month: "short", year: "numeric" }); var dateAndTimeFormatter = new Intl.DateTimeFormat(undefined, { day: "numeric", month: "short", year: "numeric", hour: "numeric", minute: "numeric" }); +function Startup() { + // xpconnect to password manager interfaces + passwordmanager = Components.classes["@mozilla.org/login-manager;1"] + .getService(Components.interfaces.nsILoginManager); + + // be prepared to reload the display if anything changes + kObserverService = Components.classes["@mozilla.org/observer-service;1"] + .getService(Components.interfaces.nsIObserverService); + kObserverService.addObserver(signonReloadDisplay, "passwordmgr-storage-changed", false); + + signonsTree = document.getElementById("signonsTree"); +} + + +// TODO: Integragte to SignonsStartup? +function HandleTreeColumnClick(sortFunction, event) { + if (event.target.nodeName != "treecol" || event.button != 0) { + return; + } + + let sortField = event.target.getAttribute("data-field-name"); + if (!sortField) { + return; + } + + sortFunction(sortField); + Services.telemetry.getKeyedHistogramById("PWMGR_MANAGE_SORTED").add(sortField); +} + function SignonsStartup() { kSignonBundle = document.getElementById("signonBundle"); document.getElementById("togglePasswords").label = kSignonBundle.getString("showPasswords"); @@ -44,6 +111,10 @@ function SignonsStartup() { FocusFilterBox(); } +function Shutdown() { + kObserverService.removeObserver(signonReloadDisplay, "passwordmgr-storage-changed"); +} + function setFilter(aFilterString) { document.getElementById("filter").value = aFilterString; _filterPasswords(); @@ -160,6 +231,73 @@ var signonsTreeView = { }, }; +function SortTree(tree, view, table, column, lastSortColumn, lastSortAscending, updateSelection) { + + // remember which item was selected so we can restore it after the sort + var selections = GetTreeSelections(tree); + var selectedNumber = selections.length ? table[selections[0]].number : -1; + + // determine if sort is to be ascending or descending + var ascending = (column == lastSortColumn) ? !lastSortAscending : true; + + function compareFunc(a, b) { + var valA, valB; + switch (column) { + case "hostname": + var realmA = a.httpRealm; + var realmB = b.httpRealm; + realmA = realmA == null ? "" : realmA.toLowerCase(); + realmB = realmB == null ? "" : realmB.toLowerCase(); + + valA = a[column].toLowerCase() + realmA; + valB = b[column].toLowerCase() + realmB; + break; + case "username": + case "password": + valA = a[column].toLowerCase(); + valB = b[column].toLowerCase(); + break; + + default: + valA = a[column]; + valB = b[column]; + } + + if (valA < valB) + return -1; + if (valA > valB) + return 1; + return 0; + } + + // do the sort + table.sort(compareFunc); + if (!ascending) + table.reverse(); + + // restore the selection + var selectedRow = -1; + if (selectedNumber>=0 && updateSelection) { + for (var s=0; s= 0) { + tree.treeBoxObject.ensureRowIsVisible(selectedRow) + } + + return ascending; +} function LoadSignons() { // loads signons into table @@ -193,6 +331,25 @@ function LoadSignons() { return true; } +function GetTreeSelections(tree) { + var selections = []; + var select = tree.view.selection; + if (select) { + var count = select.getRangeCount(); + var min = new Object(); + var max = new Object(); + for (var i=0; i= 0; s--) { + var i = selections[s]; + deletedTable[deletedTable.length] = table[i]; + table[i] = null; + } + + // collapse list by removing all the null entries + for (var j=0; j -