Add always_disabled feature
This commit is contained in:
parent
96b378695e
commit
0e48a34d71
|
@ -162,7 +162,7 @@ async function ask_server(logins, domain, wdomain, mkey, sendResponse, options)
|
||||||
{
|
{
|
||||||
debug("New pbkdf2 level " + server_pbkdf2_level);
|
debug("New pbkdf2 level " + server_pbkdf2_level);
|
||||||
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;
|
ret = SERVER.RESTART_REQUEST;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -247,12 +247,29 @@ function update_gpass_icon(iconId, tabId)
|
||||||
browser.browserAction.setIcon(icon_infos);
|
browser.browserAction.setIcon(icon_infos);
|
||||||
}
|
}
|
||||||
|
|
||||||
function is_gpass_enabled(uri)
|
async function is_gpass_enabled(uri)
|
||||||
{
|
{
|
||||||
|
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);
|
var domain = parseURI.parseUri(uri);
|
||||||
domain = domain["host"];
|
domain = domain["host"];
|
||||||
debug("Is gpass enabled for " + domain + " ?");
|
debug("Is gpass enabled for " + domain + " ?");
|
||||||
|
|
||||||
return get_preference("disable-" + domain);
|
return get_preference("disable-" + domain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function save_gpass_enable_config(uri, enable)
|
function save_gpass_enable_config(uri, enable)
|
||||||
|
@ -269,7 +286,7 @@ function save_gpass_enable_config(uri, enable)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
debug("Disable gpass for " + domain);
|
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)
|
function gpass_switch_enable(tab)
|
||||||
{
|
{
|
||||||
debug("Switch enable");
|
debug("Switch enable");
|
||||||
|
@ -311,20 +348,7 @@ function gpass_switch_enable(tab)
|
||||||
enabled = (key_present == null);
|
enabled = (key_present == null);
|
||||||
// Do switch
|
// Do switch
|
||||||
enabled = !enabled;
|
enabled = !enabled;
|
||||||
if (enabled)
|
update_enable(enabled, tab, true);
|
||||||
{
|
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,6 +406,7 @@ function extension_load()
|
||||||
if (!browser.menus && browser.contextMenus)
|
if (!browser.menus && browser.contextMenus)
|
||||||
browser.menus = browser.contextMenus;
|
browser.menus = browser.contextMenus;
|
||||||
|
|
||||||
|
/* Settings */
|
||||||
browser.menus.create({
|
browser.menus.create({
|
||||||
id: 'settings',
|
id: 'settings',
|
||||||
title: 'gPass Settings',
|
title: 'gPass Settings',
|
||||||
|
@ -394,12 +419,26 @@ function extension_load()
|
||||||
else
|
else
|
||||||
title = 'Disable or enable gPass for this website';
|
title = 'Disable or enable gPass for this website';
|
||||||
|
|
||||||
|
/* Enable/disable */
|
||||||
browser.menus.create({
|
browser.menus.create({
|
||||||
id: 'switch_enable',
|
id: 'switch_enable',
|
||||||
title: title,
|
title: title,
|
||||||
contexts: ['browser_action']
|
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(
|
browser.menus.onClicked.addListener(
|
||||||
function(info, tab) {
|
function(info, tab) {
|
||||||
switch (info.menuItemId) {
|
switch (info.menuItemId) {
|
||||||
|
@ -407,6 +446,26 @@ function extension_load()
|
||||||
browser.runtime.openOptionsPage();
|
browser.runtime.openOptionsPage();
|
||||||
break;
|
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':
|
case 'switch_enable':
|
||||||
gpass_switch_enable(tab);
|
gpass_switch_enable(tab);
|
||||||
break;
|
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();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,12 +49,14 @@ function get_preference(key)
|
||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_preference(key, value)
|
function set_preference(key, value, sendResponse)
|
||||||
{
|
{
|
||||||
pref = {[key]:value};
|
pref = {[key]:value};
|
||||||
chrome.storage.local.set(pref, function (result) {
|
chrome.storage.local.set(pref, function (result) {
|
||||||
if (chrome.runtime.lastError)
|
if (chrome.runtime.lastError)
|
||||||
alert(chrome.runtime.lastError);
|
alert(chrome.runtime.lastError);
|
||||||
|
if (sendResponse)
|
||||||
|
sendResponse(chrome.runtime.lastError);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,10 @@
|
||||||
<b>Account URL</b> URL of your gPass account <input id="account_url" type="text"/><br />
|
<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/>
|
<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/>
|
<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/>
|
||||||
<br/>
|
<br/>
|
||||||
<input type="button" id="save" value="Save"/>
|
<input type="button" id="save" value="Save"/>
|
||||||
|
|
|
@ -1,32 +1,42 @@
|
||||||
var default_preferences = {"pbkdf2_level": 1000,
|
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() {
|
function save() {
|
||||||
var account_url = document.getElementById('account_url').value;
|
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({
|
chrome.storage.local.set({
|
||||||
'account_url': account_url,
|
'account_url': account_url,
|
||||||
'pbkdf2': pbkdf2,
|
'pbkdf2_level': pbkdf2_level,
|
||||||
|
'always_disabled': always_disabled,
|
||||||
}, function() {
|
}, function() {
|
||||||
alert('Saved');
|
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) {
|
chrome.storage.local.get(null, function(prefs) {
|
||||||
if (!prefs.hasOwnProperty("account_url"))
|
restoreOption(prefs, 'account_url');
|
||||||
account_url = default_preferences['account_url'];
|
restoreOption(prefs, 'pbkdf2_level');
|
||||||
else
|
restoreOption(prefs, 'always_disabled');
|
||||||
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;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('save').addEventListener("click", save);
|
document.getElementById('save').addEventListener("click", save);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user