toolkit/components/passwordmgr/nsLoginInfo.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:803326c560f7
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
6 const Cc = Components.classes;
7 const Ci = Components.interfaces;
8
9 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
10
11 function nsLoginInfo() {}
12
13 nsLoginInfo.prototype = {
14
15 classID : Components.ID("{0f2f347c-1e4f-40cc-8efd-792dea70a85e}"),
16 QueryInterface: XPCOMUtils.generateQI([Ci.nsILoginInfo, Ci.nsILoginMetaInfo]),
17
18 //
19 // nsILoginInfo interfaces...
20 //
21
22 hostname : null,
23 formSubmitURL : null,
24 httpRealm : null,
25 username : null,
26 password : null,
27 usernameField : null,
28 passwordField : null,
29
30 init : function (aHostname, aFormSubmitURL, aHttpRealm,
31 aUsername, aPassword,
32 aUsernameField, aPasswordField) {
33 this.hostname = aHostname;
34 this.formSubmitURL = aFormSubmitURL;
35 this.httpRealm = aHttpRealm;
36 this.username = aUsername;
37 this.password = aPassword;
38 this.usernameField = aUsernameField;
39 this.passwordField = aPasswordField;
40 },
41
42 matches : function (aLogin, ignorePassword) {
43 if (this.hostname != aLogin.hostname ||
44 this.httpRealm != aLogin.httpRealm ||
45 this.username != aLogin.username)
46 return false;
47
48 if (!ignorePassword && this.password != aLogin.password)
49 return false;
50
51 // If either formSubmitURL is blank (but not null), then match.
52 if (this.formSubmitURL != "" && aLogin.formSubmitURL != "" &&
53 this.formSubmitURL != aLogin.formSubmitURL)
54 return false;
55
56 // The .usernameField and .passwordField values are ignored.
57
58 return true;
59 },
60
61 equals : function (aLogin) {
62 if (this.hostname != aLogin.hostname ||
63 this.formSubmitURL != aLogin.formSubmitURL ||
64 this.httpRealm != aLogin.httpRealm ||
65 this.username != aLogin.username ||
66 this.password != aLogin.password ||
67 this.usernameField != aLogin.usernameField ||
68 this.passwordField != aLogin.passwordField)
69 return false;
70
71 return true;
72 },
73
74 clone : function() {
75 let clone = Cc["@mozilla.org/login-manager/loginInfo;1"].
76 createInstance(Ci.nsILoginInfo);
77 clone.init(this.hostname, this.formSubmitURL, this.httpRealm,
78 this.username, this.password,
79 this.usernameField, this.passwordField);
80
81 // Copy nsILoginMetaInfo props
82 clone.QueryInterface(Ci.nsILoginMetaInfo);
83 clone.guid = this.guid;
84 clone.timeCreated = this.timeCreated;
85 clone.timeLastUsed = this.timeLastUsed;
86 clone.timePasswordChanged = this.timePasswordChanged;
87 clone.timesUsed = this.timesUsed;
88
89 return clone;
90 },
91
92 //
93 // nsILoginMetaInfo interfaces...
94 //
95
96 guid : null,
97 timeCreated : null,
98 timeLastUsed : null,
99 timePasswordChanged : null,
100 timesUsed : null
101
102 }; // end of nsLoginInfo implementation
103
104 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([nsLoginInfo]);

mercurial