From 7f95b19264d766e7d45a52642a738711154586e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Tue, 2 Mar 2021 16:54:24 +0100 Subject: [PATCH] Add a checkbox to only copy password into clipboard from popup (and a default behaviour from options) --- chrome_addon/background.js | 8 +++ chrome_addon/compat.js | 3 +- chrome_addon/options.html | 3 +- chrome_addon/options.js | 6 +- chrome_addon/popup/popup.html | 1 + chrome_addon/popup/popup.js | 99 ++++++++++++++++++--------- firefox_webextension/background.js | 8 +++ firefox_webextension/compat.js | 3 +- firefox_webextension/options.html | 3 +- firefox_webextension/options.js | 6 +- firefox_webextension/popup/popup.html | 1 + firefox_webextension/popup/popup.js | 99 ++++++++++++++++++--------- 12 files changed, 166 insertions(+), 74 deletions(-) diff --git a/chrome_addon/background.js b/chrome_addon/background.js index d55be2d..1b044b7 100644 --- a/chrome_addon/background.js +++ b/chrome_addon/background.js @@ -380,6 +380,14 @@ function extension_load() }); return true; } + else if (request.type == "getPopupClipboard") + { + get_preference("popup_clipboard").then( + function (value) { + sendResponse({"value" : value}); + }); + return true; + } else if (request.type == "is_gpass_enabled") { browser.tabs.query({active:true, currentWindow:true}, diff --git a/chrome_addon/compat.js b/chrome_addon/compat.js index dc7c5a0..fe51c5f 100644 --- a/chrome_addon/compat.js +++ b/chrome_addon/compat.js @@ -19,7 +19,8 @@ var default_preferences = {"pbkdf2_level": 1000, "account_url": "https://gpass-demo.soutade.fr/demo", - "always_disabled":false + "always_disabled":false, + "popup_clipboard":false }; function get_preference(key) diff --git a/chrome_addon/options.html b/chrome_addon/options.html index 14c3756..9e95129 100644 --- a/chrome_addon/options.html +++ b/chrome_addon/options.html @@ -10,8 +10,9 @@
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

- Always disabled Disable gPass for all websites. You can still use popup, but no hook is attached to login forms
+ Popup clipboard copy Copy password into clipboard (by default) when using popup


diff --git a/chrome_addon/options.js b/chrome_addon/options.js index b1317f6..54256d5 100644 --- a/chrome_addon/options.js +++ b/chrome_addon/options.js @@ -1,17 +1,20 @@ var default_preferences = {"pbkdf2_level": 1000, "account_url": "https://gpass-demo.soutade.fr/demo", - "always_disabled":false + "always_disabled":false, + "popup_clipboard":false }; function save() { var account_url = document.getElementById('account_url').value; var pbkdf2_level = document.getElementById('pbkdf2_level').value; var always_disabled = document.getElementById('always_disabled').checked; + var popup_clipboard = document.getElementById('popup_clipboard').checked; chrome.storage.local.set({ 'account_url': account_url, 'pbkdf2_level': pbkdf2_level, 'always_disabled': always_disabled, + 'popup_clipboard': popup_clipboard, }, function() { alert('Saved'); }); @@ -37,6 +40,7 @@ chrome.storage.local.get(null, function(prefs) { restoreOption(prefs, 'account_url'); restoreOption(prefs, 'pbkdf2_level'); restoreOption(prefs, 'always_disabled'); + restoreOption(prefs, 'popup_clipboard'); }); document.getElementById('save').addEventListener("click", save); diff --git a/chrome_addon/popup/popup.html b/chrome_addon/popup/popup.html index 8ce7697..a2e4dbd 100644 --- a/chrome_addon/popup/popup.html +++ b/chrome_addon/popup/popup.html @@ -6,6 +6,7 @@
Username
Master key
+ Copy password into clipboard
Your server
diff --git a/chrome_addon/popup/popup.js b/chrome_addon/popup/popup.js index 6fdda46..fdbec67 100644 --- a/chrome_addon/popup/popup.js +++ b/chrome_addon/popup/popup.js @@ -17,7 +17,52 @@ along with gPass. If not, see . */ -var username_filled = false +var username_filled = false; + +function _server_response(response, tabs, do_submit, force_copy) +{ + debug("Get Response"); + if (response.value == SERVER.OK) + { + /* Only copy */ + if (document.getElementById("clipboard").checked) + { + navigator.clipboard.writeText(response.password).then(function() { + notify("Password pasted into clipboard", ""); + window.close(); + }); + + return true; + } + + /* Fill + optional copy */ + parameters = { + "type":"setPassword", + "password":response.password, + "submit":do_submit + }; + send_tab_message(tabs[0].id, parameters, + function(arg) + { + debug("Response to setPassword " + arg); + if (arg === "" || force_copy) + { + navigator.clipboard.writeText(response.password).then(function() { + notify("Password pasted into clipboard", ""); + window.close(); + }); + } + else + { + notify("Password filled", ""); + window.close(); + } + } + ); + } + + return true; +} function _query_tabs_get_password(tabs) { @@ -55,38 +100,11 @@ function _query_tabs_get_password(tabs) }; browser.runtime.sendMessage(parameters, {}, - function (response) - { - debug("Get Response"); - if (response.value == SERVER.OK) - { - parameters = { - "type":"setPassword", - "password":response.password, - "submit":do_submit - }; - send_tab_message(tabs[0].id, parameters, - function(arg) - { - debug("Response to setPassword " + arg); - if (arg === "" || force_copy) - { - navigator.clipboard.writeText(response.password).then(function() { - notify("Password pasted into clipboard", ""); - window.close(); - }); - } - else - { - notify("Password filled", ""); - window.close(); - } - } - ); - } - - return true; - }); + function (response) + { + return _server_response(response, tabs, do_submit, force_copy); + } + ); return true; } @@ -129,9 +147,22 @@ function _query_tabs_init(tabs) } }); + /* Clipboard copy */ + parameters = { + "type":"getPopupClipboard" + }; + + browser.runtime.sendMessage(parameters, {}, + function (response) + { + document.getElementById("clipboard").checked = response.value; + + return true; + }); + /* Setup server link address */ parameters = { - type:"getServerAddress" + "type":"getServerAddress" }; browser.runtime.sendMessage(parameters, {}, diff --git a/firefox_webextension/background.js b/firefox_webextension/background.js index d55be2d..1b044b7 100644 --- a/firefox_webextension/background.js +++ b/firefox_webextension/background.js @@ -380,6 +380,14 @@ function extension_load() }); return true; } + else if (request.type == "getPopupClipboard") + { + get_preference("popup_clipboard").then( + function (value) { + sendResponse({"value" : value}); + }); + return true; + } else if (request.type == "is_gpass_enabled") { browser.tabs.query({active:true, currentWindow:true}, diff --git a/firefox_webextension/compat.js b/firefox_webextension/compat.js index c69fbdd..3affaaf 100644 --- a/firefox_webextension/compat.js +++ b/firefox_webextension/compat.js @@ -19,7 +19,8 @@ var default_preferences = {"pbkdf2_level": 1000, "account_url": "https://gpass-demo.soutade.fr/demo", - "always_disabled":false + "always_disabled":false, + "popup_clipboard":false }; function get_preference(key) diff --git a/firefox_webextension/options.html b/firefox_webextension/options.html index 14c3756..9e95129 100644 --- a/firefox_webextension/options.html +++ b/firefox_webextension/options.html @@ -10,8 +10,9 @@
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

- Always disabled Disable gPass for all websites. You can still use popup, but no hook is attached to login forms
+ Popup clipboard copy Copy password into clipboard (by default) when using popup


diff --git a/firefox_webextension/options.js b/firefox_webextension/options.js index 3225c11..4d8e683 100644 --- a/firefox_webextension/options.js +++ b/firefox_webextension/options.js @@ -1,17 +1,20 @@ var default_preferences = {"pbkdf2_level": 1000, "account_url": "https://gpass-demo.soutade.fr/demo", - "always_disabled":false + "always_disabled":false, + "popup_clipboard":false }; function save() { var account_url = document.getElementById('account_url').value; var pbkdf2_level = document.getElementById('pbkdf2_level').value; var always_disabled = document.getElementById('always_disabled').checked; + var popup_clipboard = document.getElementById('popup_clipboard').checked; browser.storage.local.set({ "account_url":account_url, "pbkdf2_level":pbkdf2_level, "always_disabled": always_disabled, + "popup_clipboard": popup_clipboard, }) .then(function ok() { alert("Saved"); }, function err() { alert("Cannot save your preferences");} @@ -42,6 +45,7 @@ function restoreOptions() restoreOption(prefs, 'account_url'); restoreOption(prefs, 'pbkdf2_level'); restoreOption(prefs, 'always_disabled'); + restoreOption(prefs, 'popup_clipboard'); } ); } diff --git a/firefox_webextension/popup/popup.html b/firefox_webextension/popup/popup.html index 8ce7697..a2e4dbd 100644 --- a/firefox_webextension/popup/popup.html +++ b/firefox_webextension/popup/popup.html @@ -6,6 +6,7 @@
Username
Master key
+ Copy password into clipboard
Your server
diff --git a/firefox_webextension/popup/popup.js b/firefox_webextension/popup/popup.js index 6fdda46..fdbec67 100644 --- a/firefox_webextension/popup/popup.js +++ b/firefox_webextension/popup/popup.js @@ -17,7 +17,52 @@ along with gPass. If not, see . */ -var username_filled = false +var username_filled = false; + +function _server_response(response, tabs, do_submit, force_copy) +{ + debug("Get Response"); + if (response.value == SERVER.OK) + { + /* Only copy */ + if (document.getElementById("clipboard").checked) + { + navigator.clipboard.writeText(response.password).then(function() { + notify("Password pasted into clipboard", ""); + window.close(); + }); + + return true; + } + + /* Fill + optional copy */ + parameters = { + "type":"setPassword", + "password":response.password, + "submit":do_submit + }; + send_tab_message(tabs[0].id, parameters, + function(arg) + { + debug("Response to setPassword " + arg); + if (arg === "" || force_copy) + { + navigator.clipboard.writeText(response.password).then(function() { + notify("Password pasted into clipboard", ""); + window.close(); + }); + } + else + { + notify("Password filled", ""); + window.close(); + } + } + ); + } + + return true; +} function _query_tabs_get_password(tabs) { @@ -55,38 +100,11 @@ function _query_tabs_get_password(tabs) }; browser.runtime.sendMessage(parameters, {}, - function (response) - { - debug("Get Response"); - if (response.value == SERVER.OK) - { - parameters = { - "type":"setPassword", - "password":response.password, - "submit":do_submit - }; - send_tab_message(tabs[0].id, parameters, - function(arg) - { - debug("Response to setPassword " + arg); - if (arg === "" || force_copy) - { - navigator.clipboard.writeText(response.password).then(function() { - notify("Password pasted into clipboard", ""); - window.close(); - }); - } - else - { - notify("Password filled", ""); - window.close(); - } - } - ); - } - - return true; - }); + function (response) + { + return _server_response(response, tabs, do_submit, force_copy); + } + ); return true; } @@ -129,9 +147,22 @@ function _query_tabs_init(tabs) } }); + /* Clipboard copy */ + parameters = { + "type":"getPopupClipboard" + }; + + browser.runtime.sendMessage(parameters, {}, + function (response) + { + document.getElementById("clipboard").checked = response.value; + + return true; + }); + /* Setup server link address */ parameters = { - type:"getServerAddress" + "type":"getServerAddress" }; browser.runtime.sendMessage(parameters, {},