Browse Source

Land patch for bug 1926406

Ian Neal 5 hours ago
parent
commit
bb85cff116

+ 578 - 0
comm-release/patches/1926406-irc-chatzilla-service-25320.patch

@@ -0,0 +1,578 @@
+# HG changeset patch
+# User Ian Neal <iann_cvs@blueyonder.co.uk>
+# Date 1729626535 -3600
+# Parent  82cf855548399963941b9cfff155a249df440498
+Bug 1926406 - Tidy up chatzilla-service.js. r=frg f=tobin a=frg
+
+diff --git a/suite/extensions/irc/jar.mn b/suite/extensions/irc/jar.mn
+--- a/suite/extensions/irc/jar.mn
++++ b/suite/extensions/irc/jar.mn
+@@ -23,18 +23,16 @@ chatzilla.jar:
+ 	content/chatzilla/lib/js/irc.js              (js/lib/irc.js) 
+ 	content/chatzilla/lib/js/irc-debug.js        (js/lib/irc-debug.js)
+ 	content/chatzilla/lib/js/file-utils.js       (js/lib/file-utils.js)
+ 	content/chatzilla/lib/js/dcc.js              (js/lib/dcc.js) 
+ 	content/chatzilla/lib/js/json-serializer.js  (js/lib/json-serializer.js)
+ 	content/chatzilla/lib/js/sts.js              (js/lib/sts.js)
+ 	content/chatzilla/lib/js/text-serializer.js  (js/lib/text-serializer.js)
+ 	content/chatzilla/lib/js/text-logger.js      (js/lib/text-logger.js)
+-	content/chatzilla/lib/js/chatzilla-protocol-script.js (js/lib/chatzilla-protocol-script.js)
+-	content/chatzilla/lib/js/protocol-handlers.jsm (js/lib/protocol-handlers.jsm)
+ 	content/chatzilla/lib/xul/munger.js          (xul/lib/munger.js) 
+ 	content/chatzilla/lib/xul/tree-utils.js      (xul/lib/tree-utils.js) 
+ 	content/chatzilla/chatzilla.xul              (xul/content/chatzilla.xul) 
+ 	content/chatzilla/scripts.xul                (xul/content/scripts.xul) 
+ 	content/chatzilla/menus.xul                  (xul/content/menus.xul) 
+ 	content/chatzilla/popups.xul                 (xul/content/popups.xul) 
+ 	content/chatzilla/channels.xul               (xul/content/channels.xul) 
+ 	content/chatzilla/channels.js                (xul/content/channels.js) 
+diff --git a/suite/extensions/irc/js/lib/chatzilla-protocol-script.js b/suite/extensions/irc/js/lib/chatzilla-protocol-script.js
+deleted file mode 100644
+--- a/suite/extensions/irc/js/lib/chatzilla-protocol-script.js
++++ /dev/null
+@@ -1,10 +0,0 @@
+-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+- * 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 { utils: Cu } = Components;
+-
+-let { ChatZillaProtocols } = Cu.import("chrome://chatzilla/content/lib/js/protocol-handlers.jsm", {});
+-
+-ChatZillaProtocols.init();
+diff --git a/suite/extensions/irc/js/lib/chatzilla-service.js b/suite/extensions/irc/js/lib/chatzilla-service.js
+--- a/suite/extensions/irc/js/lib/chatzilla-service.js
++++ b/suite/extensions/irc/js/lib/chatzilla-service.js
+@@ -4,30 +4,29 @@
+  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+ 
+ ChromeUtils.import("resource://gre/modules/Services.jsm");
+ ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
+ 
+ 
+ const RDFS_CONTRACTID =
+     "@mozilla.org/rdf/rdf-service;1";
+-const PPMM_CONTRACTID =
+-    "@mozilla.org/parentprocessmessagemanager;1";
+-
+ const CLINE_SERVICE_CID =
+     Components.ID("{38a95514-1dd2-11b2-97e7-9da958640f2c}");
+ const STARTUP_CID =
+     Components.ID("{ae6ad015-433b-42ab-9afc-1636af5a7fc4}");
+ 
+-
+-Cu.import("chrome://chatzilla/content/lib/js/protocol-handlers.jsm");
+-/* global ChatZillaProtocols */
+-/* global IRCProtocolHandlerFactory, IRCSProtocolHandlerFactory */
+-/* global IRCPROT_HANDLER_CID, IRCSPROT_HANDLER_CID */
+-
++const IRCPROT_HANDLER_CONTRACTID =
++    "@mozilla.org/network/protocol;1?name=irc";
++const IRCSPROT_HANDLER_CONTRACTID =
++    "@mozilla.org/network/protocol;1?name=ircs";
++const IRCPROT_HANDLER_CID =
++    Components.ID("{f21c35f4-1dd1-11b2-a503-9bf8a539ea39}");
++const IRCSPROT_HANDLER_CID =
++    Components.ID("{f21c35f4-1dd1-11b2-a503-9bf8a539ea3a}");
+ 
+ function spawnChatZilla(uri, count)
+ {
+     const hiddenWin = Services.appShell.hiddenDOMWindow;
+ 
+     // Ok, not starting currently, so check if we've got existing windows.
+     const w = Services.wm.getMostRecentWindow("irc:chatzilla");
+ 
+@@ -89,16 +88,18 @@ function spawnChatZilla(uri, count)
+ 
+ 
+ function CommandLineService()
+ {
+ }
+ 
+ CommandLineService.prototype =
+ {
++    classID: CLINE_SERVICE_CID,
++
+     /* nsISupports */
+     QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
+ 
+     /* nsICommandLineHandler */
+     handle(cmdLine)
+     {
+         var uri;
+         try
+@@ -134,47 +135,36 @@ const CommandLineFactory =
+ 
+ 
+ function ProcessHandler()
+ {
+ }
+ 
+ ProcessHandler.prototype =
+ {
++    classID: STARTUP_CID,
++
+     /* nsISupports */
+-    QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
+-                                           Ci.nsIMessageListener]),
++    QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
+ 
+     /* nsIObserver */
+     observe(subject, topic, data)
+     {
+         if (topic !== "profile-after-change")
+             return;
+ 
+-        var ppmm;
+-        // Ci.nsIMessageBroadcaster went in Gecko 61.
+-        if (Ci.nsIMessageBroadcaster)
+-        {
+-            ppmm = Cc[PPMM_CONTRACTID].getService(Ci.nsIMessageBroadcaster);
+-        }
+-        else
+-        {
+-            ppmm = Cc[PPMM_CONTRACTID].getService();
+-        }
+-        ppmm.loadProcessScript("chrome://chatzilla/content/lib/js/chatzilla-protocol-script.js", true);
+-        ppmm.addMessageListener("ChatZilla:SpawnChatZilla", this);
+-    },
+-
+-    /* nsIMessageListener */
+-    receiveMessage(msg)
+-    {
+-        if (msg.name !== "ChatZilla:SpawnChatZilla")
+-            return;
+-
+-        spawnChatZilla(msg.data.uri);
++        const compMgr = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
++        compMgr.registerFactory(IRCPROT_HANDLER_CID,
++                                "IRC protocol handler",
++                                IRCPROT_HANDLER_CONTRACTID,
++                                IRCProtocolHandlerFactory);
++        compMgr.registerFactory(IRCSPROT_HANDLER_CID,
++                                "IRCS protocol handler",
++                                IRCSPROT_HANDLER_CONTRACTID,
++                                IRCSProtocolHandlerFactory);
+     },
+ };
+ 
+ 
+ const StartupFactory =
+ {
+     createInstance(outer, iid)
+     {
+@@ -185,16 +175,180 @@ const StartupFactory =
+             throw Cr.NS_ERROR_NO_INTERFACE;
+ 
+         // startup:
+         return new ProcessHandler();
+     },
+ };
+ 
+ 
++const IRC_MIMETYPE = "application/x-irc";
++const IRCS_MIMETYPE = "application/x-ircs";
++
++//XXXgijs: Because necko is annoying and doesn't expose this error flag, we
++//         define our own constant for it. Throwing something else will show
++//         ugly errors instead of seeminly doing nothing.
++const NS_ERROR_MODULE_NETWORK_BASE = 0x804b0000;
++const NS_ERROR_NO_CONTENT = NS_ERROR_MODULE_NETWORK_BASE + 17;
++
++
++function GenericIRCProtocolHandler(isSecure)
++{
++    this.isSecure = isSecure;
++    this.scheme = isSecure ? "ircs" : "irc";
++    this.classID = isSecure ? IRCSPROT_HANDLER_CID : IRCPROT_HANDLER_CID;
++    this.defaultPort = isSecure ? 6697 : 6667;
++}
++
++GenericIRCProtocolHandler.prototype =
++{
++    QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler,
++                                           Ci.nsISupports]),
++
++    protocolFlags: Ci.nsIProtocolHandler.URI_NORELATIVE |
++                   Ci.nsIProtocolHandler.ALLOWS_PROXY |
++                   Ci.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE |
++                   Ci.nsIProtocolHandler.URI_NON_PERSISTABLE |
++                   Ci.nsIProtocolHandler.URI_DOES_NOT_RETURN_DATA,
++
++    allowPort(port, scheme)
++    {
++        // Allow all ports to connect, so long as they are irc: or ircs:
++        return (scheme === 'irc' || scheme === 'ircs');
++    },
++
++    newURI(spec, charset, baseURI)
++    {
++        return Cc["@mozilla.org/network/standard-url-mutator;1"]
++                 .createInstance(Ci.nsIStandardURLMutator)
++                 .init(Ci.nsIStandardURL.URLTYPE_STANDARD, this.defaultPort,
++                       spec, charset, baseURI)
++                 .finalize()
++                 .QueryInterface(Ci.nsIStandardURL);
++    },
++
++    newChannel(URI)
++    {
++        if (!Services.io.allowPort(URI.port, URI.scheme))
++            throw Cr.NS_ERROR_FAILURE;
++
++        return new BogusChannel(URI, this.isSecure);
++    },
++};
++
++
++/* Bogus IRC channel used by the IRCProtocolHandler */
++function BogusChannel(URI, isSecure)
++{
++    this.URI = URI;
++    this.originalURI = URI;
++    this.isSecure = isSecure;
++    this.contentType = this.isSecure ? IRCS_MIMETYPE : IRC_MIMETYPE;
++}
++
++BogusChannel.prototype =
++{
++    /* nsISupports */
++    QueryInterface: XPCOMUtils.generateQI([Ci.nsIChannel, Ci.nsIRequest]),
++
++    /* nsIChannel */
++    loadAttributes: null,
++    contentLength: 0,
++    owner: null,
++    loadGroup: null,
++    notificationCallbacks: null,
++    securityInfo: null,
++
++    open(observer, context)
++    {
++        spawnChatZilla(this.URI.spec);
++        // We don't throw this (a number, not a real 'resultcode') because it
++        // upsets xpconnect if we do (error in the js console).
++        Components.returnCode = NS_ERROR_NO_CONTENT;
++    },
++
++    asyncOpen(observer, context)
++    {
++        spawnChatZilla(this.URI.spec);
++        // We don't throw this (a number, not a real 'resultcode') because it
++        // upsets xpconnect if we do (error in the js console).
++        Components.returnCode = NS_ERROR_NO_CONTENT;
++    },
++
++    asyncRead(listener, context)
++    {
++        throw Cr.NS_ERROR_NOT_IMPLEMENTED;
++    },
++
++    /* nsIRequest */
++    isPending()
++    {
++        return true;
++    },
++
++    status: Cr.NS_OK,
++
++    cancel(status)
++    {
++        this.status = status;
++    },
++
++    suspend()
++    {
++        throw Cr.NS_ERROR_NOT_IMPLEMENTED;
++    },
++
++    resume()
++    {
++        throw Cr.NS_ERROR_NOT_IMPLEMENTED;
++    },
++};
++
++
++function IRCProtocolHandler()
++{
++}
++
++IRCProtocolHandler.prototype = new GenericIRCProtocolHandler(false);
++
++function IRCSProtocolHandler()
++{
++}
++
++IRCSProtocolHandler.prototype = new GenericIRCProtocolHandler(true);
++
++const IRCProtocolHandlerFactory =
++{
++    createInstance(outer, iid)
++    {
++        if (outer != null)
++            throw Cr.NS_ERROR_NO_AGGREGATION;
++
++        if (!iid.equals(Ci.nsIProtocolHandler) && !iid.equals(Ci.nsISupports))
++            throw Cr.NS_ERROR_INVALID_ARG;
++
++        return new IRCProtocolHandler(false);
++    },
++};
++
++
++const IRCSProtocolHandlerFactory =
++{
++    createInstance(outer, iid)
++    {
++        if (outer != null)
++            throw Cr.NS_ERROR_NO_AGGREGATION;
++
++        if (!iid.equals(Ci.nsIProtocolHandler) && !iid.equals(Ci.nsISupports))
++            throw Cr.NS_ERROR_INVALID_ARG;
++
++        return new IRCProtocolHandler(true);
++    },
++};
++
+ /* entrypoint */
+ function NSGetFactory(cid)
+ {
+     // Checking if we're disabled in the Chrome Registry.
+     var rv;
+     try
+     {
+         const rdfSvc = Cc[RDFS_CONTRACTID].getService(Ci.nsIRDFService);
+diff --git a/suite/extensions/irc/js/lib/protocol-handlers.jsm b/suite/extensions/irc/js/lib/protocol-handlers.jsm
+deleted file mode 100644
+--- a/suite/extensions/irc/js/lib/protocol-handlers.jsm
++++ /dev/null
+@@ -1,228 +0,0 @@
+-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+- * 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 = [
+-    "ChatZillaProtocols",
+-    "IRCProtocolHandlerFactory",
+-    "IRCSProtocolHandlerFactory",
+-    "IRCPROT_HANDLER_CID",
+-    "IRCSPROT_HANDLER_CID"
+-];
+-
+-const { classes: Cc, interfaces: Ci, results: Cr } = Components;
+-
+-const IOSERVICE_CONTRACTID =
+-    "@mozilla.org/network/io-service;1";
+-
+-const IRCPROT_HANDLER_CONTRACTID =
+-    "@mozilla.org/network/protocol;1?name=irc";
+-const IRCSPROT_HANDLER_CONTRACTID =
+-    "@mozilla.org/network/protocol;1?name=ircs";
+-this.IRCPROT_HANDLER_CID =
+-    Components.ID("{f21c35f4-1dd1-11b2-a503-9bf8a539ea39}");
+-this.IRCSPROT_HANDLER_CID =
+-    Components.ID("{f21c35f4-1dd1-11b2-a503-9bf8a539ea3a}");
+-
+-const IRC_MIMETYPE = "application/x-irc";
+-const IRCS_MIMETYPE = "application/x-ircs";
+-
+-//XXXgijs: Because necko is annoying and doesn't expose this error flag, we
+-//         define our own constant for it. Throwing something else will show
+-//         ugly errors instead of seeminly doing nothing.
+-const NS_ERROR_MODULE_NETWORK_BASE = 0x804b0000;
+-const NS_ERROR_NO_CONTENT = NS_ERROR_MODULE_NETWORK_BASE + 17;
+-
+-
+-function spawnChatZilla(uri) {
+-    var cpmm;
+-    // Ci.nsISyncMessageSender went in Gecko 61.
+-    if (Ci.nsISyncMessageSender) {
+-        cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"]
+-                 .getService(Ci.nsISyncMessageSender);
+-    } else {
+-        cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"].getService();
+-    }
+-    cpmm.sendAsyncMessage("ChatZilla:SpawnChatZilla", { uri });
+-}
+-
+-
+-function IRCProtocolHandler(isSecure)
+-{
+-    this.isSecure = isSecure;
+-}
+-
+-var protocolFlags = Ci.nsIProtocolHandler.URI_NORELATIVE |
+-                    Ci.nsIProtocolHandler.ALLOWS_PROXY;
+-if ("URI_DANGEROUS_TO_LOAD" in Ci.nsIProtocolHandler) {
+-    protocolFlags |= Ci.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE;
+-}
+-if ("URI_NON_PERSISTABLE" in Ci.nsIProtocolHandler) {
+-    protocolFlags |= Ci.nsIProtocolHandler.URI_NON_PERSISTABLE;
+-}
+-if ("URI_DOES_NOT_RETURN_DATA" in Ci.nsIProtocolHandler) {
+-    protocolFlags |= Ci.nsIProtocolHandler.URI_DOES_NOT_RETURN_DATA;
+-}
+-
+-IRCProtocolHandler.prototype =
+-{
+-    protocolFlags: protocolFlags,
+-
+-    allowPort(port, scheme)
+-    {
+-        // Allow all ports to connect, so long as they are irc: or ircs:
+-        return (scheme === 'irc' || scheme === 'ircs');
+-    },
+-
+-    newURI(spec, charset, baseURI)
+-    {
+-        const port = this.isSecure ? 6697 : 6667;
+-
+-        return Cc["@mozilla.org/network/standard-url-mutator;1"]
+-                 .createInstance(Ci.nsIStandardURLMutator)
+-                 .init(Ci.nsIStandardURL.URLTYPE_STANDARD, port, spec, charset, baseURI)
+-                 .finalize()
+-                 .QueryInterface(Ci.nsIStandardURL);
+-    },
+-
+-    newChannel(URI)
+-    {
+-        const ios = Cc[IOSERVICE_CONTRACTID].getService(Ci.nsIIOService);
+-        if (!ios.allowPort(URI.port, URI.scheme))
+-            throw Cr.NS_ERROR_FAILURE;
+-
+-        return new BogusChannel(URI, this.isSecure);
+-    },
+-};
+-
+-
+-this.IRCProtocolHandlerFactory =
+-{
+-    createInstance(outer, iid)
+-    {
+-        if (outer != null)
+-            throw Cr.NS_ERROR_NO_AGGREGATION;
+-
+-        if (!iid.equals(Ci.nsIProtocolHandler) && !iid.equals(Ci.nsISupports))
+-            throw Cr.NS_ERROR_INVALID_ARG;
+-
+-        const protHandler = new IRCProtocolHandler(false);
+-        protHandler.scheme = "irc";
+-        protHandler.defaultPort = 6667;
+-        return protHandler;
+-    },
+-};
+-
+-
+-this.IRCSProtocolHandlerFactory =
+-{
+-    createInstance(outer, iid)
+-    {
+-        if (outer != null)
+-            throw Cr.NS_ERROR_NO_AGGREGATION;
+-
+-        if (!iid.equals(Ci.nsIProtocolHandler) && !iid.equals(Ci.nsISupports))
+-            throw Cr.NS_ERROR_INVALID_ARG;
+-
+-        const protHandler = new IRCProtocolHandler(true);
+-        protHandler.scheme = "ircs";
+-        protHandler.defaultPort = 6697;
+-        return protHandler;
+-    },
+-};
+-
+-
+-/* Bogus IRC channel used by the IRCProtocolHandler */
+-function BogusChannel(URI, isSecure)
+-{
+-    this.URI = URI;
+-    this.originalURI = URI;
+-    this.isSecure = isSecure;
+-    this.contentType = this.isSecure ? IRCS_MIMETYPE : IRC_MIMETYPE;
+-}
+-
+-BogusChannel.prototype =
+-{
+-    /* nsISupports */
+-    QueryInterface(iid)
+-    {
+-        if (iid.equals(Ci.nsISupports) ||
+-            iid.equals(Ci.nsIChannel) ||
+-            iid.equals(Ci.nsIRequest))
+-        {
+-            return this;
+-        }
+-
+-        throw Cr.NS_ERROR_NO_INTERFACE;
+-    },
+-
+-    /* nsIChannel */
+-    loadAttributes: null,
+-    contentLength: 0,
+-    owner: null,
+-    loadGroup: null,
+-    notificationCallbacks: null,
+-    securityInfo: null,
+-
+-    open(observer, context)
+-    {
+-        spawnChatZilla(this.URI.spec);
+-        // We don't throw this (a number, not a real 'resultcode') because it
+-        // upsets xpconnect if we do (error in the js console).
+-        Components.returnCode = NS_ERROR_NO_CONTENT;
+-    },
+-
+-    asyncOpen(observer, context)
+-    {
+-        spawnChatZilla(this.URI.spec);
+-        // We don't throw this (a number, not a real 'resultcode') because it
+-        // upsets xpconnect if we do (error in the js console).
+-        Components.returnCode = NS_ERROR_NO_CONTENT;
+-    },
+-
+-    asyncRead(listener, context)
+-    {
+-        throw Cr.NS_ERROR_NOT_IMPLEMENTED;
+-    },
+-
+-    /* nsIRequest */
+-    isPending()
+-    {
+-        return true;
+-    },
+-
+-    status: Cr.NS_OK,
+-
+-    cancel(status)
+-    {
+-        this.status = status;
+-    },
+-
+-    suspend()
+-    {
+-        throw Cr.NS_ERROR_NOT_IMPLEMENTED;
+-    },
+-
+-    resume()
+-    {
+-        throw Cr.NS_ERROR_NOT_IMPLEMENTED;
+-    },
+-};
+-
+-
+-this.ChatZillaProtocols =
+-{
+-    init()
+-    {
+-        const compMgr = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
+-        compMgr.registerFactory(IRCPROT_HANDLER_CID,
+-                                "IRC protocol handler",
+-                                IRCPROT_HANDLER_CONTRACTID,
+-                                IRCProtocolHandlerFactory);
+-        compMgr.registerFactory(IRCSPROT_HANDLER_CID,
+-                                "IRC protocol handler",
+-                                IRCSPROT_HANDLER_CONTRACTID,
+-                                IRCSProtocolHandlerFactory);
+-    },
+-};

+ 2 - 1
comm-release/patches/series

@@ -2218,5 +2218,6 @@ TOP-1872623-cancelbookmark-25319.patch
 1925025-specificsearch-25320.patch
 1925033-focus-25320.patch
 1925037-switchToTabHavingURI-1_1-25320.patch
-1925871-irc-remove-NSGetModule-v1_1-25320.patch
 1925849-domi-cmdline-25320.patch
+1925871-irc-remove-NSGetModule-v1_1-25320.patch
+1926406-irc-chatzilla-service-25320.patch