browser/components/preferences/security.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
     8 var gSecurityPane = {
     9   _pane: null,
    11   /**
    12    * Initializes master password UI.
    13    */
    14   init: function ()
    15   {
    16     this._pane = document.getElementById("paneSecurity");
    17     this._initMasterPasswordUI();
    18   },
    20   // ADD-ONS
    22   /*
    23    * Preferences:
    24    *
    25    * xpinstall.whitelist.required
    26    * - true if a site must be added to a site whitelist before extensions
    27    *   provided by the site may be installed from it, false if the extension
    28    *   may be directly installed after a confirmation dialog
    29    */
    31   /**
    32    * Enables/disables the add-ons Exceptions button depending on whether
    33    * or not add-on installation warnings are displayed.
    34    */
    35   readWarnAddonInstall: function ()
    36   {
    37     var warn = document.getElementById("xpinstall.whitelist.required");
    38     var exceptions = document.getElementById("addonExceptions");
    40     exceptions.disabled = !warn.value;
    42     // don't override the preference value
    43     return undefined;
    44   },
    46   /**
    47    * Displays the exceptions lists for add-on installation warnings.
    48    */
    49   showAddonExceptions: function ()
    50   {
    51     var bundlePrefs = document.getElementById("bundlePreferences");
    53     var params = this._addonParams;
    54     if (!params.windowTitle || !params.introText) {
    55       params.windowTitle = bundlePrefs.getString("addons_permissions_title");
    56       params.introText = bundlePrefs.getString("addonspermissionstext");
    57     }
    59     document.documentElement.openWindow("Browser:Permissions",
    60                                         "chrome://browser/content/preferences/permissions.xul",
    61                                         "", params);
    62   },
    64   /**
    65    * Parameters for the add-on install permissions dialog.
    66    */
    67   _addonParams:
    68     {
    69       blockVisible: false,
    70       sessionVisible: false,
    71       allowVisible: true,
    72       prefilledHost: "",
    73       permissionType: "install"
    74     },
    76   // PASSWORDS
    78   /*
    79    * Preferences:
    80    *
    81    * signon.rememberSignons
    82    * - true if passwords are remembered, false otherwise
    83    */
    85   /**
    86    * Enables/disables the Exceptions button used to configure sites where
    87    * passwords are never saved. When browser is set to start in Private
    88    * Browsing mode, the "Remember passwords" UI is useless, so we disable it.
    89    */
    90   readSavePasswords: function ()
    91   {
    92     var pref = document.getElementById("signon.rememberSignons");
    93     var excepts = document.getElementById("passwordExceptions");
    95     if (PrivateBrowsingUtils.permanentPrivateBrowsing) {
    96       document.getElementById("savePasswords").disabled = true;
    97       excepts.disabled = true;
    98       return false;
    99     } else {
   100       excepts.disabled = !pref.value;
   101       // don't override pref value in UI
   102       return undefined;
   103     }
   104   },
   106   /**
   107    * Displays a dialog in which the user can view and modify the list of sites
   108    * where passwords are never saved.
   109    */
   110   showPasswordExceptions: function ()
   111   {
   112     document.documentElement.openWindow("Toolkit:PasswordManagerExceptions",
   113                                         "chrome://passwordmgr/content/passwordManagerExceptions.xul",
   114                                         "", null);
   115   },
   117   /**
   118    * Initializes master password UI: the "use master password" checkbox, selects
   119    * the master password button to show, and enables/disables it as necessary.
   120    * The master password is controlled by various bits of NSS functionality, so
   121    * the UI for it can't be controlled by the normal preference bindings.
   122    */
   123   _initMasterPasswordUI: function ()
   124   {
   125     var noMP = !this._masterPasswordSet();
   127     var button = document.getElementById("changeMasterPassword");
   128     button.disabled = noMP;
   130     var checkbox = document.getElementById("useMasterPassword");
   131     checkbox.checked = !noMP;
   132   },
   134   /**
   135    * Returns true if the user has a master password set and false otherwise.
   136    */
   137   _masterPasswordSet: function ()
   138   {
   139     const Cc = Components.classes, Ci = Components.interfaces;
   140     var secmodDB = Cc["@mozilla.org/security/pkcs11moduledb;1"].
   141                    getService(Ci.nsIPKCS11ModuleDB);
   142     var slot = secmodDB.findSlotByName("");
   143     if (slot) {
   144       var status = slot.status;
   145       var hasMP = status != Ci.nsIPKCS11Slot.SLOT_UNINITIALIZED &&
   146                   status != Ci.nsIPKCS11Slot.SLOT_READY;
   147       return hasMP;
   148     } else {
   149       // XXX I have no bloody idea what this means
   150       return false;
   151     }
   152   },
   154   /**
   155    * Enables/disables the master password button depending on the state of the
   156    * "use master password" checkbox, and prompts for master password removal if
   157    * one is set.
   158    */
   159   updateMasterPasswordButton: function ()
   160   {
   161     var checkbox = document.getElementById("useMasterPassword");
   162     var button = document.getElementById("changeMasterPassword");
   163     button.disabled = !checkbox.checked;
   165     // unchecking the checkbox should try to immediately remove the master
   166     // password, because it's impossible to non-destructively remove the master
   167     // password used to encrypt all the passwords without providing it (by
   168     // design), and it would be extremely odd to pop up that dialog when the
   169     // user closes the prefwindow and saves his settings
   170     if (!checkbox.checked)
   171       this._removeMasterPassword();
   172     else
   173       this.changeMasterPassword();
   175     this._initMasterPasswordUI();
   177     // We might want to hide sync's password engine.
   178     gSyncPane.updateWeavePrefs();
   179   },
   181   /**
   182    * Displays the "remove master password" dialog to allow the user to remove
   183    * the current master password.  When the dialog is dismissed, master password
   184    * UI is automatically updated.
   185    */
   186   _removeMasterPassword: function ()
   187   {
   188     const Cc = Components.classes, Ci = Components.interfaces;
   189     var secmodDB = Cc["@mozilla.org/security/pkcs11moduledb;1"].
   190                    getService(Ci.nsIPKCS11ModuleDB);
   191     if (secmodDB.isFIPSEnabled) {
   192       var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"].
   193                           getService(Ci.nsIPromptService);
   194       var bundle = document.getElementById("bundlePreferences");
   195       promptService.alert(window,
   196                           bundle.getString("pw_change_failed_title"),
   197                           bundle.getString("pw_change2empty_in_fips_mode"));
   198     }
   199     else {
   200       document.documentElement.openSubDialog("chrome://mozapps/content/preferences/removemp.xul",
   201                                              "", null);
   202     }
   203     this._initMasterPasswordUI();
   204   },
   206   /**
   207    * Displays a dialog in which the master password may be changed.
   208    */
   209   changeMasterPassword: function ()
   210   {
   211     document.documentElement.openSubDialog("chrome://mozapps/content/preferences/changemp.xul",
   212                                            "", null);
   213     this._initMasterPasswordUI();
   214   },
   216   /**
   217    * Shows the sites where the user has saved passwords and the associated login
   218    * information.
   219    */
   220   showPasswords: function ()
   221   {
   222     document.documentElement.openWindow("Toolkit:PasswordManager",
   223                                         "chrome://passwordmgr/content/passwordManager.xul",
   224                                         "", null);
   225   }
   227 };

mercurial