Skip to content

Commit

Permalink
(1.0.3) Use nsIPromptService for modal dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacSchemm committed Jan 30, 2017
1 parent 10d73ed commit f0b2428
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
28 changes: 18 additions & 10 deletions chrome/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

var prefs = null;
var observerObj = null;
var title = "WebRTC Permissions UI Toggle";

this.addEventListener("load", function () {
prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("media.navigator.permission.");
Expand All @@ -17,11 +18,11 @@ this.addEventListener("load", function () {

var message = "";
if (newValue) {
toolbarbutton.label = toolbarbutton.tooltipText = "WebRTC Auto (On)";
toolbarbutton.label = toolbarbutton.tooltipText = "WebRTC Override (On)";
toolbarbutton.classList.add("setting-true");
message = "Automatic WebRTC connection has been turned on. Make sure to turn it off when you're done!\nYou might need to refresh the current page.";
} else {
toolbarbutton.label = toolbarbutton.tooltipText = "WebRTC Auto (Off)";
toolbarbutton.label = toolbarbutton.tooltipText = "WebRTC Override (Off)";
toolbarbutton.classList.remove("setting-true");
message = "Automatic WebRTC connection has been turned off.";
}
Expand All @@ -35,20 +36,24 @@ this.addEventListener("load", function () {
try {
Components.classes['@mozilla.org/alerts-service;1']
.getService(Components.interfaces.nsIAlertsService)
.showAlertNotification(null, "WebRTC Permissions UI Toggle", message, false, '', null);
.showAlertNotification(null, title, message, false, '', null);
} catch (e) {
alert(message);
Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService)
.alert(thisWindow, title, message);
}
break;
case "none":
break;
default:
try {
alert(message);
Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService)
.alert(thisWindow, title, message);
} catch (e) {
Components.classes['@mozilla.org/alerts-service;1']
.getService(Components.interfaces.nsIAlertsService)
.showAlertNotification(null, "WebRTC Permissions UI Toggle", message, false, '', null);
.showAlertNotification(null, title, message, false, '', null);
}
break;
}
Expand All @@ -60,7 +65,7 @@ this.addEventListener("load", function () {

var value = prefs.getBoolPref("disabled");
if (value) {
toolbarbutton.label = toolbarbutton.tooltipText = "WebRTC Auto (On)";
toolbarbutton.label = toolbarbutton.tooltipText = "WebRTC Override (On)";
toolbarbutton.classList.add("setting-true");

var r = Components.classes["@mozilla.org/preferences-service;1"]
Expand All @@ -71,19 +76,22 @@ this.addEventListener("load", function () {
prefs.setBoolPref("disabled", false);
}
} else {
toolbarbutton.label = toolbarbutton.tooltipText = "WebRTC Auto (Off)";
toolbarbutton.label = toolbarbutton.tooltipText = "WebRTC Override (Off)";
}
});
this.addEventListener("unload", function () {
prefs.removeObserver("", observerObj);
});

WebRTCPermissionsButtons = {
TogglePermissionsUI: function (toolbarbutton) {
TogglePermissionsUI: toolbarbutton => {
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);

var actualValue = prefs.getBoolPref("disabled");
if (actualValue) {
prefs.setBoolPref("disabled", false);
} else if (confirm(`Only use this feature with sites you trust. Sharing can allow deceptive sites to browse as you and steal your private data.
} else if (promptService.confirm(this.window, title, `Only use this feature with sites you trust. Sharing can allow deceptive sites to browse as you and steal your private data.
Are you sure you want to share your camera, microphone, and screen with all open web sites?
`)) {
prefs.setBoolPref("disabled", true);
Expand Down
4 changes: 2 additions & 2 deletions chrome/button.xul
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

<!-- button details -->
<toolbarbutton id="webrtc-permissions-ui-toggle-1"
label="WebRTC Permissions"
tooltiptext="WebRTC Permissions"
label="WebRTC Override"
tooltiptext="WebRTC Override"
oncommand="WebRTCPermissionsButtons.TogglePermissionsUI(this)"
class="webrtc-permissions-ui-button chromeclass-toolbar-additional"
/>
Expand Down
4 changes: 2 additions & 2 deletions install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
about="urn:mozilla:install-manifest"

em:name="WebRTC Permissions UI Toggle"
em:description="A toolbar button to disable the WebRTC permissions dialog and allow media capture automatically."
em:description="A toolbar button for SeaMonkey to override the missing WebRTC permissions dialog and allow media capture automatically."
em:creator="Isaac Schemm"

em:id="webrtc-permissions-ui-toggle@lakora.us"
em:version="1.0.2"
em:version="1.0.3"
em:homepageURL="https://github.com/IsaacSchemm/webrtc-permissions-ui-toggle"

em:iconURL="chrome://webrtc-permissions-ui-toggle/content/icon.png"
Expand Down

0 comments on commit f0b2428

Please sign in to comment.