Bug 1389449 - Fix breakage caused by Gecko 57 api removals. r=gijs
authorFrank-Rainer Grahl <frgrahl@gmx.net>
Thu, 17 Aug 2017 18:03:26 +0200
changeset 2060 4f72d8882106df55a2f03504bb68fe4ac7f126b4
parent 2057 1b2980f49772de1f3834be4d404a0d66ffdb8ae4
child 2123 a9db5fb61a081e082c809030ba4258e543fd0dd3
push id491
push userfrgrahl@gmx.net
push dateThu, 17 Aug 2017 16:04:04 +0000
reviewersgijs
bugs1389449
Bug 1389449 - Fix breakage caused by Gecko 57 api removals. r=gijs
js/lib/file-utils.js
js/lib/pref-manager.js
js/lib/utils.js
xul/content/ceip/ceip.js
xul/content/commands.js
xul/content/static.js
--- a/js/lib/file-utils.js
+++ b/js/lib/file-utils.js
@@ -62,30 +62,30 @@ futils.MSG_OPEN = "Open";
  *                 (title and filter, respectively); when using a string,
  *                 the following standard filters may be used: |$all|, |$html|,
  *                 |$text|, |$images|, |$xml|, |$xul|, |$noAll| (prevents "All
  *                 Files" filter being included).
  * @param attribs Optional. Takes an object with either or both of the
  *                properties: |defaultString| (*defaultFile* in |pick|
  *                functions) sets the initial/default filename, and
  *                |defaultExtension| XXX FIXME (this seems wrong?) XXX.
- * @returns An |Object| with |ok| (Boolean), |file| (|nsILocalFile|) and
+ * @returns An |Object| with |ok| (Boolean), |file| (|nsIFile|) and
  *          |picker| (|nsIFilePicker|) properties.
  */
 futils.getPicker =
 function futils_nosepicker(initialPath, typeList, attribs)
 {
     const classes = Components.classes;
     const interfaces = Components.interfaces;
 
     const PICKER_CTRID = "@mozilla.org/filepicker;1";
     const LOCALFILE_CTRID = "@mozilla.org/file/local;1";
 
     const nsIFilePicker = interfaces.nsIFilePicker;
-    const nsILocalFile = interfaces.nsILocalFile;
+    const nsIFile = interfaces.nsIFile;
 
     var picker = classes[PICKER_CTRID].createInstance(nsIFilePicker);
     if (attribs)
     {
         if (typeof attribs == "object")
         {
             for (var a in attribs)
                 picker[a] = attribs[a];
@@ -98,22 +98,22 @@ function futils_nosepicker(initialPath, 
 
     if (initialPath)
     {
         var localFile;
 
         if (typeof initialPath == "string")
         {
             localFile =
-                classes[LOCALFILE_CTRID].createInstance(nsILocalFile);
+                classes[LOCALFILE_CTRID].createInstance(nsIFile);
             localFile.initWithPath(initialPath);
         }
         else
         {
-            if (!isinstance(initialPath, nsILocalFile))
+            if (!isinstance(initialPath, nsIFile))
                 throw "bad type for argument |initialPath|";
 
             localFile = initialPath;
         }
 
         picker.displayDirectory = localFile
     }
 
@@ -204,17 +204,17 @@ function getPickerChoice(picker)
 /**
  * Displays a standard file save dialog.
  *
  * @param title Optional. The title for the dialog.
  * @param typeList Optional. See |futils.getPicker| for details.
  * @param defaultFile Optional. See |futils.getPicker| for details.
  * @param defaultDir Optional. See |futils.getPicker| for details.
  * @param defaultExt Optional. See |futils.getPicker| for details.
- * @returns An |Object| with "ok" (Boolean), "file" (|nsILocalFile|) and
+ * @returns An |Object| with "ok" (Boolean), "file" (|nsIFile|) and
  *          "picker" (|nsIFilePicker|) properties.
  */
 function pickSaveAs (title, typeList, defaultFile, defaultDir, defaultExt)
 {
     if (!defaultDir && "lastSaveAsDir" in futils)
         defaultDir = futils.lastSaveAsDir;
 
     var picker = futils.getPicker (defaultDir, typeList,
@@ -232,17 +232,17 @@ function pickSaveAs (title, typeList, de
 
 /**
  * Displays a standard file open dialog.
  *
  * @param title Optional. The title for the dialog.
  * @param typeList Optional. See |futils.getPicker| for details.
  * @param defaultFile Optional. See |futils.getPicker| for details.
  * @param defaultDir Optional. See |futils.getPicker| for details.
- * @returns An |Object| with "ok" (Boolean), "file" (|nsILocalFile|) and
+ * @returns An |Object| with "ok" (Boolean), "file" (|nsIFile|) and
  *          "picker" (|nsIFilePicker|) properties.
  */
 function pickOpen (title, typeList, defaultFile, defaultDir)
 {
     if (!defaultDir && "lastOpenDir" in futils)
         defaultDir = futils.lastOpenDir;
 
     var picker = futils.getPicker (defaultDir, typeList,
@@ -257,17 +257,17 @@ function pickOpen (title, typeList, defa
     return rv;
 }
 
 /**
  * Displays a standard directory selection dialog.
  *
  * @param title Optional. The title for the dialog.
  * @param defaultDir Optional. See |futils.getPicker| for details.
- * @returns An |Object| with "ok" (Boolean), "file" (|nsILocalFile|) and
+ * @returns An |Object| with "ok" (Boolean), "file" (|nsIFile|) and
  *          "picker" (|nsIFilePicker|) properties.
  */
 function pickGetFolder(title, defaultDir)
 {
     if (!defaultDir && "lastOpenDir" in futils)
         defaultDir = futils.lastOpenDir;
 
     var picker = futils.getPicker(defaultDir);
@@ -295,20 +295,20 @@ function getTempFile(path, name)
     tempFile.append(name);
     tempFile.createUnique(0, 0600);
     return tempFile;
 }
 
 function nsLocalFile(path)
 {
     const LOCALFILE_CTRID = "@mozilla.org/file/local;1";
-    const nsILocalFile = Components.interfaces.nsILocalFile;
+    const nsIFile = Components.interfaces.nsIFile;
 
     var localFile =
-        Components.classes[LOCALFILE_CTRID].createInstance(nsILocalFile);
+        Components.classes[LOCALFILE_CTRID].createInstance(nsIFile);
     localFile.initWithPath(path);
     return localFile;
 }
 
 function fopen (path, mode, perms, tmp)
 {
     return new LocalFile(path, mode, perms, tmp);
 }
@@ -319,17 +319,16 @@ function LocalFile(file, mode, perms, tm
     const interfaces = Components.interfaces;
 
     const LOCALFILE_CTRID = "@mozilla.org/file/local;1";
     const FILEIN_CTRID = "@mozilla.org/network/file-input-stream;1";
     const FILEOUT_CTRID = "@mozilla.org/network/file-output-stream;1";
     const SCRIPTSTREAM_CTRID = "@mozilla.org/scriptableinputstream;1";
 
     const nsIFile = interfaces.nsIFile;
-    const nsILocalFile = interfaces.nsILocalFile;
     const nsIFileOutputStream = interfaces.nsIFileOutputStream;
     const nsIFileInputStream = interfaces.nsIFileInputStream;
     const nsIScriptableInputStream = interfaces.nsIScriptableInputStream;
 
     if (typeof perms == "undefined")
         perms = 0666 & ~futils.umask;
 
     if (typeof mode == "string")
@@ -349,17 +348,17 @@ function LocalFile(file, mode, perms, tm
                 throw "Invalid mode ``" + mode + "''";
         }
     }
 
     if (typeof file == "string")
     {
         this.localFile = new nsLocalFile(file);
     }
-    else if (isinstance(file, nsILocalFile))
+    else if (isinstance(file, nsIFile))
     {
         this.localFile = file;
     }
     else
     {
         throw "bad type for argument |file|.";
     }
 
--- a/js/lib/pref-manager.js
+++ b/js/lib/pref-manager.js
@@ -28,34 +28,33 @@ function PrefManager (branchName, defaul
     function pm_observe (prefService, topic, prefName)
     {
         prefManager.onPrefChanged(prefName);
     };
 
     const PREF_CTRID = "@mozilla.org/preferences-service;1";
     const nsIPrefService = Components.interfaces.nsIPrefService;
     const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
-    const nsIPrefBranchInternal = Components.interfaces.nsIPrefBranchInternal;
 
     this.prefService =
         Components.classes[PREF_CTRID].getService(nsIPrefService);
     this.prefBranch = this.prefService.getBranch(branchName);
     this.prefSaveTime = 0;
     this.prefSaveTimer = 0;
     this.branchName = branchName;
     this.defaultValues = new Object();
     this.prefs = new Object();
     this.prefNames = new Array();
     this.prefRecords = new Object();
     this.observer = { observe: pm_observe, branch: branchName };
     this.observers = new Array();
 
-    this.prefBranchInternal =
-        this.prefBranch.QueryInterface(nsIPrefBranchInternal);
-    this.prefBranchInternal.addObserver("", this.observer, false);
+    this.nsIPrefBranch =
+        this.prefBranch.QueryInterface(nsIPrefBranch);
+    this.nsIPrefBranch.addObserver("", this.observer, false);
 
     this.defaultBundle = defaultBundle;
 
     this.valid = true;
 }
 
 // Delay between change and save.
 PrefManager.prototype.PREF_SAVE_DELAY =  5000; // 5 seconds.
@@ -65,17 +64,17 @@ PrefManager.prototype.PREF_SAVE_DELAY = 
 PrefManager.prototype.PREF_MAX_DELAY  = 15000; // 15 seconds.
 
 //
 PrefManager.prototype.destroy =
 function pm_destroy()
 {
     if (this.valid)
     {
-        this.prefBranchInternal.removeObserver("", this.observer);
+        this.nsIPrefBranch.removeObserver("", this.observer);
         this.valid = false;
     }
 }
 
 PrefManager.prototype.getBranch =
 function pm_getbranch(suffix)
 {
     return this.prefService.getBranch(this.prefBranch.root + suffix);
--- a/js/lib/utils.js
+++ b/js/lib/utils.js
@@ -1000,17 +1000,17 @@ function getFileFromURLSpec(url)
     if ("getFileFromURLSpec" in service)
         return service.getFileFromURLSpec(url);
 
     /* In builds before 2002-08-15, there is no getFileFromURLSpec at all.
      * Instead, we have nsIIOservice.initFileFromURLSpec(nsIFile, string).
      */
     if ("initFileFromURLSpec" in service)
     {
-        var file = newObject("@mozilla.org/file/local;1", "nsILocalFile");
+        var file = newObject("@mozilla.org/file/local;1", "nsIFile");
         service.initFileFromURLSpec(file, url);
         return file;
     }
 
     var handler = service.getProtocolHandler("file");
     handler = handler.QueryInterface(nsIFileProtocolHandler);
     return handler.getFileFromURLSpec(url);
 }
@@ -1019,22 +1019,22 @@ function getURLSpecFromFile (file)
 {
     if (!file)
         return null;
 
     const IOS_CTRID = "@mozilla.org/network/io-service;1";
     const LOCALFILE_CTRID = "@mozilla.org/file/local;1";
 
     const nsIIOService = Components.interfaces.nsIIOService;
-    const nsILocalFile = Components.interfaces.nsILocalFile;
+    const nsIFile = Components.interfaces.nsIFile;
 
     if (typeof file == "string")
     {
         var fileObj =
-            Components.classes[LOCALFILE_CTRID].createInstance(nsILocalFile);
+            Components.classes[LOCALFILE_CTRID].createInstance(nsIFile);
         fileObj.initWithPath(file);
         file = fileObj;
     }
 
     var service = Components.classes[IOS_CTRID].getService(nsIIOService);
     /* In sept 2002, bug 166792 moved this method to the nsIFileProtocolHandler
      * interface, but we need to support older versions too. */
     if ("getURLSpecFromFile" in service)
--- a/xul/content/ceip/ceip.js
+++ b/xul/content/ceip/ceip.js
@@ -247,29 +247,29 @@ function ceip_writelogline(line)
     catch (ex)
     {}
 }
 
 // @internal
 CEIP.prototype.uploadLogs =
 function ceip_uploadlogs()
 {
-    const nsILocalFile = Components.interfaces.nsILocalFile;
+    const nsIFile = Components.interfaces.nsIFile;
 
     try
     {
         var logPath = this.getLogFolder();
         if (!logPath.exists())
             return;
         var enumerator = logPath.directoryEntries;
         var re = new RegExp("^\\d+\\.xml", "i");
 
         while (enumerator.hasMoreElements())
         {
-            var file = enumerator.getNext().QueryInterface(nsILocalFile);
+            var file = enumerator.getNext().QueryInterface(nsIFile);
             if (re.test(file.leafName))
                 this.uploadLog(file);
         }
     }
     catch(ex)
     {
         this.logEvent({type: "logger", event: "error", method: "uploadLogs",
                        error: formatException(ex)});
--- a/xul/content/commands.js
+++ b/xul/content/commands.js
@@ -4121,27 +4121,27 @@ function cmdDCCSend(e)
     {
         var pickerRv = pickOpen(MSG_DCCFILE_SEND);
         if (!pickerRv.ok)
             return false;
         file = pickerRv.file;
     }
     else
     {
-        // Wrap in try/catch because nsILocalFile creation throws a freaking
+        // Wrap in try/catch because nsIFile creation throws a freaking
         // error if it doesn't get a FULL path.
         try
         {
             file = nsLocalFile(e.file);
         }
         catch(ex)
         {
             // Ok, try user's home directory.
             var fl = Components.classes[DIRSVC_CID].getService(nsIProperties);
-            file = fl.get("Home", Components.interfaces.nsILocalFile);
+            file = fl.get("Home", Components.interfaces.nsIFile);
 
             // Another freaking try/catch wrapper.
             try
             {
                 // NOTE: This is so pathetic it can't cope with any path
                 // separators in it, so don't even THINK about lobing a
                 // relative path at it.
                 file.append(e.file);
--- a/xul/content/static.js
+++ b/xul/content/static.js
@@ -1,14 +1,16 @@
 /* -*- 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/. */
 
+Components.utils.import("resource://gre/modules/Services.jsm");
+
 const __cz_version   = "0.9.93";
 const __cz_condition = "green";
 const __cz_suffix    = "";
 const __cz_guid      = "59c81df5-4b7a-477b-912d-4e0fdf64e5f2";
 const __cz_locale    = "0.9.92";
 
 var warn;
 var ASSERT;
@@ -243,31 +245,48 @@ function initStatic()
     }
     catch (ex)
     {
         dd("Global History failed to initialize: " + ex);
     }
 
     try
     {
-        const nsISDateFormat = Components.interfaces.nsIScriptableDateFormat;
-        const DTFMT_CID = "@mozilla.org/intl/scriptabledateformat;1";
-        client.dtFormatter =
-            Components.classes[DTFMT_CID].createInstance(nsISDateFormat);
-
-        // Mmmm, fun. This ONLY affects the ChatZilla window, don't worry!
-        Date.prototype.toStringInt = Date.prototype.toString;
-        Date.prototype.toString = function() {
-            var dtf = client.dtFormatter;
-            return dtf.FormatDateTime("", dtf.dateFormatLong,
-                                      dtf.timeFormatSeconds,
-                                      this.getFullYear(), this.getMonth() + 1,
-                                      this.getDate(), this.getHours(),
-                                      this.getMinutes(), this.getSeconds()
-                                     );
+        // nsIScriptableDateFormat was removed from Gecko 57
+        // The replacement function was not available in a stable version
+        // prior to Gecko 56.
+        if (Services.vc.compare(Services.appinfo.platformVersion, "56.0") < 0)
+        {
+            const nsISDateFormat = Components.interfaces.nsIScriptableDateFormat;
+            const DTFMT_CID = "@mozilla.org/intl/scriptabledateformat;1";
+            client.dtFormatter =
+                Components.classes[DTFMT_CID].createInstance(nsISDateFormat);
+
+            // Mmmm, fun. This ONLY affects the ChatZilla window, don't worry!
+            Date.prototype.toStringInt = Date.prototype.toString;
+            Date.prototype.toString = function() {
+                var dtf = client.dtFormatter;
+                return dtf.FormatDateTime("", dtf.dateFormatLong,
+                                          dtf.timeFormatSeconds,
+                                          this.getFullYear(), this.getMonth() + 1,
+                                          this.getDate(), this.getHours(),
+                                          this.getMinutes(), this.getSeconds()
+                                         );
+            }
+        }
+        else
+        {
+            client.dtFormatter = Services.intl.createDateTimeFormat(
+                undefined, { dateStyle: "full", timeStyle: "long" });
+
+            // Mmmm, fun. This ONLY affects the ChatZilla window, don't worry!
+            Date.prototype.toStringInt = Date.prototype.toString;
+            Date.prototype.toString = function() {
+                return client.dtFormatter.format(this);
+            }
         }
     }
     catch (ex)
     {
         dd("Locale-correct date formatting failed to initialize: " + ex);
     }
 
     // XXX Bug 335998: See cmdHideView for usage of this.
@@ -747,17 +766,17 @@ function loadPluginDirectory(localPath, 
 
     if (recurse < 1)
         return;
 
     var enumer = localPath.directoryEntries;
     while (enumer.hasMoreElements())
     {
         var entry = enumer.getNext();
-        entry = entry.QueryInterface(Components.interfaces.nsILocalFile);
+        entry = entry.QueryInterface(Components.interfaces.nsIFile);
         if (entry.isDirectory())
             loadPluginDirectory(entry, recurse - 1);
     }
 }
 
 function loadLocalFile(localFile)
 {
     var url = getURLSpecFromFile(localFile);