Bug 1417842 - Make Cu.readFile and Cu.readURI UTF-8 aware. r=erahm draft
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Thu, 30 Nov 2017 20:10:44 +0900
changeset 710292 5e11234b57dfa2cee7914da0ebf1af2c037041e3
parent 709637 a461fe03fdb07218b7f50e92c59dde64b8f8a5b0
child 710296 419c63196be01746b89086aa2f4ac4ca826dd645
push id92802
push userVYV03354@nifty.ne.jp
push dateSat, 09 Dec 2017 03:54:30 +0000
reviewerserahm
bugs1417842
milestone59.0a1
Bug 1417842 - Make Cu.readFile and Cu.readURI UTF-8 aware. r=erahm MozReview-Commit-ID: NwQSoAFzjL
js/xpconnect/idl/xpccomponents.idl
js/xpconnect/src/XPCComponents.cpp
toolkit/components/xulstore/XULStore.js
toolkit/mozapps/extensions/internal/XPIProvider.jsm
--- a/js/xpconnect/idl/xpccomponents.idl
+++ b/js/xpconnect/idl/xpccomponents.idl
@@ -704,24 +704,27 @@ interface nsIXPCComponents_Utils : nsISu
      * startup, measured with a monotonic clock.
      */
     double now();
 
     /*
      * Reads the given file and returns its contents. If called during early
      * startup, the file will be pre-read on a background thread during profile
      * startup so its contents will be available the next time they're read.
+     *
+     * The file must be a text file encoded in UTF-8. Otherwise the result is
+     * undefined.
      */
-    ACString readFile(in nsIFile file);
+    AUTF8String readUTF8File(in nsIFile file);
 
     /*
      * Reads the given local file URL and returns its contents. This has the
-     * same semantics of readFile.
+     * same semantics of readUTF8File.
      */
-    ACString readURI(in nsIURI url);
+    AUTF8String readUTF8URI(in nsIURI url);
 
     /**
      * If the main thread is using any kind of fancy cooperative
      * scheduling (e.g., Quantum DOM scheduling),
      * blockThreadedExecution disables it temporarily. The
      * aBlockedCallback is called when it has been completely disabled
      * and events are back to running sequentially on a single main
      * thread. Calling unblockThreadedExecution will re-enable thread
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -3165,26 +3165,26 @@ nsXPCComponents_Utils::AllowCPOWsInAddon
         return NS_ERROR_FAILURE;
     if (!XPCWrappedNativeScope::AllowCPOWsInAddon(cx, addonId, allow))
         return NS_ERROR_FAILURE;
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
-nsXPCComponents_Utils::ReadFile(nsIFile* aFile, nsACString& aResult)
+nsXPCComponents_Utils::ReadUTF8File(nsIFile* aFile, nsACString& aResult)
 {
     NS_ENSURE_TRUE(aFile, NS_ERROR_INVALID_ARG);
 
     MOZ_TRY_VAR(aResult, URLPreloader::ReadFile(aFile));
     return NS_OK;
 }
 
 NS_IMETHODIMP
-nsXPCComponents_Utils::ReadURI(nsIURI* aURI, nsACString& aResult)
+nsXPCComponents_Utils::ReadUTF8URI(nsIURI* aURI, nsACString& aResult)
 {
     NS_ENSURE_TRUE(aURI, NS_ERROR_INVALID_ARG);
 
     MOZ_TRY_VAR(aResult, URLPreloader::ReadURI(aURI));
     return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/toolkit/components/xulstore/XULStore.js
+++ b/toolkit/components/xulstore/XULStore.js
@@ -89,17 +89,17 @@ XULStore.prototype = {
     if (!debugMode)
       return;
     dump("XULStore: " + message + "\n");
     Services.console.logStringMessage("XULStore: " + message);
   },
 
   readFile() {
     try {
-      this._data = JSON.parse(Cu.readFile(this._storeFile));
+      this._data = JSON.parse(Cu.readUTF8File(this._storeFile));
     } catch (e) {
       this.log("Error reading JSON: " + e);
       // This exception could mean that the file didn't exist.
       // We'll just ignore the error and start with a blank slate.
     }
   },
 
   async writeFile() {
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -6369,17 +6369,17 @@ class BuiltInInstallLocation extends Dir
   /**
    * Read the manifest of allowed add-ons and build a mapping between ID and URI
    * for each.
    */
   _readAddons() {
     let manifest;
     try {
       let url = Services.io.newURI(BUILT_IN_ADDONS_URI);
-      let data = Cu.readURI(url);
+      let data = Cu.readUTF8URI(url);
       manifest = JSON.parse(data);
     } catch (e) {
       logger.warn("List of valid built-in add-ons could not be parsed.", e);
       return;
     }
 
     if (!("system" in manifest)) {
       logger.warn("No list of valid system add-ons found.");