Browse Source

More cZ patches

Ian Neal 1 week ago
parent
commit
dfe4a8d3b2

+ 142 - 0
comm-release/patches/1924336-irc-logins-25320.patch

@@ -0,0 +1,142 @@
+# HG changeset patch
+# User Ian Neal <iann_cvs@blueyonder.co.uk>
+# Date 1728777521 -3600
+# Parent  978ab079ee50c8b7c959d92fb2db03ee925b340f
+Bug 1924336 - Tidy up logins code in cZ. r=frg a=frg
+
+diff --git a/suite/extensions/irc/js/lib/utils.js b/suite/extensions/irc/js/lib/utils.js
+--- a/suite/extensions/irc/js/lib/utils.js
++++ b/suite/extensions/irc/js/lib/utils.js
+@@ -911,47 +911,16 @@ function viewCert(cert, parent)
+ {
+     var cd = getService("@mozilla.org/nsCertificateDialogs;1",
+                         "nsICertificateDialogs");
+     if (!parent)
+         parent = window;
+     cd.viewCert(parent, cert);
+ }
+ 
+-function addOrUpdateLogin(url, type, username, password)
+-{
+-    username = username.toLowerCase();
+-    var newinfo = newObject("@mozilla.org/login-manager/loginInfo;1",
+-                            "nsILoginInfo");
+-    newinfo.init(url, null, type, username, password, "", "");
+-    var oldinfo = getLogin(url, type, username);
+-
+-    if (oldinfo) {
+-        Services.logins.modifyLogin(oldinfo, newinfo);
+-        return true; //updated
+-    }
+-
+-    Services.logins.addLogin(newinfo);
+-    return false; //added
+-}
+-
+-function getLogin(url, realm, username)
+-{
+-    username = username.toLowerCase();
+-
+-    let logins = Services.logins.findLogins({}, url, null, realm);
+-    for (let login of logins) {
+-        if (login.username == username) {
+-            return login;
+-        }
+-    }
+-
+-    return null;
+-}
+-
+ function getHostmaskParts(hostmask)
+ {
+     var rv;
+     // A bit cheeky this, we try the matches here, and then branch
+     // according to the ones we like.
+     var ary1 = hostmask.match(/([^ ]*)!([^ ]*)@(.*)/);
+     var ary2 = hostmask.match(/([^ ]*)@(.*)/);
+     var ary3 = hostmask.match(/([^ ]*)!(.*)/);
+diff --git a/suite/extensions/irc/xul/content/static.js b/suite/extensions/irc/xul/content/static.js
+--- a/suite/extensions/irc/xul/content/static.js
++++ b/suite/extensions/irc/xul/content/static.js
+@@ -5137,36 +5137,46 @@ function cli_promptToSaveLogin(url, type
+             display(getMsg(MSG_LOGIN_ERR_UNKNOWN_TYPE, type), MT_ERROR);
+             return;
+     }
+ 
+     const buttons = [MSG_LOGIN_SAVE, MSG_LOGIN_DONT];
+     var checkState = { value: true };
+     var rv = confirmEx(getMsg(MSG_LOGIN_CONFIRM, name), buttons, 0,
+                        MSG_LOGIN_PROMPT, checkState);
+-    if (rv == 0)
+-    {
+-        client.prefs["login.promptToSave"] = checkState.value;
+-
+-        var updated = addOrUpdateLogin(url, type, username, password);
+-        if (updated) {
+-            display(getMsg(MSG_LOGIN_UPDATED, name), MT_INFO);
+-        } else {
+-            display(getMsg(MSG_LOGIN_ADDED, name), MT_INFO);
+-        }
+-    }
++    if (rv != 0)
++        return;
++
++    client.prefs["login.promptToSave"] = checkState.value;
++
++    username = username.toLowerCase();
++    var newinfo = Cc["@mozilla.org/login-manager/loginInfo;1"]
++                    .createInstance(Ci.nsILoginInfo);
++    newinfo.init(url, null, type, username, password, "", "");
++    var oldinfo = getLogin(url, type, username);
++
++    if (oldinfo) {
++        // Update login.
++        Services.logins.modifyLogin(oldinfo, newinfo);
++        display(getMsg(MSG_LOGIN_UPDATED, name), MT_INFO);
++        return;
++    }
++
++    // Add login.
++    Services.logins.addLogin(newinfo);
++    display(getMsg(MSG_LOGIN_ADDED, name), MT_INFO);
+ }
+ 
+ client.tryToGetLogin =
+ function cli_tryToGetLogin(url, type, username, existing, needpass,
+                            promptstring)
+ {
+     // Password is optional. If it is not given, we look for a saved password
+     // first. If there isn't one, we potentially use a safe prompt.
+-    var info = getLogin(url, type, username);
++    var info = getLogin(url, type, username.toLowerCase());
+     var stored = (info && info.password) ? info.password : "";
+     var promptToSave = false;
+     if (!existing && stored) {
+         existing = stored;
+     } else if (!existing && needpass) {
+         existing = promptPassword(promptstring, "");
+         if (existing)
+             promptToSave = true;
+@@ -5269,16 +5279,22 @@ function cli_stoplog(view, showMessage)
+ 
+     if (view.logFile)
+     {
+         view.logFile.close();
+         view.logFile = null;
+     }
+ }
+ 
++function getLogin(url, realm, username)
++{
++    let logins = Services.logins.findLogins({}, url, null, realm);
++    return logins.find((login) => login.username === username);
++}
++
+ function checkLogFiles()
+ {
+     // For every view that has a logfile, check if we need a different file
+     // based on the current date and the logfile preference. We close the
+     // current logfile, and display will open the new one based on the pref
+     // when it's needed.
+ 
+     var d = new Date();

+ 123 - 0
comm-release/patches/1924337-irc-zipReader-25320.patch

@@ -0,0 +1,123 @@
+# HG changeset patch
+# User Ian Neal <iann_cvs@blueyonder.co.uk>
+# Date 1728778034 -3600
+# Parent  968c13ad51817cf98728b1e63b189260e533ed37
+Bug 1924337 - Tidy up zipReader code in cZ. r=frg a=frg
+
+diff --git a/suite/extensions/irc/xul/content/static.js b/suite/extensions/irc/xul/content/static.js
+--- a/suite/extensions/irc/xul/content/static.js
++++ b/suite/extensions/irc/xul/content/static.js
+@@ -3009,33 +3009,19 @@ function cli_installPlugin(name, source)
+         installed |= (name in client.plugins);
+ 
+         if (installed)
+         {
+             display(MSG_INSTALL_PLUGIN_ERR_ALREADY_INST, MT_ERROR);
+             throw CZ_PI_ABORT;
+         }
+     };
+-    function getZipEntry(reader, entryEnum)
+-    {
+-        // nsIZipReader was rewritten...
+-        var itemName = entryEnum.getNext();
+-        if (typeof itemName != "string")
+-            name = itemName.QueryInterface(nsIZipEntry).name;
+-        return itemName;
+-    };
+-    function checkZipMore(items)
+-    {
+-        return (("hasMoreElements" in items) && items.hasMoreElements()) ||
+-               (("hasMore" in items) && items.hasMore());
+-    };
+ 
+     const DIRECTORY_TYPE = Components.interfaces.nsIFile.DIRECTORY_TYPE;
+     const CZ_PI_ABORT = "CZ_PI_ABORT";
+-    const nsIZipEntry = Components.interfaces.nsIZipEntry;
+ 
+     var dest;
+     // Find a suitable location if there was none specified.
+     var destList = client.prefs["initialScripts"];
+     if ((destList.length == 0) ||
+         ((destList.length == 1) && /^\s*$/.test(destList[0])))
+     {
+         // Reset to default because it is empty.
+@@ -3078,31 +3064,31 @@ function cli_installPlugin(name, source)
+     display(getMsg(MSG_INSTALL_PLUGIN_INSTALLING, [source.path, dest.path]),
+             MT_INFO);
+ 
+     var ary;
+     if (source.path.match(/\.(jar|zip)$/i))
+     {
+         try
+         {
+-            var zipReader = newObject("@mozilla.org/libjar/zip-reader;1",
+-                                      "nsIZipReader");
++            var zipReader = Cc["@mozilla.org/libjar/zip-reader;1"]
++                              .createInstance(Ci.nsIZipReader);
+             zipReader.open(source);
+ 
+             // This is set to the base path found on ALL items in the zip file.
+             // when we extract, this WILL BE REMOVED from all paths.
+             var zipPathBase = "";
+             // This always points to init.js, even if we're messing with paths.
+             var initPath = "init.js";
+ 
+             // Look for init.js within a directory...
+             var items = zipReader.findEntries("*/init.js");
+-            while (checkZipMore(items))
++            while (items.hasMore())
+             {
+-                var itemName = getZipEntry(zipReader, items);
++                var itemName = items.getNext();
+                 // Do we already have one?
+                 if (zipPathBase)
+                 {
+                     display(MSG_INSTALL_PLUGIN_ERR_MANY_INITJS, MT_WARN);
+                     throw CZ_PI_ABORT;
+                 }
+                 zipPathBase = itemName.match(/^(.*\/)init.js$/)[1];
+                 initPath = itemName;
+@@ -3110,19 +3096,19 @@ function cli_installPlugin(name, source)
+ 
+             if (zipPathBase)
+             {
+                 // We have a base for init.js, assert that all files are inside
+                 // it. If not, we drop the path and install exactly as-is
+                 // instead (which will probably cause it to not work because the
+                 // init.js isn't in the right place).
+                 items = zipReader.findEntries("*");
+-                while (checkZipMore(items))
++                while (items.hasMore())
+                 {
+-                    itemName = getZipEntry(zipReader, items);
++                    itemName = items.getNext();
+                     if (itemName.substr(0, zipPathBase.length) != zipPathBase)
+                     {
+                         display(MSG_INSTALL_PLUGIN_ERR_MIXED_BASE, MT_WARN);
+                         zipPathBase = "";
+                         break;
+                     }
+                 }
+             }
+@@ -3149,19 +3135,19 @@ function cli_installPlugin(name, source)
+             dest.append(name);
+             checkPluginInstalled(name, dest);
+ 
+             dest.create(DIRECTORY_TYPE, 0o700);
+ 
+             // Actually extract files...
+             var destInit;
+             items = zipReader.findEntries("*");
+-            while (checkZipMore(items))
++            while (items.hasMore())
+             {
+-                itemName = getZipEntry(zipReader, items);
++                itemName = items.getNext();
+                 if (!itemName.match(/\/$/))
+                 {
+                     var dirs = itemName;
+                     // Remove common path if there is one.
+                     if (zipPathBase)
+                         dirs = dirs.substring(zipPathBase.length);
+                     dirs = dirs.split("/");
+ 

+ 242 - 0
comm-release/patches/1924338-irc-newObject-25320.patch

@@ -0,0 +1,242 @@
+# HG changeset patch
+# User Ian Neal <iann_cvs@blueyonder.co.uk>
+# Date 1728778539 -3600
+# Parent  281c55ff6f461b24107590e74a018dd6af4ec609
+Bug 1924338 - Inline newObject function in cZ. r=frg a=frg
+
+diff --git a/suite/extensions/irc/js/lib/utils.js b/suite/extensions/irc/js/lib/utils.js
+--- a/suite/extensions/irc/js/lib/utils.js
++++ b/suite/extensions/irc/js/lib/utils.js
+@@ -504,47 +504,16 @@ function renameProperty (obj, oldname, n
+     if (oldname == newname)
+         return;
+ 
+     obj[newname] = obj[oldname];
+     delete obj[oldname];
+ 
+ }
+ 
+-function newObject(contractID, iface)
+-{
+-    var rv;
+-    var cls = Components.classes[contractID];
+-
+-    if (!cls)
+-        return null;
+-
+-    switch (typeof iface)
+-    {
+-        case "undefined":
+-            rv = cls.createInstance();
+-            break;
+-
+-        case "string":
+-            rv = cls.createInstance(Components.interfaces[iface]);
+-            break;
+-
+-        case "object":
+-            rv = cls.createInstance(iface);
+-            break;
+-
+-        default:
+-            rv = null;
+-            break;
+-    }
+-
+-    return rv;
+-
+-}
+-
+ function getService(contractID, iface)
+ {
+     var rv;
+     var cls = Components.classes[contractID];
+ 
+     if (!cls)
+         return null;
+ 
+diff --git a/suite/extensions/irc/xul/content/about/about.js b/suite/extensions/irc/xul/content/about/about.js
+--- a/suite/extensions/irc/xul/content/about/about.js
++++ b/suite/extensions/irc/xul/content/about/about.js
+@@ -88,24 +88,25 @@ function onLoad()
+ function onUnload()
+ {
+     if (ownerClient)
+         delete ownerClient.aboutDialog;
+ }
+ 
+ function copyVersion()
+ {
+-    const cbID = Components.interfaces.nsIClipboard.kGlobalClipboard;
+-    var cb = getService("@mozilla.org/widget/clipboard;1", "nsIClipboard");
+-    var tr = newObject("@mozilla.org/widget/transferable;1", "nsITransferable");
+-    var str = newObject("@mozilla.org/supports-string;1", "nsISupportsString");
++    var tr = Cc["@mozilla.org/widget/transferable;1"]
++               .createInstance(Ci.nsITransferable);
++    var str = Cc["@mozilla.org/supports-string;1"]
++                .createInstance(Ci.nsISupportsString);
+ 
++    tr.addDataFlavor("text/unicode");
+     str.data = client.userAgent;
+     tr.setTransferData("text/unicode", str, str.data.length * 2);
+-    cb.setData(tr, null, cbID);
++    Services.clipboard.setData(tr, null, Services.clipboard.kGlobalClipboard);
+ }
+ 
+ function openHomepage()
+ {
+     if (ownerClient)
+         ownerClient.dispatch("goto-url", {url: MSG_SOURCE_REPLY});
+     else
+         window.opener.open(MSG_SOURCE_REPLY, "_blank");
+diff --git a/suite/extensions/irc/xul/content/commands.js b/suite/extensions/irc/xul/content/commands.js
+--- a/suite/extensions/irc/xul/content/commands.js
++++ b/suite/extensions/irc/xul/content/commands.js
+@@ -3555,39 +3555,39 @@ function cmdSave(e)
+     var OutputProgressListener =
+     {
+         onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus)
+         {
+             // Use this to access onStateChange flags
+             var requestSpec;
+             try
+             {
+-              var channel = aRequest.QueryInterface(nsIChannel);
++              var channel = aRequest.QueryInterface(Ci.nsIChannel);
+               requestSpec = channel.URI.spec;
+             }
+             catch (ex) { }
+ 
+             // Detect end of file saving of any file:
+-            if (aStateFlags & nsIWebProgressListener.STATE_STOP)
++            if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP)
+             {
+                 if (aStatus == kErrorBindingAborted)
+                     aStatus = 0;
+ 
+                 // We abort saving for all errors except if image src file is
+                 // not found
+                 var abortSaving = (aStatus != 0 && aStatus != kFileNotFound);
+                 if (abortSaving)
+                 {
+                     // Cancel saving
+                     wbp.cancelSave();
+                     display(getMsg(MSG_SAVE_ERR_FAILED, aMessage), MT_ERROR);
+                     return;
+                 }
+ 
+-                if (aStateFlags & nsIWebProgressListener.STATE_IS_NETWORK
++                if (aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK
+                     && wbp.currentState == nsIWBP.PERSIST_STATE_FINISHED)
+                 {
+                     // Let the user know:
+                     pm = [e.sourceObject.viewName, getURLSpecFromFile(file)];
+                     display(getMsg(MSG_SAVE_SUCCESSFUL, pm), MT_INFO);
+                 }
+                 /* Check if we've finished. WebBrowserPersist screws up when we
+                  * don't save additional files. Cope when saving html only or
+@@ -3607,36 +3607,34 @@ function cmdSave(e)
+                                   aMaxSelfProgress, aCurTotalProgress,
+                                   aMaxTotalProgress) {},
+         onLocationChange: function(aWebProgress, aRequest, aLocation) {},
+         onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage) {},
+         onSecurityChange: function(aWebProgress, aRequest, state) {},
+ 
+         QueryInterface: function(aIID)
+         {
+-            if (aIID.equals(Components.interfaces.nsIWebProgressListener)
+-                || aIID.equals(Components.interfaces.nsISupports)
+-                || aIID.equals(Components.interfaces.nsISupportsWeakReference))
++            if (aIID.equals(Ci.nsIWebProgressListener)
++                || aIID.equals(Ci.nsISupports)
++                || aIID.equals(Ci.nsISupportsWeakReference))
+             {
+                 return this;
+             }
+ 
+             throw Components.results.NS_NOINTERFACE;
+         }
+     };
+ 
+     const kFileNotFound = 2152857618;
+     const kErrorBindingAborted = 2152398850;
+ 
+-    const nsIWBP = Components.interfaces.nsIWebBrowserPersist;
+-    const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener;
+-    const nsIChannel = Components.interfaces.nsIChannel;
+-
+-    var wbp = newObject("@mozilla.org/embedding/browser/nsWebBrowserPersist;1",
+-                        nsIWBP);
++    const nsIWBP = Ci.nsIWebBrowserPersist;
++
++    var wbp = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
++                .createInstance(nsIWBP);
+     wbp.progressListener = OutputProgressListener;
+ 
+     var file, saveType, saveFolder, docToBeSaved, title;
+     var flags, fileType, charLimit;
+     var dialogTitle, rv, pm;
+ 
+     // We want proper descriptions and no "All Files" option.
+     const TYPELIST = [[MSG_SAVE_COMPLETEVIEW,"*.htm;*.html"],
+diff --git a/suite/extensions/irc/xul/content/static.js b/suite/extensions/irc/xul/content/static.js
+--- a/suite/extensions/irc/xul/content/static.js
++++ b/suite/extensions/irc/xul/content/static.js
+@@ -2011,36 +2011,32 @@ function updateAlertIcon(aToggle) {
+   let state = alertState ? "on" : "off";
+   let icon = window.document.getElementById("alert-status");
+   icon.setAttribute("alertstate", state);
+   icon.setAttribute("tooltiptext", getMsg("msg.alert.icon." + state));
+ }
+ 
+ function initOfflineIcon()
+ {
+-    const PRBool_CID = "@mozilla.org/supports-PRBool;1";
+-    const OS_CID = "@mozilla.org/observer-service;1";
+-    const nsISupportsPRBool = Components.interfaces.nsISupportsPRBool;
+-
+     client.offlineObserver = {
+         _element: document.getElementById("offline-status"),
+         state: function offline_state()
+         {
+             return (Services.io.offline ? "offline" : "online");
+         },
+         observe: function offline_observe(subject, topic, state)
+         {
+             if ((topic == "offline-requested") &&
+                 (client.getConnectionCount() > 0))
+             {
+                 var buttonAry = [MSG_REALLY_GO_OFFLINE, MSG_DONT_GO_OFFLINE];
+                 var rv = confirmEx(MSG_GOING_OFFLINE, buttonAry);
+                 if (rv == 1) // Don't go offline, please!
+                 {
+-                    subject.QueryInterface(nsISupportsPRBool);
++                    subject.QueryInterface(Ci.nsISupportsPRBool);
+                     subject.data = true;
+                 }
+             }
+             else if (topic == "network:offline-status-changed")
+             {
+                 this.updateOfflineUI();
+             }
+         },
+@@ -2061,17 +2057,18 @@ function initOfflineIcon()
+ 
+             // Actually change the offline state.
+             Services.io.offline = !Services.io.offline;
+         },
+         canGoOffline: function offline_check()
+         {
+             try
+             {
+-                var canGoOffline = newObject(PRBool_CID, "nsISupportsPRBool");
++                var canGoOffline = Cc["@mozilla.org/supports-PRBool;1"]
++                                     .createInstance(Ci.nsISupportsPRBool);
+                 Services.obs.notifyObservers(canGoOffline, "offline-requested");
+                 // Someone called for a halt
+                 if (canGoOffline.data)
+                     return false;
+             }
+             catch (ex)
+             {
+                 dd("Exception when trying to ask if we could go offline:" + ex);

+ 3 - 0
comm-release/patches/series

@@ -2209,3 +2209,6 @@ TOP-1872623-cancelbookmark-25319.patch
 9999999-specificsearch-25320.patch
 1913633-mar-addendum-ids-25320.patch
 1924332-irc-input-paste-25320.patch
+1924336-irc-logins-25320.patch
+1924337-irc-zipReader-25320.patch
+1924338-irc-newObject-25320.patch