]> git.parisson.com Git - pdf.js.git/commitdiff
Address mc extension code review.
authorBrendan Dahl <brendan.dahl@gmail.com>
Tue, 20 Mar 2012 16:39:33 +0000 (09:39 -0700)
committerBrendan Dahl <brendan.dahl@gmail.com>
Tue, 20 Mar 2012 16:39:33 +0000 (09:39 -0700)
extensions/firefox/bootstrap.js
extensions/firefox/components/PdfStreamConverter.js

index 627fc7a8988e59c647bc161147420a8e83e145fa..d03812bcbbbeb765dca9b66680db5e752e72dd55 100644 (file)
@@ -10,10 +10,14 @@ let Cc = Components.classes;
 let Ci = Components.interfaces;
 let Cm = Components.manager;
 let Cu = Components.utils;
+let application = Cc['@mozilla.org/fuel/application;1']
+                    .getService(Ci.fuelIApplication);
 
 Cu.import('resource://gre/modules/Services.jsm');
 
 function log(str) {
+  if (!application.prefs.getValue(EXT_PREFIX + '.pdfBugEnabled', false))
+    return;
   dump(str + '\n');
 }
 
@@ -60,12 +64,7 @@ function startup(aData, aReason) {
   var ioService = Services.io;
   var resProt = ioService.getProtocolHandler('resource')
                   .QueryInterface(Ci.nsIResProtocolHandler);
-  var aliasFile = Cc['@mozilla.org/file/local;1']
-                    .createInstance(Ci.nsILocalFile);
-  var componentPath = aData.installPath.clone();
-  componentPath.append('content');
-  aliasFile.initWithPath(componentPath.path);
-  var aliasURI = ioService.newFileURI(aliasFile);
+  var aliasURI = ioService.newURI('content/', 'UTF-8', aData.resourceURI);
   resProt.setSubstitution(RESOURCE_NAME, aliasURI);
 
   // Load the component and register it.
@@ -73,12 +72,9 @@ function startup(aData, aReason) {
                           'components/PdfStreamConverter.js';
   Cu.import(pdfStreamConverterUrl);
   Factory.register(PdfStreamConverter);
-  Services.prefs.setBoolPref('extensions.pdf.js.active', true);
 }
 
 function shutdown(aData, aReason) {
-  if (Services.prefs.getBoolPref('extensions.pdf.js.active'))
-    Services.prefs.setBoolPref('extensions.pdf.js.active', false);
   if (aReason == APP_SHUTDOWN)
     return;
   var ioService = Services.io;
@@ -89,18 +85,14 @@ function shutdown(aData, aReason) {
   // Remove the contract/component.
   Factory.unregister();
   // Unload the converter
-  if (pdfStreamConverterUrl) {
-    Cu.unload(pdfStreamConverterUrl);
-    pdfStreamConverterUrl = null;
-  }
+  Cu.unload(pdfStreamConverterUrl);
+  pdfStreamConverterUrl = null;
 }
 
 function install(aData, aReason) {
-  Services.prefs.setBoolPref('extensions.pdf.js.active', false);
 }
 
 function uninstall(aData, aReason) {
-  Services.prefs.clearUserPref('extensions.pdf.js.active');
   application.prefs.setValue(EXT_PREFIX + '.database', '{}');
 }
 
index 8aeb4a0c9fcdf5f483ef1e5d414073a270ee0190..9375a26909c0747a45e72204181e86b809645654 100644 (file)
@@ -17,7 +17,15 @@ const MAX_DATABASE_LENGTH = 4096;
 Cu.import('resource://gre/modules/XPCOMUtils.jsm');
 Cu.import('resource://gre/modules/Services.jsm');
 
+let application = Cc['@mozilla.org/fuel/application;1']
+                    .getService(Ci.fuelIApplication);
+let privateBrowsing = Cc['@mozilla.org/privatebrowsing;1']
+                        .getService(Ci.nsIPrivateBrowsingService);
+let inPrivateBrowswing = privateBrowsing.privateBrowsingEnabled;
+
 function log(aMsg) {
+  if (!application.prefs.getValue(EXT_PREFIX + '.pdfBugEnabled', false))
+    return;
   let msg = 'PdfStreamConverter.js: ' + (aMsg.join ? aMsg.join('') : aMsg);
   Services.console.logStringMessage(msg);
   dump(msg + '\n');
@@ -40,11 +48,6 @@ function topWindow(win) {
             .QueryInterface(Ci.nsIInterfaceRequestor)
             .getInterface(Ci.nsIDOMWindow);
 }
-let application = Cc['@mozilla.org/fuel/application;1']
-                    .getService(Ci.fuelIApplication);
-let privateBrowsing = Cc['@mozilla.org/privatebrowsing;1']
-                        .getService(Ci.nsIPrivateBrowsingService);
-let inPrivateBrowswing = privateBrowsing.privateBrowsingEnabled;
 
 // All the priviledged actions.
 function ChromeActions() {
@@ -125,9 +128,6 @@ PdfStreamConverter.prototype = {
 
   // nsIStreamConverter::asyncConvertData
   asyncConvertData: function(aFromType, aToType, aListener, aCtxt) {
-    if (!Services.prefs.getBoolPref('extensions.pdf.js.active'))
-      throw Cr.NS_ERROR_NOT_IMPLEMENTED;
-
     // Ignoring HTTP POST requests -- pdf.js has to repeat the request.
     var skipConversion = false;
     try {