]> git.parisson.com Git - pdf.js.git/commitdiff
Add support for disabling the firefox extension on the fly
authorVivien Nicolas <21@vingtetun.org>
Mon, 31 Oct 2011 12:18:30 +0000 (13:18 +0100)
committerVivien Nicolas <21@vingtetun.org>
Mon, 31 Oct 2011 12:18:30 +0000 (13:18 +0100)
extensions/firefox/bootstrap.js
extensions/firefox/components/pdfContentHandler.js

index 5384a05df08b253696cff6fef27c9f948c38f64b..e51df28f8bd2a56202830169819c7a0e9ccde804 100644 (file)
@@ -16,21 +16,31 @@ function log(str) {
 
 function startup(aData, aReason) {
   let manifestPath = 'chrome.manifest';
-  let file = Cc['@mozilla.org/file/local;1'].createInstance(Ci.nsILocalFile);
+  let manifest = Cc['@mozilla.org/file/local;1']
+                   .createInstance(Ci.nsILocalFile);
   try {
-    file.initWithPath(aData.installPath.path);
-    file.append(manifestPath);
-    Cm.QueryInterface(Ci.nsIComponentRegistrar).autoRegister(file);
+    manifest.initWithPath(aData.installPath.path);
+    manifest.append(manifestPath);
+    Cm.QueryInterface(Ci.nsIComponentRegistrar).autoRegister(manifest);
+    Services.prefs.setBoolPref('extensions.pdf.js.active', true);
   } catch (e) {
     log(e);
   }
 }
 
 function shutdown(aData, aReason) {
+  if (Services.prefs.getBoolPref('extensions.pdf.js.active'))
+    Services.prefs.setBoolPref('extensions.pdf.js.active', false);
 }
 
 function install(aData, aReason) {
   let url = 'chrome://pdf.js/content/web/viewer.html?file=%s';
   Services.prefs.setCharPref('extensions.pdf.js.url', url);
+  Services.prefs.setBoolPref('extensions.pdf.js.active', false);
+}
+
+function uninstall(aData, aReason) {
+  Services.prefs.clearUserPref('extensions.pdf.js.url');
+  Services.prefs.clearUserPref('extensions.pdf.js.active');
 }
 
index 7746e41b65a53cf9b8eb5c51156b136524067967..a234610857937244484b621f9b0eb8a2f2c605a3 100644 (file)
@@ -32,6 +32,9 @@ pdfContentHandler.prototype = {
     if (!(aRequest instanceof Ci.nsIChannel))
       throw NS_ERROR_WONT_HANDLE_CONTENT;
 
+    if (!Services.prefs.getBoolPref('extensions.pdf.js.active'))
+      throw NS_ERROR_WONT_HANDLE_CONTENT;
+
     let window = null;
     let callbacks = aRequest.notificationCallbacks ||
                     aRequest.loadGroup.notificationCallbacks;