Source code

Revision control

Other Tools

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
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
6
const { XPCOMUtils } = ChromeUtils.import(
8
);
9
10
ChromeUtils.defineModuleGetter(
11
this,
12
"LoginHelper",
14
);
15
16
function nsLoginInfo() {}
17
18
nsLoginInfo.prototype = {
19
classID: Components.ID("{0f2f347c-1e4f-40cc-8efd-792dea70a85e}"),
20
QueryInterface: ChromeUtils.generateQI([
21
Ci.nsILoginInfo,
22
Ci.nsILoginMetaInfo,
23
]),
24
25
//
26
// nsILoginInfo interfaces...
27
//
28
29
origin: null,
30
formActionOrigin: null,
31
httpRealm: null,
32
username: null,
33
password: null,
34
usernameField: null,
35
passwordField: null,
36
37
get displayOrigin() {
38
let displayOrigin = this.origin;
39
try {
40
let uri = Services.io.newURI(this.origin);
41
// Fallback to handle file: URIs
42
displayOrigin = uri.displayHostPort || this.origin;
43
} catch (ex) {
44
// Fallback to this.origin set above in case a URI can't be contructed e.g.
46
}
47
48
if (this.httpRealm === null) {
49
return displayOrigin;
50
}
51
52
return `${displayOrigin} (${this.httpRealm})`;
53
},
54
55
/**
56
* @deprecated Use `origin` instead.
57
*/
58
get hostname() {
59
return this.origin;
60
},
61
62
/**
63
* @deprecated Use `formActionOrigin` instead.
64
*/
65
get formSubmitURL() {
66
return this.formActionOrigin;
67
},
68
69
init(
70
aOrigin,
71
aFormActionOrigin,
72
aHttpRealm,
73
aUsername,
74
aPassword,
75
aUsernameField = "",
76
aPasswordField = ""
77
) {
78
this.origin = aOrigin;
79
this.formActionOrigin = aFormActionOrigin;
80
this.httpRealm = aHttpRealm;
81
this.username = aUsername;
82
this.password = aPassword;
83
this.usernameField = aUsernameField || "";
84
this.passwordField = aPasswordField || "";
85
},
86
87
matches(aLogin, ignorePassword) {
88
return LoginHelper.doLoginsMatch(this, aLogin, {
89
ignorePassword,
90
});
91
},
92
93
equals(aLogin) {
94
if (
95
this.origin != aLogin.origin ||
96
this.formActionOrigin != aLogin.formActionOrigin ||
97
this.httpRealm != aLogin.httpRealm ||
98
this.username != aLogin.username ||
99
this.password != aLogin.password ||
100
this.usernameField != aLogin.usernameField ||
101
this.passwordField != aLogin.passwordField
102
) {
103
return false;
104
}
105
106
return true;
107
},
108
109
clone() {
110
let clone = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(
111
Ci.nsILoginInfo
112
);
113
clone.init(
114
this.origin,
115
this.formActionOrigin,
116
this.httpRealm,
117
this.username,
118
this.password,
119
this.usernameField,
120
this.passwordField
121
);
122
123
// Copy nsILoginMetaInfo props
124
clone.QueryInterface(Ci.nsILoginMetaInfo);
125
clone.guid = this.guid;
126
clone.timeCreated = this.timeCreated;
127
clone.timeLastUsed = this.timeLastUsed;
128
clone.timePasswordChanged = this.timePasswordChanged;
129
clone.timesUsed = this.timesUsed;
130
131
return clone;
132
},
133
134
//
135
// nsILoginMetaInfo interfaces...
136
//
137
138
guid: null,
139
timeCreated: null,
140
timeLastUsed: null,
141
timePasswordChanged: null,
142
timesUsed: null,
143
}; // end of nsLoginInfo implementation
144
145
const EXPORTED_SYMBOLS = ["nsLoginInfo"];