Skip to content

Commit

Permalink
Add "Block plugins" checkbox to button's context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Infocatcher committed Dec 10, 2012
1 parent 4cfdbf4 commit 434821c
Showing 1 changed file with 68 additions and 32 deletions.
100 changes: 68 additions & 32 deletions Plugins_Permissions/pluginsPermissions.js
@@ -1,4 +1,5 @@
// http://infocatcher.ucoz.net/js/cb/pluginsPermissions.js // http://infocatcher.ucoz.net/js/cb/pluginsPermissions.js
// http://forum.mozilla-russia.org/viewtopic.php?id=57303
// https://github.com/Infocatcher/Custom_Buttons/tree/master/Plugins_Permissions // https://github.com/Infocatcher/Custom_Buttons/tree/master/Plugins_Permissions


// Plugins Permissions button for Custom Buttons // Plugins Permissions button for Custom Buttons
Expand All @@ -10,7 +11,7 @@
// Based on Cookies Permissions button // Based on Cookies Permissions button
// https://github.com/Infocatcher/Custom_Buttons/tree/master/Cookies_Permissions // https://github.com/Infocatcher/Custom_Buttons/tree/master/Cookies_Permissions


// Note: plugins.click_to_play in about:config should be enabled // Note: plugins.click_to_play in about:config ("Block plugins" checkbox) should be enabled


var options = { var options = {
useBaseDomain: { // If set to true, will use short domain like google.com instead of www.google.com useBaseDomain: { // If set to true, will use short domain like google.com instead of www.google.com
Expand Down Expand Up @@ -53,6 +54,9 @@ function _localize(sid) {
allowLabel: "Allow", allowLabel: "Allow",
allowAccesskey: "A", allowAccesskey: "A",


blockPluginsLabel: "Block plugins",
blockPluginsAccesskey: "c",

showPermissionsLabel: "Show Exceptions…", showPermissionsLabel: "Show Exceptions…",
showPermissionsAccesskey: "x", showPermissionsAccesskey: "x",


Expand Down Expand Up @@ -82,6 +86,9 @@ function _localize(sid) {
allowLabel: "Разрешить", allowLabel: "Разрешить",
allowAccesskey: "Р", allowAccesskey: "Р",


blockPluginsLabel: "Блокировать плагины",
blockPluginsAccesskey: "к",

showPermissionsLabel: "Показать исключения…", showPermissionsLabel: "Показать исключения…",
showPermissionsAccesskey: "и", showPermissionsAccesskey: "и",


Expand Down Expand Up @@ -203,6 +210,13 @@ this.permissions = {
label="' + _localize("allowLabel") + '"\ label="' + _localize("allowLabel") + '"\
accesskey="' + _localize("allowAccesskey") + '" />\ accesskey="' + _localize("allowAccesskey") + '" />\
<menuseparator />\ <menuseparator />\
<menuitem\
cb_id="toggleBlock"\
type="checkbox"\
oncommand="this.parentNode.parentNode.permissions.toggleBlock(this.getAttribute(\'checked\') == \'true\');"\
label="' + _localize("blockPluginsLabel") + '"\
accesskey="' + _localize("blockPluginsAccesskey") + '" />\
<menuseparator />\
<menuitem\ <menuitem\
cb_id="openPermissions"\ cb_id="openPermissions"\
oncommand="this.parentNode.parentNode.permissions.openPermissions();"\ oncommand="this.parentNode.parentNode.permissions.openPermissions();"\
Expand Down Expand Up @@ -279,36 +293,44 @@ this.permissions = {
}; };
this.oSvc.addObserver(this.permissionsObserver, "perm-changed", false); this.oSvc.addObserver(this.permissionsObserver, "perm-changed", false);


if(this.options.showDefaultPolicy) { var ps = this.prefs = {
let po = this.prefsObserver = { context: this,
context: this, get branch() {
get prefs() { delete this.branch;
delete this.prefs; return this.branch = Components.classes["@mozilla.org/preferences-service;1"]
return this.prefs = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefService)
.getService(Components.interfaces.nsIPrefService) .getBranch("plugins.click_to_play")
.getBranch("plugins.click_to_play") .QueryInterface(Components.interfaces.nsIPrefBranch2 || Components.interfaces.nsIPrefBranch);
.QueryInterface(Components.interfaces.nsIPrefBranch2 || Components.interfaces.nsIPrefBranch); },
}, get: function(name) {
getBoolPref: function(name) { try {
try { return this.branch.getBoolPref(name || "");
return this.prefs.getBoolPref(name); }
} catch(e) {
catch(e) { Components.utils.reportError(e);
Components.utils.reportError(e); }
} return false;
return false; },
}, set: function(val, name) {
observe: function(subject, topic, data) { try {
if(topic != "nsPref:changed") this.branch.setBoolPref(name || "", val);
return; }
if(data != "") catch(e) {
return; Components.utils.reportError(e);
this.context.defaultDeny = this.getBoolPref(data);
this.context.updButtonState();
} }
}; },
this.defaultDeny = po.getBoolPref(""); observe: function(subject, topic, data) {
po.prefs.addObserver("", po, false); if(topic != "nsPref:changed" || data != "")
return;
var ctx = this.context;
ctx.defaultDeny = this.get();
ctx.updButtonState();
ctx.updToggleBlockItem();
}
};
if(this.options.showDefaultPolicy) {
this.defaultDeny = ps.get();
ps.branch.addObserver("", ps, false);
} }


this.updButtonState(); this.updButtonState();
Expand All @@ -321,8 +343,8 @@ this.permissions = {
gBrowser.removeProgressListener(this.progressListener); gBrowser.removeProgressListener(this.progressListener);
this.oSvc.removeObserver(this.permissionsObserver, "perm-changed"); this.oSvc.removeObserver(this.permissionsObserver, "perm-changed");
if(this.options.showDefaultPolicy) if(this.options.showDefaultPolicy)
this.prefsObserver.prefs.removeObserver("", this.prefsObserver); this.prefs.branch.removeObserver("", this.prefs);
this.progressListener = this.permissionsObserver = this.prefsObserver = null; this.progressListener = this.permissionsObserver = this.prefs = null;
}, },
moveToStatusBar: function() { moveToStatusBar: function() {
var insPoint; var insPoint;
Expand Down Expand Up @@ -414,8 +436,22 @@ this.permissions = {
var mi = this.mp.getElementsByAttribute("cb_permission", permission); var mi = this.mp.getElementsByAttribute("cb_permission", permission);
mi.length && mi[0].setAttribute("checked", "true"); mi.length && mi[0].setAttribute("checked", "true");


this.updToggleBlockItem();

return true; return true;
}, },
updToggleBlockItem: function() {
this.mp.getElementsByAttribute("cb_id", "toggleBlock")[0]
.setAttribute(
"checked",
this.options.showDefaultPolicy
? this.defaultDeny
: this.prefs.get()
);
},
toggleBlock: function(block) {
this.prefs.set(block);
},


openPermissions: function() { openPermissions: function() {
var host = this.options.useBaseDomain.openPermissions var host = this.options.useBaseDomain.openPermissions
Expand Down

0 comments on commit 434821c

Please sign in to comment.