var gAS_Controller = { Cc: Components.classes, Ci: Components.interfaces, _password: null, _firstTime: true, init: function() { this._buildLoginList(); this.updateUI(); }, updateUI: function() { var cs = document.getElementById("credentialsSource"); var isCustom = cs.value == "custom"; document.getElementById("username").disabled = !isCustom; document.getElementById("password").disabled = !isCustom; document.getElementById("lastFmUsername").disabled = isCustom; }, passwordSyncTo: function() { var plaintext = document.getElementById("password").value; this._password = plaintext; if(plaintext.length > 0) { var as = this.Cc["@skrul.com/audioscrobbler-service;1"] .getService(this.Ci.sbIAudioscrobblerService); return as.hashPassword(plaintext); } else { return ""; } }, passwordSyncFrom: function() { // If this is the first time, we don't know what the password is yet if(this._firstTime) { this._firstTime = false; var value = document.getElementById("preference.password").value; // If the password pref is blank, return a blank so the textbox is // empty. Otherwise just put an arbitrary value in there to represent // the saved password if(value == "") { this._password = ""; } else { this._password = "xxxxxxxxxx"; } } return this._password; }, _buildLoginList: function() { var menulist = document.getElementById("lastFmUsername"); var usernames = []; var pm = this.Cc["@mozilla.org/passwordmanager;1"] .getService(this.Ci.nsIPasswordManager); var e = pm.enumerator; var i = 0; while(e.hasMoreElements()) { var password = e.getNext(); if(password.host == "last.fm" || password.host == "www.last.fm") { menulist.insertItemAt(i, password.user, password.user, ""); i++; } } if(i == 0) { menulist.insertItemAt(0, "", "-1", ""); menulist.selectedIndex = 0; } } }