Bug 1348981 - add Cu.readURI helper for sync file reading on startup r?kmag draft
authorRobert Helmer <rhelmer@mozilla.com>
Tue, 19 Sep 2017 12:13:08 -0700
changeset 668853 b80e4bac92ec7ad2f6bbdf7a4ba548d064127c64
parent 668852 362592e3881114d9db568451da37dff39f94ebad
child 668854 03b498be730b1f1341c4831c04db5a8381dc4808
push id81140
push userbmo:rhelmer@mozilla.com
push dateFri, 22 Sep 2017 03:38:54 +0000
reviewerskmag
bugs1348981
milestone58.0a1
Bug 1348981 - add Cu.readURI helper for sync file reading on startup r?kmag MozReview-Commit-ID: 1yz25afCUDs
js/xpconnect/idl/xpccomponents.idl
js/xpconnect/src/XPCComponents.cpp
--- a/js/xpconnect/idl/xpccomponents.idl
+++ b/js/xpconnect/idl/xpccomponents.idl
@@ -10,16 +10,17 @@
 %}
 
 interface xpcIJSWeakReference;
 interface nsIAddonInterposition;
 interface nsIClassInfo;
 interface nsIComponentManager;
 interface nsICycleCollectorListener;
 interface nsIFile;
+interface nsIURI;
 interface nsIJSCID;
 interface nsIJSIID;
 interface nsIPrincipal;
 interface nsIStackFrame;
 
 /**
 * interface of Components.interfacesByID
 * (interesting stuff only reflected into JavaScript)
@@ -696,16 +697,22 @@ interface nsIXPCComponents_Utils : nsISu
     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.
      */
     ACString readFile(in nsIFile file);
+
+    /*
+     * Reads the given local file URL and returns its contents. This has the
+     * same semantics of readFile.
+     */
+    ACString readURI(in nsIURI url);
 };
 
 /**
 * Interface for the 'Components' object.
 *
 * The first interface contains things that are available to non-chrome XBL code
 * that runs in a scope with an ExpandedPrincipal. The second interface
 * includes members that are only exposed to chrome.
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -3393,16 +3393,25 @@ nsXPCComponents_Utils::ReadFile(nsIFile*
 {
     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)
+{
+    NS_ENSURE_TRUE(aURI, NS_ERROR_INVALID_ARG);
+
+    MOZ_TRY_VAR(aResult, URLPreloader::ReadURI(aURI));
+    return NS_OK;
+}
+
+NS_IMETHODIMP
 nsXPCComponents_Utils::Now(double* aRetval)
 {
     TimeStamp start = TimeStamp::ProcessCreation();
     *aRetval = (TimeStamp::Now() - start).ToMilliseconds();
     return NS_OK;
 }
 
 /***************************************************************************/