Bug 1351690, part 4 - Only load the stream converter when we try to view a pdf. r=bdahl

This inlines and simplifies the call to XPCOMUtils._getFactory,
because otherwise passing PdfStreamConverter appears to resolve it
immediately, loading the JSM. (The stream converter prototype does not
have a property _xpcom_factory, so there's no need for the check.)

Once that is done, we can just lazily load the stream converter JSM to
keep it from being loaded on startup.

This patch also checks that the stream converter is not loaded at
startup in the main process or the content process, and that PdfJs.jsm
is not loaded at startup in the content process. It needs to be loaded
in the main process to watch for some prefs.

MozReview-Commit-ID: EA0pSgs4AWH

--HG--
extra : rebase_source : fd79cf660e55a3b4e033b3f112228f36942169ea
This commit is contained in:
Andrew McCreight 2018-05-22 16:13:47 -07:00
parent b13bcee28c
commit d637399f88
3 changed files with 14 additions and 2 deletions

View File

@ -119,6 +119,7 @@ const startupPhases = {
"resource://gre/modules/AsyncPrefs.jsm",
"resource://gre/modules/LoginManagerContextMenu.jsm",
"resource://gre/modules/Task.jsm",
"resource://pdf.js/PdfStreamConverter.jsm",
]),
}},
};

View File

@ -29,6 +29,8 @@ const blacklist = {
"resource://gre/modules/Promise.jsm",
"resource://gre/modules/Task.jsm",
"resource://gre/modules/osfile.jsm",
"resource://pdf.js/PdfJs.jsm",
"resource://pdf.js/PdfStreamConverter.jsm",
]),
services: new Set([
"@mozilla.org/base/telemetry-startup;1",

View File

@ -21,6 +21,8 @@ const Cm = Components.manager;
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.defineModuleGetter(this, "PdfStreamConverter",
"resource://pdf.js/PdfStreamConverter.jsm");
// Register/unregister a constructor as a factory.
function StreamConverterFactory() {}
@ -35,8 +37,15 @@ StreamConverterFactory.prototype = {
_contractID2: "@mozilla.org/streamconv;1?from=application/pdf&to=text/html",
register: function register() {
ChromeUtils.import("resource://pdf.js/PdfStreamConverter.jsm");
var factory = XPCOMUtils._getFactory(PdfStreamConverter);
var factory = {
createInstance(outer, iid) {
if (outer)
throw Cr.NS_ERROR_NO_AGGREGATION;
return (new PdfStreamConverter()).QueryInterface(iid);
},
QueryInterface: ChromeUtils.generateQI([Ci.nsIFactory])
};
this._factory = factory;
var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);