Bug 1682939 - Remove nsISimpleEnumerator use from prplIProtocol. r=clokep
--- a/chat/components/public/prplIProtocol.idl
+++ b/chat/components/public/prplIProtocol.idl
@@ -1,16 +1,18 @@
/* 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/. */
#include "nsISupports.idl"
-#include "nsISimpleEnumerator.idl"
#include "imIAccount.idl"
+interface prplIPref;
+interface prplIUsernameSplit;
+
[scriptable, uuid(7d302db0-3813-4c51-8372-c7eb5fc9f3d3)]
interface prplIProtocol: nsISupports {
/**
* This method is used so that classes implementing several protocol
* plugins can know which protocol is desired for this instance.
*
* @param aId The prpl id.
*/
@@ -22,24 +24,24 @@ interface prplIProtocol: nsISupports {
// for the directory name for log storage.
readonly attribute AUTF8String normalizedName;
// returns a chrome URI pointing to a folder that contains the files:
// icon.png icon32.png and icon48.png
readonly attribute AUTF8String iconBaseURI;
/**
- * @returns an enumerator of prplIPref
+ * @returns an array of prplIPref
*/
- nsISimpleEnumerator getOptions();
+ Array<prplIPref> getOptions();
/**
- * @returns an enumerator of prplIUsernameSplit
+ * @returns an array of prplIUsernameSplit
*/
- nsISimpleEnumerator getUsernameSplit();
+ Array<prplIUsernameSplit> getUsernameSplit();
// descriptive text to put in the username input box when it is empty
readonly attribute AUTF8String usernameEmptyText;
// Use this function to avoid attempting to create duplicate accounts
boolean accountExists(in AUTF8String aName);
// These should all be stuff that some plugins can do and others can't.
--- a/chat/components/src/imAccounts.jsm
+++ b/chat/components/src/imAccounts.jsm
@@ -1,17 +1,16 @@
/* 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/. */
var EXPORTED_SYMBOLS = ["AccountsService"];
var {
ClassInfo,
- EmptyEnumerator,
nsSimpleEnumerator,
XPCOMUtils,
setTimeout,
clearTimeout,
executeSoon,
l10nHelper,
} = ChromeUtils.import("resource:///modules/imXPCOMUtils.jsm");
var { Services } = ChromeUtils.import("resource:///modules/imServices.jsm");
@@ -104,20 +103,20 @@ UnknownProtocol.prototype = {
},
get normalizedName() {
return this.name;
},
get iconBaseURI() {
return "chrome://chat/skin/prpl-unknown/";
},
getOptions() {
- return EmptyEnumerator;
+ return [];
},
getUsernameSplit() {
- return EmptyEnumerator;
+ return [];
},
get usernameEmptyText() {
return "";
},
getAccount(aKey, aName) {
throw Components.Exception("", Cr.NS_ERROR_NOT_IMPLEMENTED);
},
--- a/chat/modules/jsProtoHelper.jsm
+++ b/chat/modules/jsProtoHelper.jsm
@@ -1159,33 +1159,30 @@ var GenericProtocolPrototype = {
_getOptionDefault(aName) {
if (this.options && this.options.hasOwnProperty(aName)) {
return this.options[aName].default;
}
throw new Error(aName + " has no default value in " + this.id + ".");
},
getOptions() {
if (!this.options) {
- return EmptyEnumerator;
+ return [];
}
let purplePrefs = [];
for (let [name, option] of Object.entries(this.options)) {
purplePrefs.push(new purplePref(name, option));
}
- return new nsSimpleEnumerator(purplePrefs);
+ return purplePrefs;
},
getUsernameSplit() {
if (!this.usernameSplits || !this.usernameSplits.length) {
- return EmptyEnumerator;
+ return [];
}
-
- return new nsSimpleEnumerator(
- this.usernameSplits.map(split => new UsernameSplit(split))
- );
+ return this.usernameSplits.map(split => new UsernameSplit(split));
},
registerCommands() {
if (!this.commands) {
return;
}
this.commands.forEach(function(command) {
--- a/mail/components/im/content/am-im.js
+++ b/mail/components/im/content/am-im.js
@@ -93,22 +93,16 @@ var account = {
}
this.prefs = Services.prefs.getBranch(
"messenger.account." + this.account.id + ".options."
);
this.populateProtoSpecificBox();
},
- *getProtoOptions() {
- for (let option of this.proto.getOptions()) {
- yield option;
- }
- },
-
populateProtoSpecificBox() {
let attributes = {};
attributes[Ci.prplIPref.typeBool] = [
{ name: "wsm_persist", value: "true" },
{ name: "preftype", value: "bool" },
{ name: "genericattr", value: "true" },
];
attributes[Ci.prplIPref.typeInt] = [
@@ -118,17 +112,17 @@ var account = {
];
attributes[Ci.prplIPref.typeString] = attributes[Ci.prplIPref.typeList] = [
{ name: "wsm_persist", value: "true" },
{ name: "preftype", value: "wstring" },
{ name: "genericattr", value: "true" },
];
let haveOptions = accountOptionsHelper.addOptions(
"server.",
- this.getProtoOptions(),
+ this.proto.getOptions(),
attributes
);
let advanced = document.getElementById("advanced");
if (advanced.hidden && haveOptions) {
advanced.hidden = false;
// Force textbox XBL binding attachment by forcing layout,
// otherwise setFormElementValue from AccountManager.js sets
// properties that don't exist when restoring values.
--- a/mail/components/im/content/imAccountWizard.js
+++ b/mail/components/im/content/imAccountWizard.js
@@ -174,20 +174,17 @@ var accountWizard = {
document.getElementById("usernameInfo").textContent = usernameInfo;
var vbox = document.getElementById("userNameBox");
// remove anything that may be there for another protocol
while (vbox.hasChildNodes()) {
vbox.lastChild.remove();
}
- var splits = [];
- for (let split of this.getProtoUserSplits()) {
- splits.push(split);
- }
+ var splits = this.proto.getUsernameSplit();
var label = bundle.getString("accountUsername");
this.userNameBoxes = [this.insertUsernameField("name", label, vbox)];
this.userNameBoxes[0].emptyText = emptyText;
for (let i = 0; i < splits.length; ++i) {
this.userNameBoxes.push({ value: splits[i].separator });
label = bundle.getFormattedString("accountColon", [splits[i].label]);
@@ -219,17 +216,17 @@ var accountWizard = {
let alias = document.getElementById("alias");
alias.focus();
},
populateProtoSpecificBox() {
let haveOptions = accountOptionsHelper.addOptions(
this.proto.id + "-",
- this.getProtoOptions()
+ this.proto.getOptions()
);
document.getElementById("protoSpecificGroupbox").hidden = !haveOptions;
if (haveOptions) {
var bundle = document.getElementById("accountsBundle");
document.getElementById(
"protoSpecificCaption"
).textContent = bundle.getFormattedString("protoOptions", [
this.proto.name,
@@ -296,17 +293,17 @@ var accountWizard = {
/* FIXME
if (this.proto.newMailNotification)
rows.appendChild(this.createSummaryRow("Notify of new mails:",
this.getValue("newMailNotification")));
*/
var id = this.proto.id;
this.prefs = [];
- for (let opt of this.getProtoOptions()) {
+ for (let opt of this.proto.getOptions()) {
let name = opt.name;
let eltName = id + "-" + name;
let val = this.getValue(eltName);
// The value will be undefined if the proto specific groupbox has never been opened
if (val === undefined) {
continue;
}
switch (opt.type) {
@@ -430,22 +427,16 @@ var accountWizard = {
return undefined;
},
*getIter(aEnumerator) {
for (let iter of aEnumerator) {
yield iter;
}
},
- getProtoOptions() {
- return this.getIter(this.proto.getOptions());
- },
- getProtoUserSplits() {
- return this.getIter(this.proto.getUsernameSplit());
- },
/* Check for correctness and set URL for the "Get more protocols..."-link
* Stripped down code from preferences/themes.js
*/
setGetMoreProtocols() {
let prefURL = PREF_EXTENSIONS_GETMOREPROTOCOLSURL;
var getMore = document.getElementById("getMoreProtocols");
var showGetMore = false;