Click here to Skip to main content
Click here to Skip to main content

JavaScript listens to Enable/Disable event of an extension in Firefox4

, 5 Jan 2011
Rate this:
Please Sign up or sign in to vote.
JavaScript can listen to the enable/disable event from Firefox4 and can send to XPCOM components

Introduction

This article explains how a script will receive a notification whenever user will enable or disable an extension in Firefox 4.


Background

The background is in a previous version of Firefox displayed extensions in a separate window but in case of Firefox4, an Add-ons Manager Tab will display all attached extensions with enable/disable button.

JavaScript code

A developer first needs to add addEventListener for the main window and needs to add an addon listener which will listen to each event of the extensions. Refer to the below code:

var listener = {
    onDisabling: function(addon,needsRestart) {  
    if (addon.id == "{{9974FB49-725B-4e4b-AE33-3C0781F1F41D}}") {
    var observerService = Components.classes["@mozilla.org/observer-service;1"]
     .getService(Components.interfaces.nsIObserverService);
    observerService.notifyObservers(null, "user-notification-disable", "Ext is disabled");
	  }
  }  
}       
var listener = {
    onEnabling: function(addon,needsRestart) {  
    if (addon.id == "{{9974FB49-725B-4e4b-AE33-3C0781F1F41D}}") {
    var observerService = Components.classes["@mozilla.org/observer-service;1"]
     .getService(Components.interfaces.nsIObserverService);
    observerService.notifyObservers(null, "user-notification-disable", "Ext is Enabled");
	  }
  }  }
var Hide = { 
onLoad: function() { 
	try { 
	    Components.utils.import("resource://gre/modules/AddonManager.jsm"); 
	    AddonManager.addAddonListener(listener); 
       } 
	catch (ex) {} 
   } 
}; 
window.addEventListener("load", function(e) { Hide.onLoad(e); }, false);

Points of Interest

Script can send a notification to XPCOM component for further action on enable/disable event.

History

This is the first version of the article.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Monu_TCS

India India
No Biography provided

Comments and Discussions

 
GeneralReason for my vote of 5 nice going to user it PinmemberPranay Rana5-Jan-11 20:58 
Reason for my vote of 5
nice going to user it

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 5 Jan 2011
Article Copyright 2011 by Monu_TCS
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid