diff --git a/firefox_webextension/background.js b/firefox_webextension/background.js
index 5b185ec..d55be2d 100644
--- a/firefox_webextension/background.js
+++ b/firefox_webextension/background.js
@@ -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;
@@ -234,6 +234,8 @@ function update_gpass_icon(iconId, tabId)
break;
default:
}
+
+ debug(icon_name);
icon_infos["path"] = {
16:"icons/gpass" + icon_name + "_icon_16.png",
@@ -245,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)
@@ -267,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);
}
}
@@ -278,7 +297,7 @@ function _query_tabs_is_gpass_enabled(tabs, sendResponse)
is_gpass_enabled(tabs[0].url).then(
function (key_present) {
enabled = (key_present == null);
- update_gpass_icon((enabled)?GPASS_ICON.ENABLED:GPASS_ICON.DISABLED, tabs[0].id);
+ update_gpass_icon((enabled)?GPASS_ICON.NORMAL:GPASS_ICON.DISABLED, tabs[0].id);
sendResponse({"enabled":enabled});
}
);
@@ -300,28 +319,36 @@ 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");
is_gpass_enabled(tab.url).then(
function (key_present)
{
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);
});
}
@@ -361,15 +388,6 @@ function extension_load()
});
return true;
}
- else if (request.type == "switch_enable")
- {
- debug("Switch enable");
- browser.tabs.query({active:true, currentWindow:true},
- function cb(tabs) {
- _query_tabs_switch_enable(tabs, sendResponse)
- });
- return true;
- }
else if (request.type == "update_icon")
{
debug("update_icon");
@@ -387,7 +405,8 @@ function extension_load()
if (!browser.menus && browser.contextMenus)
browser.menus = browser.contextMenus;
-
+
+ /* Settings */
browser.menus.create({
id: 'settings',
title: 'gPass Settings',
@@ -396,16 +415,30 @@ function extension_load()
/* Not supported by Chrome */
if (browser.menus.onShown)
- title = 'disable gPass for this website';
+ title = 'Disable gPass for this website';
else
- title = 'disable or enable gPass for this website';
+ 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) {
@@ -413,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.
*/
+var default_preferences = {"pbkdf2_level": 1000,
+ "account_url": "https://gpass-demo.soutade.fr/demo",
+ "always_disabled":false
+ };
+
function get_preference(key)
{
return browser.storage.local.get(key)
@@ -38,9 +43,11 @@ function get_preference(key)
);
}
-function set_preference(key, value)
+function set_preference(key, value, sendResponse)
{
browser.storage.local.set({[key]:value});
+ if (sendResponse)
+ sendResponse(true);
}
function delete_preference(key)
diff --git a/firefox_webextension/lib/main.js b/firefox_webextension/lib/main.js
index ea39299..29e8143 100644
--- a/firefox_webextension/lib/main.js
+++ b/firefox_webextension/lib/main.js
@@ -56,23 +56,35 @@ function try_get_name(fields, type_filters, match)
for (var i=0; i &&
+ type_filters.push("text");
+ type_filters.push("email");
+ if (all_logins)
+ logins = try_get_name(fields, type_filters, true);
+ else
+ {
+ // Get all other fields except text, email and password
+ type_filters.push("password");
+ type_filters.push("hidden");
+ logins = try_get_name(fields, type_filters, false);
+ }
+
+ return logins;
+}
+
function on_focus(e)
{
- if (gpass_enabled)
+ if (!gpass_enabled)
+ return;
+
+ var logins = get_logins(this.form, true);
+ var all_logins = get_logins(this.form, false);
+
+ if (logins.length || all_logins.length)
{
- parameters = {
+ parameters = {
type:"update_icon",
icon_id:GPASS_ICON.ACTIVATED,
- };
- browser.runtime.sendMessage(parameters, {});
+ };
+ browser.runtime.sendMessage(parameters, {});
}
}
function on_blur(e)
{
- if (gpass_enabled)
- {
- parameters = {
- type:"update_icon",
- icon_id:GPASS_ICON.NORMAL,
- };
- browser.runtime.sendMessage(parameters, {});
- }
+ if (!gpass_enabled)
+ return;
+
+ parameters = {
+ type:"update_icon",
+ icon_id:GPASS_ICON.NORMAL,
+ };
+ browser.runtime.sendMessage(parameters, {});
}
function on_sumbit(e)
@@ -116,15 +159,8 @@ function on_sumbit(e)
debug("on_submit");
- type_filters = new Array();
- // Get all &&
- type_filters.push("text");
- type_filters.push("email");
- logins = try_get_name(fields, type_filters, true);
-
- // Get all other fields except text, email and password
- type_filters.push("password");
- all_logins = try_get_name(fields, type_filters, false);
+ logins = get_logins(form, true);
+ all_logins = get_logins(form, false);
if (!logins.length)
logins = all_logins;
@@ -259,8 +295,6 @@ function unblock_all_forms()
{
debug("unblock all forms");
- on_blur(null);
-
for(var i=0; i",
"activeTab",
"notifications",
- "webRequest",
- "webRequestBlocking",
"tabs",
"storage",
"clipboardWrite",
diff --git a/firefox_webextension/options.html b/firefox_webextension/options.html
index c169be1..14c3756 100644
--- a/firefox_webextension/options.html
+++ b/firefox_webextension/options.html
@@ -8,7 +8,10 @@
Account URL URL of your gPass account WARNING 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.
- PBKDF2 level Number of iterations used to derivate master key
+ PBKDF2 level Number of iterations used to derivate master key
+
+
+ Always disabled Disable gPass for all websites. You can still use popup, but no hook is attached to login forms
diff --git a/firefox_webextension/options.js b/firefox_webextension/options.js
index 5a3a7e0..3225c11 100644
--- a/firefox_webextension/options.js
+++ b/firefox_webextension/options.js
@@ -1,33 +1,47 @@
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;
browser.storage.local.set({
"account_url":account_url,
- "pbkdf2_level":pbkdf2,
+ "pbkdf2_level":pbkdf2_level,
+ "always_disabled": always_disabled,
})
.then(function ok() { alert("Saved"); },
function err() { alert("Cannot save your preferences");}
);
}
+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;
+}
+
function restoreOptions()
{
- document.getElementById('account_url').value = default_preferences['account_url'];
- document.getElementById('pbkdf2').value = default_preferences['pbkdf2_level'];
-
browser.storage.local.get().then(
function(prefs)
{
- if (prefs.hasOwnProperty("account_url"))
- document.getElementById('account_url').value = prefs["account_url"];
-
- if (prefs.hasOwnProperty("pbkdf2_level"))
- document.getElementById('pbkdf2').value = prefs["pbkdf2_level"];
+ restoreOption(prefs, 'account_url');
+ restoreOption(prefs, 'pbkdf2_level');
+ restoreOption(prefs, 'always_disabled');
}
);
}