This file is indexed.

/usr/share/xul-ext/password-editor/content/SavedPasswordEditor.jsm is in xul-ext-password-editor 2.9.6-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*
    Saved Password Editor, extension for Gecko applications
    Copyright (C) 2015  Daniel Dawson <danielcdawson@gmail.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

const Cc = Components.classes,
      Ci = Components.interfaces,
      Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");

var EXPORTED_SYMBOLS = ["SavedPasswordEditor"];

XPCOMUtils.defineLazyGetter(
  this, "prefs", function ()
    Cc["@mozilla.org/preferences-service;1"].
      getService(Ci.nsIPrefService).
      getBranch("extensions.savedpasswordeditor."));
XPCOMUtils.defineLazyServiceGetter(
  this, "pwdSvc",
  "@mozilla.org/login-manager;1", "nsILoginManager");
XPCOMUtils.defineLazyServiceGetter(
  this, "stringSvc",
  "@mozilla.org/intl/stringbundle;1", "nsIStringBundleService");
XPCOMUtils.defineLazyServiceGetter(
  this, "alertsSvc",
  "@mozilla.org/alerts-service;1", "nsIAlertsService");
XPCOMUtils.defineLazyServiceGetter(
  this, "promptSvc",
  "@mozilla.org/embedcomp/prompt-service;1", "nsIPromptService");
XPCOMUtils.defineLazyGetter(
  this, "genStrBundle", function ()
    stringSvc.createBundle(
      "chrome://savedpasswordeditor/locale/spe.properties"));
XPCOMUtils.defineLazyGetter(
  this, "pmoStrBundle", function ()
    stringSvc.createBundle(
      "chrome://savedpasswordeditor/locale/pwdmgrOverlay.properties"));

function el (aWindow, aId) aWindow.document.getElementById(aId)

function showAlert (aMsg) {
  alertsSvc.showAlertNotification(
    "chrome://savedpasswordeditor/skin/key32.png",
    genStrBundle.GetStringFromName("savedpasswordeditor"), aMsg);
}

