Skip to content

Commit

Permalink
also set mozbrowser access
Browse files Browse the repository at this point in the history
  • Loading branch information
mykmelez committed Oct 13, 2014
1 parent 0e845f7 commit 4a41450
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ var { Cu } = require("chrome");
Cu.import("resource://gre/modules/Services.jsm");

// dom.mozTCPSocket.enabled is not set by default, but it's observed.
// dom.mozContacts.enabled is set by default but ignored, which is why
// dom.mozBrowserFramesEnabled is also not set by default but observed.
// dom.mozContacts.enabled is set by default but ignored! Which is why
// we have to import ContactService.jsm below. So it actually doesn't
// do anything now, but it'll do something in the future, when the bug
// is fixed.
// XXX File the bug!
Services.prefs.setBoolPref("dom.mozTCPSocket.enabled", true);
Services.prefs.setBoolPref("dom.mozBrowserFramesEnabled", true);
Services.prefs.setBoolPref("dom.mozContacts.enabled", true);

// We don't use this directly (which is why we import it into an object literal
Expand All @@ -24,6 +27,7 @@ const TCP_SOCKET_PERM = "tcp-socket";
const CONTACTS_READ_PERM = "contacts-read";
const CONTACTS_WRITE_PERM = "contacts-write";
const CONTACTS_CREATE_PERM = "contacts-create";
const BROWSER_PERM = "browser";
const LABEL_DISABLED = "mozTCPSocket/mozContacts APIs disabled";
const LABEL_ENABLED = "mozTCPSocket/mozContacts APIs enabled";
const ICON_DISABLED = "./unplugged.svg";
Expand Down Expand Up @@ -53,13 +57,15 @@ var button = ActionButton({
Services.perms.addFromPrincipal(getPrincipal(tabs.activeTab), CONTACTS_READ_PERM, Services.perms.ALLOW_ACTION);
Services.perms.addFromPrincipal(getPrincipal(tabs.activeTab), CONTACTS_WRITE_PERM, Services.perms.ALLOW_ACTION);
Services.perms.addFromPrincipal(getPrincipal(tabs.activeTab), CONTACTS_CREATE_PERM, Services.perms.ALLOW_ACTION);
Services.perms.addFromPrincipal(getPrincipal(tabs.activeTab), BROWSER_PERM, Services.perms.ALLOW_ACTION);
button.state("tab", STATE_ENABLED);
}
else {
Services.perms.removeFromPrincipal(getPrincipal(tabs.activeTab), TCP_SOCKET_PERM);
Services.perms.removeFromPrincipal(getPrincipal(tabs.activeTab), CONTACTS_READ_PERM);
Services.perms.removeFromPrincipal(getPrincipal(tabs.activeTab), CONTACTS_WRITE_PERM);
Services.perms.removeFromPrincipal(getPrincipal(tabs.activeTab), CONTACTS_CREATE_PERM);
Services.perms.removeFromPrincipal(getPrincipal(tabs.activeTab), BROWSER_PERM);
button.state("tab", STATE_DISABLED);
}
},
Expand All @@ -70,7 +76,8 @@ tabs.on("pageshow", function(tab) {
if (Services.perms.testPermissionFromPrincipal(getPrincipal(tab), TCP_SOCKET_PERM) == Services.perms.ALLOW_ACTION &&
Services.perms.testPermissionFromPrincipal(getPrincipal(tab), CONTACTS_READ_PERM) == Services.perms.ALLOW_ACTION &&
Services.perms.testPermissionFromPrincipal(getPrincipal(tab), CONTACTS_WRITE_PERM) == Services.perms.ALLOW_ACTION &&
Services.perms.testPermissionFromPrincipal(getPrincipal(tab), CONTACTS_CREATE_PERM) == Services.perms.ALLOW_ACTION) {
Services.perms.testPermissionFromPrincipal(getPrincipal(tab), CONTACTS_CREATE_PERM) == Services.perms.ALLOW_ACTION &&
Services.perms.testPermissionFromPrincipal(getPrincipal(tab), BROWSER_PERM) == Services.perms.ALLOW_ACTION) {
button.state(tab, STATE_ENABLED);
}
else {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"title": "API Enabler",
"name": "tcpsocketpup",
"version": "0.4.0",
"description": "Toggle mozTCPSocket/mozContacts access for a page.",
"version": "0.5.0",
"description": "Toggle mozTCPSocket/mozContacts/mozbrowser access for a page.",
"main": "index.js",
"author": "Myk Melez",
"engines": {
Expand Down

0 comments on commit 4a41450

Please sign in to comment.