Bug 1351690, part 3 - Move stream converter XPCOM registration constants into the registration file. r=bdahl
authorAndrew McCreight <continuation@gmail.com>
Tue, 22 May 2018 15:37:58 -0700
changeset 804115 5eb08c5b8492287d22674ed747d0932c2cc55f42
parent 804114 21a2a25d8fa04ccdcb225a8459cadfd187135ecd
child 804116 a85debb4f781f9f90ba5c9f0df5e27edecf1102d
push id112312
push userbmo:standard8@mozilla.com
push dateTue, 05 Jun 2018 16:07:56 +0000
reviewersbdahl
bugs1351690
milestone62.0a1
Bug 1351690, part 3 - Move stream converter XPCOM registration constants into the registration file. r=bdahl As with the last patch, the factory is only used for a single class, so move the constants closer to where they are used. This will allow us to register the stream converter without loading the stream converter JSM. MozReview-Commit-ID: DRKVtYQOs2J
browser/extensions/pdfjs/content/PdfJsRegistration.jsm
browser/extensions/pdfjs/content/PdfStreamConverter.jsm
--- a/browser/extensions/pdfjs/content/PdfJsRegistration.jsm
+++ b/browser/extensions/pdfjs/content/PdfJsRegistration.jsm
@@ -20,33 +20,35 @@ var EXPORTED_SYMBOLS = ["PdfJsRegistrati
 const Cm = Components.manager;
 
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 
 // Register/unregister a constructor as a factory.
 function StreamConverterFactory() {}
 StreamConverterFactory.prototype = {
+
+  // properties required for XPCOM registration:
+  _classID: Components.ID("{d0c5195d-e798-49d4-b1d3-9324328b2291}"),
+  _classDescription: "pdf.js Component",
+  _contractID: "@mozilla.org/streamconv;1?from=application/pdf&to=*/*",
+
+  _classID2: Components.ID("{d0c5195d-e798-49d4-b1d3-9324328b2292}"),
+  _contractID2: "@mozilla.org/streamconv;1?from=application/pdf&to=text/html",
+
   register: function register() {
     ChromeUtils.import("resource://pdf.js/PdfStreamConverter.jsm");
-    var proto = PdfStreamConverter.prototype;
-    this._classID = proto.classID;
-
     var factory = XPCOMUtils._getFactory(PdfStreamConverter);
     this._factory = factory;
 
     var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
-    registrar.registerFactory(proto.classID, proto.classDescription,
-                              proto.contractID, factory);
-
-    if (proto.classID2) {
-      this._classID2 = proto.classID2;
-      registrar.registerFactory(proto.classID2, proto.classDescription,
-                                proto.contractID2, factory);
-    }
+    registrar.registerFactory(this._classID, this._classDescription,
+                              this._contractID, factory);
+    registrar.registerFactory(this._classID2, this._classDescription,
+                              this._contractID2, factory);
   },
 
   unregister: function unregister() {
     var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
     registrar.unregisterFactory(this._classID, this._factory);
     if (this._classID2) {
       registrar.unregisterFactory(this._classID2, this._factory);
     }
--- a/browser/extensions/pdfjs/content/PdfStreamConverter.jsm
+++ b/browser/extensions/pdfjs/content/PdfStreamConverter.jsm
@@ -795,25 +795,16 @@ class FindEventManager {
     this.winmm.sendAsyncMessage("PDFJS:Parent:removeEventListener");
   }
 }
 
 function PdfStreamConverter() {
 }
 
 PdfStreamConverter.prototype = {
-
-  // properties required for XPCOM registration:
-  classID: Components.ID("{d0c5195d-e798-49d4-b1d3-9324328b2291}"),
-  classDescription: "pdf.js Component",
-  contractID: "@mozilla.org/streamconv;1?from=application/pdf&to=*/*",
-
-  classID2: Components.ID("{d0c5195d-e798-49d4-b1d3-9324328b2292}"),
-  contractID2: "@mozilla.org/streamconv;1?from=application/pdf&to=text/html",
-
   QueryInterface: ChromeUtils.generateQI([Ci.nsIStreamConverter, Ci.nsIStreamListener, Ci.nsIRequestObserver]),
 
   /*
    * This component works as such:
    * 1. asyncConvertData stores the listener
    * 2. onStartRequest creates a new channel, streams the viewer
    * 3. If range requests are supported:
    *      3.1. Leave the request open until the viewer is ready to switch to