toolkit/mozapps/preferences/removemp.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/preferences/removemp.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,56 @@
     1.4 +// -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 +
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +var gRemovePasswordDialog = {
    1.11 +  _token    : null,
    1.12 +  _bundle   : null,
    1.13 +  _prompt   : null,
    1.14 +  _okButton : null,
    1.15 +  _password : null,
    1.16 +  init: function ()
    1.17 +  {
    1.18 +    this._prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
    1.19 +                             .getService(Components.interfaces.nsIPromptService);
    1.20 +    this._bundle = document.getElementById("bundlePreferences");
    1.21 +
    1.22 +    this._okButton = document.documentElement.getButton("accept");
    1.23 +    this._okButton.label = this._bundle.getString("pw_remove_button");
    1.24 +    
    1.25 +    this._password = document.getElementById("password");
    1.26 +
    1.27 +    var pk11db = Components.classes["@mozilla.org/security/pk11tokendb;1"]
    1.28 +                           .getService(Components.interfaces.nsIPK11TokenDB);
    1.29 +    this._token = pk11db.getInternalKeyToken();
    1.30 +
    1.31 +    // Initialize the enabled state of the Remove button by checking the 
    1.32 +    // initial value of the password ("" should be incorrect).
    1.33 +    this.validateInput();
    1.34 +  },
    1.35 +  
    1.36 +  validateInput: function ()
    1.37 +  {
    1.38 +    this._okButton.disabled = !this._token.checkPassword(this._password.value);    
    1.39 +  },
    1.40 +  
    1.41 +  removePassword: function ()
    1.42 +  {
    1.43 +    if (this._token.checkPassword(this._password.value)) {
    1.44 +      this._token.changePassword(this._password.value, "");
    1.45 +      this._prompt.alert(window,
    1.46 +                         this._bundle.getString("pw_change_success_title"),
    1.47 +                         this._bundle.getString("pw_erased_ok") 
    1.48 +                         + " " + this._bundle.getString("pw_empty_warning"));
    1.49 +    }
    1.50 +    else {
    1.51 +      this._password.value = "";
    1.52 +      this._password.focus();
    1.53 +      this._prompt.alert(window, 
    1.54 +                         this._bundle.getString("pw_change_failed_title"),
    1.55 +                         this._bundle.getString("incorrect_pw"));
    1.56 +    }
    1.57 +  },
    1.58 +};
    1.59 +

mercurial