From 0331847927a26449555843339a9c7060941563d8 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Mon, 31 Oct 2011 13:18:30 +0100 Subject: [PATCH] Add support for disabling the firefox extension on the fly --- extensions/firefox/bootstrap.js | 18 ++++++++++++++---- .../firefox/components/pdfContentHandler.js | 3 +++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/extensions/firefox/bootstrap.js b/extensions/firefox/bootstrap.js index 5384a05df..e51df28f8 100644 --- a/extensions/firefox/bootstrap.js +++ b/extensions/firefox/bootstrap.js @@ -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'); } diff --git a/extensions/firefox/components/pdfContentHandler.js b/extensions/firefox/components/pdfContentHandler.js index 7746e41b6..a23461085 100644 --- a/extensions/firefox/components/pdfContentHandler.js +++ b/extensions/firefox/components/pdfContentHandler.js @@ -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;