Bug 1719413 - Add NntpProtocolInfo.jsm to implement nsIMsgProtocolInfo. r=mkmelin

Differential Revision: https://phabricator.services.mozilla.com/D128041

--HG--
extra : amend_source : 429876a1d85a9a27a882e3b28626de3fcc794287
This commit is contained in:
Ping Chen 2021-10-11 13:01:57 +03:00
Родитель a47e2023ab
Коммит 211efa7f52
5 изменённых файлов: 91 добавлений и 4 удалений

Просмотреть файл

@ -57,6 +57,11 @@ var nntpJSModules = [
"{dc4ad42f-bc98-4193-a469-0cfa95ed9bcb}",
"@mozilla.org/messenger/server;1?type=nntp",
],
[
"NntpProtocolInfo",
"{7d71db22-0624-4c9f-8d70-dea6ab3ff076}",
"@mozilla.org/messenger/protocol/info;1?type=nntp",
],
];
NntpModuleLoader.prototype = {

Просмотреть файл

@ -0,0 +1,81 @@
/* 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 EXPORTED_SYMBOLS = ["NntpProtocolInfo"];
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
/**
* @implements {nsIMsgProtocolInfo}
*/
class NntpProtocolInfo {
QueryInterface = ChromeUtils.generateQI(["nsIMsgProtocolInfo"]);
serverIID = Components.ID("{dc4ad42f-bc98-4193-a469-0cfa95ed9bcb}");
requiresUsername = false;
preflightPrettyNameWithEmailAddress = false;
canDelete = true;
canLoginAtStartUp = true;
canDuplicate = true;
canGetMessages = false;
canGetIncomingMessages = false;
defaultDoBiff = false;
showComposeMsgLink = false;
foldersCreatedAsync = false;
get defaultLocalPath() {
let file = this._getFileValue("mail.newsrc_root-rel", "mail.newsrc_root");
if (!file) {
file = Services.dirsvc.get("NewsD", Ci.nsIFile);
this._setFileValue("mail.newsrc_root-rel", "mail.newsrc_root", file);
}
if (!file.exists()) {
file.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0o775);
}
return file;
}
set defaultLocalPath(value) {
this._setFileValue("mail.root.nntp-rel", "mail.root.nntp", value);
}
getDefaultServerPort(isSecure) {
return isSecure
? Ci.nsINntpUrl.DEFAULT_NNTPS_PORT
: Ci.nsINntpUrl.DEFAULT_NNTP_PORT;
}
_getFileValue(relPrefName, absPrefName) {
try {
return Services.prefs.getComplexValue(relPrefName, Ci.nsIRelativeFilePref)
.file;
} catch (e) {
try {
let file = Services.prefs.getComplexValue(absPrefName, Ci.nsIFile);
Services.prefs.setComplexValue(relPrefName, Ci.nsIRelativeFilePref, {
QueryInterface: ChromeUtils.generateQI(["nsIRelativeFilePref"]),
file,
relativeToKey: "ProfD",
});
return file;
} catch (e) {
return null;
}
}
}
_setFileValue(relPrefName, absPrefName, file) {
Services.prefs.setComplexValue(relPrefName, Ci.nsIRelativeFilePref, {
QueryInterface: ChromeUtils.generateQI(["nsIRelativeFilePref"]),
file,
relativeToKey: "ProfD",
});
Services.prefs.setComplexValue(absPrefName, Ci.nsIFile, file);
}
}
NntpProtocolInfo.prototype.classID = Components.ID(
"{7d71db22-0624-4c9f-8d70-dea6ab3ff076}"
);

Просмотреть файл

@ -27,6 +27,7 @@ EXTRA_JS_MODULES += [
"NntpModuleLoader.jsm",
"NntpNewsGroup.jsm",
"NntpProtocolHandler.jsm",
"NntpProtocolInfo.jsm",
"NntpService.jsm",
]

Просмотреть файл

@ -11,11 +11,7 @@ prefs =
[test_nntpContentLength.js]
# The server doesn't support returning sizes! (bug 782629)
skip-if = true
[test_newsAutocomplete.js]
[test_nntpProxy.js]
[test_nntpUrl.js]
[test_server.js]
run-sequentially = Uses fixed NNTP_PORT
[test_uriParser.js]
[include:xpcshell-shared.ini]

Просмотреть файл

@ -7,6 +7,7 @@ run-sequentially = Restarts server twice--may work but dangerous
[test_filter.js]
[test_getNewsMessage.js]
[test_internalUris.js]
[test_newsAutocomplete.js]
[test_nntpGroupPassword.js]
[test_nntpPassword.js]
[test_nntpPassword2.js]
@ -14,3 +15,6 @@ run-sequentially = Restarts server twice--may work but dangerous
[test_nntpPasswordFailure.js]
[test_nntpPost.js]
[test_nntpProtocols.js]
[test_nntpProxy.js]
[test_nntpUrl.js]
[test_uriParser.js]