55Components . utils . import ( "resource://gre/modules/XPCOMUtils.jsm" ) ;
66Components . utils . import ( "resource://gre/modules/AddonManager.jsm" ) ;
77
8+ // When the user decides to disable or uninstall the add-on, turn the override
9+ // off immediately, instead of waiting for application shutdown. In button.js
10+ // we check the status of the add-on, and prevent the user from turning the
11+ // override back on if the extension is going to be uninstalled or disabled.
812AddonManager . addAddonListener ( {
913 onUninstalling : function ( addon ) {
1014 if ( addon . id == "[email protected] " ) { @@ -21,8 +25,7 @@ AddonManager.addAddonListener({
2125 . getBranch ( "media.navigator.permission." )
2226 . setBoolPref ( "disabled" , false ) ;
2327 }
24- } ,
25- // If user decides to cancel the disable/uninstall, they can just reactivate the override with the toolbar button.
28+ }
2629} ) ;
2730
2831/***********************************************************
@@ -35,36 +38,41 @@ function WebRTCToggle() { }
3538// class definition
3639WebRTCToggle . prototype = {
3740
38- // properties required for XPCOM registration:
39- classDescription : "WebRTC Toggle (WebRTC Permissions UI Override)" ,
40- classID : Components . ID ( "{265ba61d-8b89-4739-acc6-24df0bf7eb70}" ) ,
41- contractID : "@propfire/startup;1" ,
42- QueryInterface : XPCOMUtils . generateQI ( [ Components . interfaces . nsIObserver ] ) ,
41+ // properties required for XPCOM registration:
42+ classDescription : "WebRTC Toggle (WebRTC Permissions UI Override)" ,
43+ classID : Components . ID ( "{265ba61d-8b89-4739-acc6-24df0bf7eb70}" ) ,
44+ contractID : "@propfire/startup;1" ,
45+ QueryInterface : XPCOMUtils . generateQI ( [ Components . interfaces . nsIObserver ] ) ,
4346
44- // add to category manager
45- _xpcom_categories : [ { category : "profile-after-change" } ] ,
47+ // add to category manager
48+ _xpcom_categories : [ { category : "profile-after-change" } ] ,
4649
47- observe : function ( aSubject , aTopic , aData )
48- {
49- switch ( aTopic )
50- {
51- case "profile-after-change" :
52- Components . classes [ "@mozilla.org/observer-service;1" ]
50+ observe : function ( aSubject , aTopic , aData )
51+ {
52+ switch ( aTopic )
53+ {
54+ case "profile-after-change" :
55+ // Set up listeners for the cases below.
56+ Components . classes [ "@mozilla.org/observer-service;1" ]
5357 . getService ( Components . interfaces . nsIObserverService )
5458 . addObserver ( this , "quit-application" , false ) ;
5559
5660 Components . classes [ "@mozilla.org/preferences-service;1" ]
5761 . getService ( Components . interfaces . nsIPrefService )
5862 . getBranch ( "media.navigator.permission." )
5963 . addObserver ( "" , this , false ) ;
60- break ;
64+ break ;
6165 case "quit-application" :
66+ // Turn the override off when closing the application,
67+ // regardless of whether or not the add-on is going to be
68+ // uninstalled.
6269 Components . classes [ "@mozilla.org/preferences-service;1" ]
6370 . getService ( Components . interfaces . nsIPrefService )
6471 . getBranch ( "media.navigator.permission." )
6572 . setBoolPref ( "disabled" , false ) ;
6673 break ;
67- case "nsPref:changed" :
74+ case "nsPref:changed" :
75+ // Determine which message to show to the user.
6876 var title = "WebRTC Permissions UI Toggle" ;
6977 var newValue = Components . classes [ "@mozilla.org/preferences-service;1" ]
7078 . getService ( Components . interfaces . nsIPrefService )
@@ -84,6 +92,9 @@ WebRTCToggle.prototype = {
8492 . getCharPref ( "notify-type" ) ;
8593 switch ( type ) {
8694 case "non-modal" :
95+ // Use nsIAlertsService to show a notification.
96+ // If you want the native Windows 10 notifications you
97+ // can use the GNotifier add-on along with this one.
8798 try {
8899 Components . classes [ '@mozilla.org/alerts-service;1' ]
89100 . getService ( Components . interfaces . nsIAlertsService )
@@ -95,8 +106,10 @@ WebRTCToggle.prototype = {
95106 }
96107 break ;
97108 case "none" :
109+ // User has decided not to show a notification.
98110 break ;
99111 default :
112+ // Use nsIPromptService to show an old-fashioned modal dialog.
100113 try {
101114 Components . classes [ "@mozilla.org/embedcomp/prompt-service;1" ]
102115 . getService ( Components . interfaces . nsIPromptService )
@@ -108,20 +121,20 @@ WebRTCToggle.prototype = {
108121 }
109122 break ;
110123 }
111- break ;
112- default :
113- throw Components . Exception ( "Unknown topic: " + aTopic ) ;
114- }
115- }
124+ break ;
125+ default :
126+ throw Components . Exception ( "Unknown topic: " + aTopic ) ;
127+ }
128+ }
116129} ;
117130
118131var components = [ WebRTCToggle ] ;
119132if ( XPCOMUtils . generateNSGetFactory )
120133{
121- var NSGetFactory = XPCOMUtils . generateNSGetFactory ( components ) ;
134+ var NSGetFactory = XPCOMUtils . generateNSGetFactory ( components ) ;
122135}
123136else
124137{
125- var NSGetModule = XPCOMUtils . generateNSGetModule ( components ) ;
138+ var NSGetModule = XPCOMUtils . generateNSGetModule ( components ) ;
126139}
127140
0 commit comments