Skip to content

Commit 629505a

Browse files
committed
Add comments; use tabs instead of spaces in components/WebRTCToggle.js
1 parent 360b30e commit 629505a

File tree

2 files changed

+40
-31
lines changed

2 files changed

+40
-31
lines changed

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ that's open will be able to get access to your microphone, camera, and screen!
1414
So be sure to only turn it on when you need to use WebRTC, and turn it off
1515
once you're done with it.
1616

17-
Closing the entire application, or uninstalling the extension, will always
18-
turn off the override. If you want, you can also have it turn off whenever a
19-
new browser window is opened.
17+
Closing the entire application, or disabling or removing the extension, will
18+
always turn off the override. If you want, you can also have it turn off
19+
whenever a new browser window is opened.
2020

2121
Instructions
2222
------------
@@ -46,10 +46,6 @@ Known Bugs
4646
* If toggling the override is configured to trigger a standard notification
4747
(the default), and you have windows open that were launched from JavaScript,
4848
the notification may appear outside of the top edge of the monitor.
49-
* If toggling the override is configured to trigger a modal dialog, and you
50-
have multiple windows open, multiple notification dialogs will be displayed.
51-
* If the override is on, closing SeaMonkey with File > Exit or Ctrl+Q may not
52-
turn it off.
5349

5450
Notes
5551
-----

components/WebRTCToggle.js

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ XPCOM
55
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
66
Components.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.
812
AddonManager.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
3639
WebRTCToggle.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

118131
var components = [WebRTCToggle];
119132
if (XPCOMUtils.generateNSGetFactory)
120133
{
121-
var NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
134+
var NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
122135
}
123136
else
124137
{
125-
var NSGetModule = XPCOMUtils.generateNSGetModule(components);
138+
var NSGetModule = XPCOMUtils.generateNSGetModule(components);
126139
}
127140

0 commit comments

Comments
 (0)