161
* Merge |src| into this, using the keys of the |nameValuePairs|
162
* associative array as the properties to overwrite in |this|.
164
merge : function(src, nameValuePairs) {
165
for (var propertyName in nameValuePairs) {
166
// Simple sanity check on our input
167
var obj = this.propertyBelongsTo(propertyName, this, this.manualconf, this.autoconf);
168
// If obj == null then we don't understand this property, so ignore it.
170
obj[propertyName] = nameValuePairs[propertyName];
174
getPropertyValue : function(propertyName) {
175
var obj = this.propertyBelongsTo(propertyName, this, this.manualconf, this.autoconf);
176
return obj ? obj[propertyName] : "";
180
* Checks if |propertyName| is a known writable property of the classes Proxy,
181
* ManualConf, or AutoConf (excepting readOnly properties). |x|, |y|, or |z|
182
* is returned, respectively, based on |propertyName's| membership in one of those
183
* classes, If the property is unknown or read-only, null is returned.
185
propertyBelongsTo : function(propertyName, x, y, z) {
186
function validType(str) {
187
return str == "string" || str == "boolean" || str == "number";
189
if (this.readOnlyProperties.indexOf(propertyName) > -1) return null;
191
if (validType(typeof(this[propertyName])))
193
else if (validType(typeof(this.manualconf[propertyName])))
195
else if (validType(typeof(this.autoconf[propertyName])))
201
* Use as a static-style method on this class.
202
* Returns a |Proxy| instance based on the |nameValuePairs|
203
* associative array. Each key in the array is expected to be
204
* a property of either Proxy, ManualConf, or AutoConf, otherwise
207
fromAssociateArray : function(nameValuePairs) {
208
var doc = CC["@mozilla.org/xml/xml-document;1"].createInstance(CI.nsIDOMDocument),
209
proxyElem = doc.createElement("proxy"),
210
manualConfElem = doc.createElement("manualconf"),
211
autoConfElem = doc.createElement("autoconf");
213
proxyElem.appendChild(manualConfElem);
214
proxyElem.appendChild(autoConfElem);
215
for (var i in nameValuePairs) {
216
// Simple sanity check on our input
217
var elem = this.propertyBelongsTo(i, proxyElem, manualConfElem, autoConfElem);
218
/* If elem == null then we don't understand this property, so ignore it.
219
However, even if an unrecognized property were to slip by us here,
220
the |Proxy.fromDOM()| code would ignore it anyway. This check just prevents us from
221
building an arbitrarily large DOM element.
224
elem.setAttribute(i, nameValuePairs[i] == null ? "" : nameValuePairs[i]);
226
// Turn it on by default
227
if (!nameValuePairs["enabled"])
228
proxyElem.setAttribute("enabled", "true");
230
// If a socks version was specified and either isSocks is true or no isSocks parameter was specified,
232
if (nameValuePairs["socksversion"] && (nameValuePairs["isSocks"] == "true" || !nameValuePairs["isSocks"])) {
233
nameValuePairs["isSocks"] = true;
234
manualConfElem.setAttribute("isSocks", "true");
235
manualConfElem.setAttribute("socksversion", parseInt(nameValuePairs["socksversion"]));
237
// If a URL was specified and either mode was specified as auto or no mode was specified,
238
// then set mode to auto
239
if (nameValuePairs["url"] && (nameValuePairs["mode"] == "auto" || !nameValuePairs["mode"])) {
240
nameValuePairs["mode"] = "auto";
241
proxyElem.setAttribute("mode", "auto");
243
// Change the mode to "direct" if we don't have enough info for "manual" and "auto"
244
var noManual = (nameValuePairs["host"] && !nameValuePairs["port"]) ||
245
(!nameValuePairs["host"] && nameValuePairs["port"]);
246
if (!nameValuePairs["url"] && noManual) {
247
nameValuePairs["mode"] = "direct";
248
proxyElem.setAttribute("mode", "direct");
249
dump("No host and port specified, and no PAC URL specified; setting proxy mode to direct.\n");
252
// Set a default name if one wasn't specified. Don't set the default name based
253
// on the mode because proxies like these will end up with different names:
254
// proxy:host=my.proxy.server.com&port=999
255
// proxy:host=my.proxy.server.com&port=999&mode=direct
256
if (!nameValuePairs["name"]) {
258
nameValuePairs["name"] = nameValuePairs["url"] ? nameValuePairs["url"] : this.fp.getMessage("new.proxy");
260
nameValuePairs["name"] = nameValuePairs["host"] + ":" + nameValuePairs["port"];
261
proxyElem.setAttribute("name", nameValuePairs["name"]);
263
this.fromDOM(proxyElem, true);
158
266
set proxyDNS(e) {
159
267
this._proxyDNS = e;
160
268
this.manualconf._makeProxy();