Add always_disabled feature

This commit is contained in:
Grégory Soutadé 2021-03-02 14:56:07 +01:00
parent 96b378695e
commit 0e48a34d71
4 changed files with 132 additions and 39 deletions

View File

@ -162,7 +162,7 @@ async function ask_server(logins, domain, wdomain, mkey, sendResponse, options)
{
debug("New pbkdf2 level " + server_pbkdf2_level);
pbkdf2_level = server_pbkdf2_level;
set_preference("pbkdf2_level", pbkdf2_level);
set_preference("pbkdf2_level", pbkdf2_level, null);
ret = SERVER.RESTART_REQUEST;
}
break;
@ -247,12 +247,29 @@ function update_gpass_icon(iconId, tabId)
browser.browserAction.setIcon(icon_infos);
}
function is_gpass_enabled(uri)
async function is_gpass_enabled(uri)
{
var domain = parseURI.parseUri(uri);
domain = domain["host"];
debug("Is gpass enabled for " + domain + " ?");
return get_preference("disable-" + domain);
return await get_preference("always_disabled").then(
function(always_disabled) {
if (always_disabled)
{
debug("Always disabled");
return new Promise(function(resolve, reject) {
resolve(1); // null -> enabled, 1 -> disabled
});
}
else
{
debug("Check for enable");
var domain = parseURI.parseUri(uri);
domain = domain["host"];
debug("Is gpass enabled for " + domain + " ?");
return get_preference("disable-" + domain);
}
}
);
}
function save_gpass_enable_config(uri, enable)
@ -269,7 +286,7 @@ function save_gpass_enable_config(uri, enable)
else
{
debug("Disable gpass for " + domain);
set_preference(key, true);
set_preference(key, true, null);
}
}
@ -302,6 +319,26 @@ function _query_tabs_update_icon(tabs, iconId)
}
}
function update_enable(enabled, tab, saveConfig)
{
if (enabled)
{
parameters = {type:"blockForms"};
saveConfig = true;// Force save when enable website
debug("Now enabled");
}
else
{
parameters = {type:"unblockForms"};
debug("Now disabled");
}
if (saveConfig)
save_gpass_enable_config(tab.url, enabled);
update_gpass_icon((enabled)?GPASS_ICON.NORMAL:GPASS_ICON.DISABLED, tab.id);
browser.tabs.sendMessage(tab.id, parameters);
}
function gpass_switch_enable(tab)
{
debug("Switch enable");
@ -311,20 +348,7 @@ function gpass_switch_enable(tab)
enabled = (key_present == null);
// Do switch
enabled = !enabled;
if (enabled)
{
parameters = {type:"blockForms"};
debug("Now enabled");
}
else
{
parameters = {type:"unblockForms"};
debug("Now disabled");
}
save_gpass_enable_config(tab.url, enabled);
update_gpass_icon((enabled)?GPASS_ICON.ENABLED:GPASS_ICON.DISABLED, tab.id);
browser.tabs.sendMessage(tab.id, parameters);
update_enable(enabled, tab, true);
});
}
@ -381,7 +405,8 @@ function extension_load()
if (!browser.menus && browser.contextMenus)
browser.menus = browser.contextMenus;
/* Settings */
browser.menus.create({
id: 'settings',
title: 'gPass Settings',
@ -394,12 +419,26 @@ function extension_load()
else
title = 'Disable or enable gPass for this website';
/* Enable/disable */
browser.menus.create({
id: 'switch_enable',
title: title,
contexts: ['browser_action']
});
/* Not supported by Chrome */
if (browser.menus.onShown)
title = 'Disable gPass for ALL websites';
else
title = 'Disable or enable gPass for ALL websites';
/* Always enable/disable */
browser.menus.create({
id: 'always_disable',
title: title,
contexts: ['browser_action']
});
browser.menus.onClicked.addListener(
function(info, tab) {
switch (info.menuItemId) {
@ -407,6 +446,26 @@ function extension_load()
browser.runtime.openOptionsPage();
break;
case 'always_disable':
get_preference('always_disabled').then(
function (always_disabled) {
debug('Change always disable');
debug(always_disabled);
always_disabled = !always_disabled;
set_preference('always_disabled', always_disabled,
function(error)
{
browser.tabs.query({},
function cb(tabs) {
for (i=0; i<tabs.length; i++)
update_enable(!always_disabled, tabs[i], false);
});
}
);
}
);
break;
case 'switch_enable':
gpass_switch_enable(tab);
break;
@ -435,6 +494,25 @@ function extension_load()
);
}
);
browser.menus.onShown.addListener(
function(info, tab) {
get_preference('always_disabled').then(
function (always_disabled) {
if (always_disabled)
title = 'Enable gPass for ALL websites';
else
title = 'Disable gPass for ALL websites';
browser.menus.update("always_disable",
{
"title":title
}
);
browser.menus.refresh();
}
);
}
);
}
}

