summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/nsLoginInfo.js
blob: d6ea86446fbed35d85c741e64582736374142f14 (plain)
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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;

Cu.import("resource://gre/modules/XPCOMUtils.jsm");

XPCOMUtils.defineLazyModuleGetter(this, "LoginHelper",
                                  "resource://gre/modules/LoginHelper.jsm");


function nsLoginInfo() {}

nsLoginInfo.prototype = {

  classID : Components.ID("{0f2f347c-1e4f-40cc-8efd-792dea70a85e}"),
  QueryInterface: XPCOMUtils.generateQI([Ci.nsILoginInfo, Ci.nsILoginMetaInfo]),

  //
  // nsILoginInfo interfaces...
  //

  hostname      : null,
  formSubmitURL : null,
  httpRealm     : null,
  username      : null,
  password      : null,
  usernameField : null,
  passwordField : null,

  init : function (aHostname, aFormSubmitURL, aHttpRealm,
                   aUsername,      aPassword,
                   aUsernameField, aPasswordField) {
    this.hostname      = aHostname;
    this.formSubmitURL = aFormSubmitURL;
    this.httpRealm     = aHttpRealm;
    this.username      = aUsername;
    this.password      = aPassword;
    this.usernameField = aUsernameField;
    this.passwordField = aPasswordField;
  },

  matches(aLogin, ignorePassword) {
    return LoginHelper.doLoginsMatch(this, aLogin, {
      ignorePassword,
    });
  },

  equals : function (aLogin) {
    if (this.hostname      != aLogin.hostname      ||
        this.formSubmitURL != aLogin.formSubmitURL ||
        this.httpRealm     != aLogin.httpRealm     ||
        this.username      != aLogin.username      ||
        this.password      != aLogin.password      ||
        this.usernameField != aLogin.usernameField ||
        this.passwordField != aLogin.passwordField)
      return false;

    return true;
  },

  clone : function() {
    let clone = Cc["@mozilla.org/login-manager/loginInfo;1"].
                createInstance(Ci.nsILoginInfo);
    clone.init(this.hostname, this.formSubmitURL, this.httpRealm,
               this.username, this.password,
               this.usernameField, this.passwordField);

    // Copy nsILoginMetaInfo props
    clone.QueryInterface(Ci.nsILoginMetaInfo);
    clone.guid = this.guid;
    clone.timeCreated = this.timeCreated;
    clone.timeLastUsed = this.timeLastUsed;
    clone.timePasswordChanged = this.timePasswordChanged;
    clone.timesUsed = this.timesUsed;

    return clone;
  },

  //
  // nsILoginMetaInfo interfaces...
  //

  guid : null,
  timeCreated : null,
  timeLastUsed : null,
  timePasswordChanged : null,
  timesUsed : null

}; // end of nsLoginInfo implementation

this.NSGetFactory = XPCOMUtils.generateNSGetFactory([nsLoginInfo]);