var SavedPasswordEditor = {
  _deleting: false,
  _signonMap: {},

  openSavedPasswords: function () {
    var spWin = Cc["@mozilla.org/appshell/window-mediator;1"].
                  getService(Ci.nsIWindowMediator).
                  getMostRecentWindow("Toolkit:PasswordManager");
    if (spWin)
      spWin.focus();
    else
      Cc["@mozilla.org/embedcomp/window-watcher;1"].
        getService(Ci.nsIWindowWatcher).
        openWindow(
          null, "chrome://passwordmgr/content/passwordManager.xul", "",
          "chrome,titlebar,toolbar,centerscreen,resizable", null);
  },

  contextMenuShowing: function (aElement) {
    if (aElement instanceof Ci.nsIDOMHTMLInputElement && aElement.form) {
      var form = aElement.form;
    } else
      return false;

    var curDoc = aElement.ownerDocument;
    var curLocation = curDoc.defaultView.location;
    var hostname = curLocation.protocol + "//" + curLocation.host;
    var passwordField = null;
    for (var i = 0; i < form.elements.length; i++) {
      let element = form.elements[i];
      if (element instanceof Ci.nsIDOMHTMLInputElement
          && element.type.toLowerCase() == "password") {
        passwordField = element;
        break;
      }
    }
    if (!passwordField) return false;

    var usernameField = null;
    for (i = i - 1; i >= 0; i--) {
      let element = form.elements[i];
      if (!element instanceof Ci.nsIDOMHTMLInputElement) continue;
      let elType = (element.getAttribute("type") || "").toLowerCase();
      if (!elType || elType == "text" || elType == "email" || elType == "url"
          || elType == "tel" || elType == "number") {
        usernameField = element;
        break;
      }
    }
    if (!usernameField) return false;

    var formAction = form.action;
    var res;
    if (formAction && formAction.startsWith("javascript:"))
      res = "javascript:";
    else {
      res = formAction ? /^([0-9-_A-Za-z]+:\/\/[^/]+)\//.exec(formAction)
                           : [ null, hostname ];
      if (!res) return false;
      res = res[1];
    }

    this.curInfo = {
      hostname: hostname,
      formSubmitURL: res,
      username: usernameField.value,
      password: passwordField.value,
      usernameField: usernameField.name,
      passwordField: passwordField.name,
    };
    return true;
  },

  saveLoginInfo: function (aWindow, aEvt) {
    function _finish (aNewSignon) {
      if (!aNewSignon) return;
      try {
        let newSignon = Cc["@mozilla.org/login-manager/loginInfo;1"].
                        createInstance(Ci.nsILoginInfo);
        newSignon.init(aNewSignon.hostname, aNewSignon.formSubmitURL,
                       aNewSignon.httpRealm, aNewSignon.username,
                       aNewSignon.password, aNewSignon.usernameField,
                       aNewSignon.passwordField);
        pwdSvc.addLogin(newSignon);
        showAlert(genStrBundle.GetStringFromName("logininfosaved"));
      } catch (e) {
        promptSvc.alert(
          aWindow,
          genStrBundle.GetStringFromName("error"),
          pmoStrBundle.formatStringFromName("badnewentry", [e.message], 1));
      }
    }

    var ret = { newSignon: null, callback: _finish, parentWindow: null };
    aWindow.openDialog(
      "chrome://savedpasswordeditor/content/pwdedit.xul", "",
      "centerscreen,dependent,dialog,chrome",
      [this.curInfo], 0, false, ret);
    this.curInfo = null;
  },

  _finishEdit: function (aNewSignon, aParentWindow) {
    if (!aNewSignon) return;

    var newSignon = Cc["@mozilla.org/login-manager/loginInfo;1"].
                    createInstance(Ci.nsILoginInfo);
    newSignon.init(aNewSignon.hostname, aNewSignon.formSubmitURL,
                   aNewSignon.httpRealm, aNewSignon.username,
                   aNewSignon.password, aNewSignon.usernameField,
                   aNewSignon.passwordField);
    try {
      pwdSvc.modifyLogin(SavedPasswordEditor.oldSignon, newSignon);
      showAlert(genStrBundle.GetStringFromName("logininfochanged"));
    } catch (e) {
      promptSvc.alert(
        aParentWindow,
        genStrBundle.GetStringFromName("error"),
        genStrBundle.formatStringFromName("failed", [e.message], 1));
    }
  },

  _handleDisambigSelection: function (aEvt) {
    var spe = SavedPasswordEditor, target = aEvt.target,
        window = target.ownerDocument.defaultView,
        dp = el(window, "savedpasswordeditor-disambig-popup");

    if (spe._deleting) {
      try {
        pwdSvc.removeLogin(spe._signonMap[target.label]);
        showAlert(genStrBundle.GetStringFromName("logininfodeleted"));
      } catch (e) {
        promptSvc.alert(
          window,
          genStrBundle.GetStringFromName("error"),
          genStrBundle.formatStringFromName("failed", [e.message], 1));
      }
    } else {
      SavedPasswordEditor.oldSignon = spe._signonMap[target.label];
      window.openDialog(
        "chrome://savedpasswordeditor/content/pwdedit.xul", "",
        "centerscreen,dependent,dialog,chrome",
        [SavedPasswordEditor.oldSignon], 1, false,
        { newSignon: null, callback: spe._finishEdit, parentWindow: window });
    }

    spe._deleting = false;
  },

  _showDisambig: function (aWindow, aSignons) {
    var dp = el(aWindow, "savedpasswordeditor-disambig-popup");
    while (dp.hasChildNodes()) dp.removeChild(dp.firstChild);

    this._signonMap = {};
    for each (let signon in aSignons) {
      this._signonMap[signon.username] = signon;
      let mi = aWindow.document.createElement("menuitem");
      mi.setAttribute("label", signon.username);
      dp.appendChild(mi);
    }

    dp.addEventListener("command", this._handleDisambigSelection, false);
    var spe = this;
    dp.addEventListener(
      "popuphidden",
      function _phHandler () {
        dp.removeEventListener("command", spe._handleDisambigSelection, false);
        dp.removeEventListener("popuphidden", _phHandler, false);
      },
      false);

    var bo = el(aWindow, "contentAreaContextMenu").boxObject,
        x = bo.x, y = bo.y;
    aWindow.setTimeout(
      function () { dp.openPopup(null, null, x, y, true, false, null); }, 1);
  },

  editLoginInfo: function (aWindow) {
    var signons = pwdSvc.findLogins({}, this.curInfo.hostname,
                                    this.curInfo.formSubmitURL, null);
    this.curInfo = null;
    this._deleting = false;

    if (signons.length == 0) {
      promptSvc.alert(
        aWindow,
        genStrBundle.GetStringFromName("error"),
        genStrBundle.GetStringFromName("nologinstoedit"));
    } else if (signons.length == 1) {
      SavedPasswordEditor.oldSignon = signons[0];
      aWindow.openDialog(
        "chrome://savedpasswordeditor/content/pwdedit.xul", "",
        "centerscreen,dependent,dialog,chrome",
        [signons[0]], 1, false,
        { newSignon: null, callback: this._finishEdit,
          parentWindow: aWindow });
    } else
      this._showDisambig(aWindow, signons);
  },

  deleteLoginInfo: function (aWindow) {
    var signons = pwdSvc.findLogins({}, this.curInfo.hostname,
                                    this.curInfo.formSubmitURL, null);
    this.curInfo = null;
    this._deleting = true;

    if (signons.length == 0) {
      promptSvc.alert(
        aWindow,
        genStrBundle.GetStringFromName("error"),
        genStrBundle.GetStringFromName("nologinstodelete"));
    } else if (signons.length == 1) {
      try {
        let res;
        if (prefs.getBoolPref("confirm_ctxmenu_delete")) {
          let cs = { value: false };
          res = promptSvc.confirmEx(
            aWindow, genStrBundle.GetStringFromName("deletinglogininfo"),
            genStrBundle.GetStringFromName("deletingareyousure"),
            promptSvc.STD_YES_NO_BUTTONS | promptSvc.BUTTON_POS_1_DEFAULT
            | promptSvc.BUTTON_DELAY_ENABLE, null, null, null,
            genStrBundle.GetStringFromName("deletingdontask"), cs);
          if (res == 0 && cs.value)
            prefs.setBoolPref("confirm_ctxmenu_delete", false);
        } else
          res = 0;

        if (res == 0) {
          pwdSvc.removeLogin(signons[0]);
          showAlert(genStrBundle.GetStringFromName("logininfodeleted"));
        }
      } catch (e) {
        promptSvc.alert(
          aWindow,
          genStrBundle.GetStringFromName("error"),
          genStrBundle.formatStringFromName("failed", [e.message], 1));
      }
    } else
      this._showDisambig(aWindow, signons);
  },
};