View File

@ -49,12 +49,14 @@ function get_preference(key)
return promise;
}
function set_preference(key, value)
function set_preference(key, value, sendResponse)
{
pref = {[key]:value};
chrome.storage.local.set(pref, function (result) {
if (chrome.runtime.lastError)
alert(chrome.runtime.lastError);
if (sendResponse)
sendResponse(chrome.runtime.lastError);
});
}

View File

@ -8,7 +8,10 @@
<b>Account URL</b> URL of your gPass account <input id="account_url" type="text"/><br />
<b>WARNING</b> It should be a valid HTTPS URL because navigator doesn't like mixed content (HTTPS/HTTP). If not, requests will silentely failed. If you have an auto-signed certificate, add it to trusted ones.<br/>
<br/>
<b>PBKDF2 level</b> Number of iterations used to derivate master key <input id="pbkdf2" type="number"/><br />
<b>PBKDF2 level</b> Number of iterations used to derivate master key <input id="pbkdf2_level" type="number"/><br />
<br/>
<br/>
<b>Always disabled</b> Disable gPass for all websites. You can still use popup, but no hook is attached to login forms<input id="always_disabled" type="checkbox"/><br />
<br/>
<br/>
<input type="button" id="save" value="Save"/>

View File

@ -1,32 +1,42 @@
var default_preferences = {"pbkdf2_level": 1000,
"account_url": "https://gpass-demo.soutade.fr/demo"
"account_url": "https://gpass-demo.soutade.fr/demo",
"always_disabled":false
};
function save() {
var account_url = document.getElementById('account_url').value;
var pbkdf2 = document.getElementById('pbkdf2').value;
var pbkdf2_level = document.getElementById('pbkdf2_level').value;
var always_disabled = document.getElementById('always_disabled').checked;
chrome.storage.local.set({
'account_url': account_url,
'pbkdf2': pbkdf2,
'pbkdf2_level': pbkdf2_level,
'always_disabled': always_disabled,
}, function() {
alert('Saved');
});
}
function restoreOption(preferences, pref)
{
var res;
if (!preferences.hasOwnProperty(pref))
res = default_preferences[pref];
else
res = preferences[pref];
var element = document.getElementById(pref);
if (element.type == 'checkbox')
element.checked = res;
else
element.value = res;
}
chrome.storage.local.get(null, function(prefs) {
if (!prefs.hasOwnProperty("account_url"))
account_url = default_preferences['account_url'];
else
account_url = prefs['account_url'];
if (!prefs.hasOwnProperty("pbkdf2_level"))
pbkdf2 = default_preferences['pbkdf2_level'];
else
pbkdf2 = prefs['pbkdf2_level'];
document.getElementById('account_url').value = account_url;
document.getElementById('pbkdf2').value = pbkdf2;
restoreOption(prefs, 'account_url');
restoreOption(prefs, 'pbkdf2_level');
restoreOption(prefs, 'always_disabled');
});
document.getElementById('save').addEventListener("click", save);