From 481cc286ff3fc8f15f4130a923ffa5f269e59206 Mon Sep 17 00:00:00 2001 From: varjolintu Date: Fri, 8 Sep 2017 08:30:20 +0300 Subject: [PATCH] "Fixed showing credentials from previous logins in the popup (credits to smorks) --- CHANGELOG | 3 +- keepassxc-browser/background/event.js | 5 +++ keepassxc-browser/background/page.js | 6 +++- keepassxc-browser/keepassxc-browser.js | 48 ++++++++++++++------------ 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 31eaa61..869d9ad 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,8 +1,9 @@ 0.3.0 (2017-??-??) ========================= - Added Mozilla's browser-polyfill -- Merged changes from the latest passifox (credits to smorks): +- Merged changes from the latest passifox (credits to smorks) - HTTP auth works with all browsers +- Fixed showing credentials from previous login in popup (credits to smorks) - TODO: Automatic detectal of div's with forms that are non-hidden by user interaction 0.2.9 (2017-08-27) diff --git a/keepassxc-browser/background/event.js b/keepassxc-browser/background/event.js index eb3b40b..e053d30 100644 --- a/keepassxc-browser/background/event.js +++ b/keepassxc-browser/background/event.js @@ -233,6 +233,10 @@ event.onMultipleFieldsPopup = function(callback, tab) { browserAction.show(null, tab); } +event.onPageClearLogins = function(callback, tab) { + page.clearLogins(tab.id); + callback(); +} // all methods named in this object have to be declared BEFORE this! event.messageHandlers = { @@ -246,6 +250,7 @@ event.messageHandlers = { 'get_tab_information': event.onGetTabInformation, 'load_keyring': event.onLoadKeyRing, 'load_settings': event.onLoadSettings, + 'page_clear_logins': event.onPageClearLogins, 'pop_stack': event.onPopStack, 'popup_login': event.onLoginPopup, 'popup_multiple-fields': event.onMultipleFieldsPopup, diff --git a/keepassxc-browser/background/page.js b/keepassxc-browser/background/page.js index 1500c81..09a17a6 100644 --- a/keepassxc-browser/background/page.js +++ b/keepassxc-browser/background/page.js @@ -91,7 +91,7 @@ page.clearCredentials = function(tabId, complete) { delete page.tabs[tabId].credentials; if (complete) { - page.tabs[tabId].loginList = []; + page.clearLogins(tabId); browser.tabs.sendMessage(tabId, { action: 'clear_credentials' @@ -99,6 +99,10 @@ page.clearCredentials = function(tabId, complete) { } } +page.clearLogins = function(tabId) { + page.tabs[tabId].loginList = []; +} + page.createTabEntry = function(tabId) { //console.log('page.createTabEntry('+tabId+')'); page.tabs[tabId] = { diff --git a/keepassxc-browser/keepassxc-browser.js b/keepassxc-browser/keepassxc-browser.js index 77d387a..3123813 100644 --- a/keepassxc-browser/keepassxc-browser.js +++ b/keepassxc-browser/keepassxc-browser.js @@ -1115,32 +1115,34 @@ cip.initCredentialFields = function(forceCall) { } _called.initCredentialFields = true; - const inputs = cipFields.getAllFields(); - cipFields.prepareVisibleFieldsWithID('select'); - cip.initPasswordGenerator(inputs); + browser.runtime.sendMessage({ 'action': 'page_clear_logins' }).then(() => { + const inputs = cipFields.getAllFields(); + cipFields.prepareVisibleFieldsWithID('select'); + cip.initPasswordGenerator(inputs); - if (!cipFields.useDefinedCredentialFields()) { - // get all combinations of username + password fields - cipFields.combinations = cipFields.getAllCombinations(inputs); - } - cipFields.prepareCombinations(cipFields.combinations); + if (!cipFields.useDefinedCredentialFields()) { + // get all combinations of username + password fields + cipFields.combinations = cipFields.getAllCombinations(inputs); + } + cipFields.prepareCombinations(cipFields.combinations); - if (cipFields.combinations.length === 0) { - browser.runtime.sendMessage({ - action: 'show_default_browseraction' - }); - return; - } + if (cipFields.combinations.length === 0) { + browser.runtime.sendMessage({ + action: 'show_default_browseraction' + }); + return; + } - cip.url = document.location.origin; - cip.submitUrl = cip.getFormActionUrl(cipFields.combinations[0]); + cip.url = document.location.origin; + cip.submitUrl = cip.getFormActionUrl(cipFields.combinations[0]); - if (cip.settings.autoRetrieveCredentials) { - browser.runtime.sendMessage({ - action: 'retrieve_credentials', - args: [ cip.url, cip.submitUrl ] - }).then(cip.retrieveCredentialsCallback); - } + if (cip.settings.autoRetrieveCredentials) { + browser.runtime.sendMessage({ + action: 'retrieve_credentials', + args: [ cip.url, cip.submitUrl ] + }).then(cip.retrieveCredentialsCallback); + } + }); } // end function init cip.initPasswordGenerator = function(inputs) { @@ -1694,4 +1696,4 @@ cipEvents.triggerActivatedTab = function() { args: [ cip.url, cip.submitUrl ] }).then(cip.retrieveCredentialsCallback); } -} +} \ No newline at end of file