Bug 1363482: Part 6 - Add Cu.readFile helper to access the file preloader from JS. r=bholley
authorKris Maglione <maglione.k@gmail.com>
Thu, 31 Aug 2017 17:02:06 -0700
changeset 427915 1f5bed26622ab351107afa822a7218d6603deec6
parent 427914 b4a57caae7d31696b3605daf24f385a5f20ecf24
child 427916 191e7abe8ce4f4398b3a19b22e53a4ec34b84a09
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1363482
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1363482: Part 6 - Add Cu.readFile helper to access the file preloader from JS. r=bholley MozReview-Commit-ID: B7kSvhxbL4f
js/xpconnect/idl/xpccomponents.idl
js/xpconnect/src/XPCComponents.cpp
--- a/js/xpconnect/idl/xpccomponents.idl
+++ b/js/xpconnect/idl/xpccomponents.idl
@@ -9,16 +9,17 @@
 #include "jspubtd.h"
 %}
 
 interface xpcIJSWeakReference;
 interface nsIAddonInterposition;
 interface nsIClassInfo;
 interface nsIComponentManager;
 interface nsICycleCollectorListener;
+interface nsIFile;
 interface nsIJSCID;
 interface nsIJSIID;
 interface nsIPrincipal;
 interface nsIStackFrame;
 
 /**
 * interface of Components.interfacesByID
 * (interesting stuff only reflected into JavaScript)
@@ -688,16 +689,23 @@ interface nsIXPCComponents_Utils : nsISu
     [implicit_jscontext]
     void allowCPOWsInAddon(in ACString addonId, in bool allow);
 
     /*
      * Return a fractional number of milliseconds from process
      * 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.
+     */
+    ACString readFile(in nsIFile file);
 };
 
 /**
 * 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
@@ -16,16 +16,18 @@
 #include "nsCycleCollector.h"
 #include "jsfriendapi.h"
 #include "js/StructuredClone.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/jsipc/CrossProcessObjectWrappers.h"
 #include "mozilla/Preferences.h"
 #include "nsJSEnvironment.h"
 #include "mozilla/TimeStamp.h"
+#include "mozilla/ResultExtensions.h"
+#include "mozilla/URLPreloader.h"
 #include "mozilla/XPTInterfaceInfoManager.h"
 #include "mozilla/dom/DOMException.h"
 #include "mozilla/dom/DOMExceptionBinding.h"
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/dom/StructuredCloneTags.h"
 #include "mozilla/dom/WindowBinding.h"
 #include "nsZipArchive.h"
 #include "nsIDOMFileList.h"
@@ -3375,16 +3377,25 @@ 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)
+{
+    NS_ENSURE_TRUE(aFile, NS_ERROR_INVALID_ARG);
+
+    MOZ_TRY_VAR(aResult, URLPreloader::ReadFile(aFile));
+    return NS_OK;
+}
+
+NS_IMETHODIMP
 nsXPCComponents_Utils::Now(double* aRetval)
 {
     TimeStamp start = TimeStamp::ProcessCreation();
     *aRetval = (TimeStamp::Now() - start).ToMilliseconds();
     return NS_OK;
 }
 
 /***************************************************************************/