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: var gRemovePasswordDialog = { michael@0: _token : null, michael@0: _bundle : null, michael@0: _prompt : null, michael@0: _okButton : null, michael@0: _password : null, michael@0: init: function () michael@0: { michael@0: this._prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] michael@0: .getService(Components.interfaces.nsIPromptService); michael@0: this._bundle = document.getElementById("bundlePreferences"); michael@0: michael@0: this._okButton = document.documentElement.getButton("accept"); michael@0: this._okButton.label = this._bundle.getString("pw_remove_button"); michael@0: michael@0: this._password = document.getElementById("password"); michael@0: michael@0: var pk11db = Components.classes["@mozilla.org/security/pk11tokendb;1"] michael@0: .getService(Components.interfaces.nsIPK11TokenDB); michael@0: this._token = pk11db.getInternalKeyToken(); michael@0: michael@0: // Initialize the enabled state of the Remove button by checking the michael@0: // initial value of the password ("" should be incorrect). michael@0: this.validateInput(); michael@0: }, michael@0: michael@0: validateInput: function () michael@0: { michael@0: this._okButton.disabled = !this._token.checkPassword(this._password.value); michael@0: }, michael@0: michael@0: removePassword: function () michael@0: { michael@0: if (this._token.checkPassword(this._password.value)) { michael@0: this._token.changePassword(this._password.value, ""); michael@0: this._prompt.alert(window, michael@0: this._bundle.getString("pw_change_success_title"), michael@0: this._bundle.getString("pw_erased_ok") michael@0: + " " + this._bundle.getString("pw_empty_warning")); michael@0: } michael@0: else { michael@0: this._password.value = ""; michael@0: this._password.focus(); michael@0: this._prompt.alert(window, michael@0: this._bundle.getString("pw_change_failed_title"), michael@0: this._bundle.getString("incorrect_pw")); michael@0: } michael@0: }, michael@0: }; michael@0: