diff --git a/keepassxc-browser/background/browserAction.js b/keepassxc-browser/background/browserAction.js index d2fdb7d..4a5e7e0 100755 --- a/keepassxc-browser/background/browserAction.js +++ b/keepassxc-browser/background/browserAction.js @@ -1,3 +1,5 @@ +'use strict'; + const browserAction = {}; const BLINK_TIMEOUT_DEFAULT = 7500; diff --git a/keepassxc-browser/background/event.js b/keepassxc-browser/background/event.js index e4fe61e..de3e6e9 100755 --- a/keepassxc-browser/background/event.js +++ b/keepassxc-browser/background/event.js @@ -1,3 +1,5 @@ +'use strict'; + const kpxcEvent = {}; kpxcEvent.onMessage = function(request, sender, callback) { @@ -264,19 +266,10 @@ kpxcEvent.pageClearLogins = function(callback, tab, alreadyCalled) { callback(); }; -kpxcEvent.oldDatabaseHash = 'no-hash'; -kpxcEvent.checkDatabaseHash = function(callback, tab) { - keepass.checkDatabaseHash((response) => { - callback({old: kpxcEvent.oldDatabaseHash, new: response}); - kpxcEvent.oldDatabaseHash = response; - }); -}; - // all methods named in this object have to be declared BEFORE this! kpxcEvent.messageHandlers = { 'add_credentials': keepass.addCredentials, 'associate': keepass.associate, - 'check_databasehash': kpxcEvent.checkDatabaseHash, 'check_update_keepassxc': kpxcEvent.onCheckUpdateKeePassXC, 'generate_password': keepass.generatePassword, 'get_connected_database': kpxcEvent.onGetConnectedDatabase, diff --git a/keepassxc-browser/background/httpauth.js b/keepassxc-browser/background/httpauth.js index 5457caa..cdd23ed 100755 --- a/keepassxc-browser/background/httpauth.js +++ b/keepassxc-browser/background/httpauth.js @@ -1,3 +1,5 @@ +'use strict'; + const httpAuth = {}; httpAuth.requests = []; diff --git a/keepassxc-browser/background/init.js b/keepassxc-browser/background/init.js index 4f6c6af..ce7fed7 100644 --- a/keepassxc-browser/background/init.js +++ b/keepassxc-browser/background/init.js @@ -1,3 +1,5 @@ +'use strict'; + keepass.migrateKeyRing().then(() => { page.initSettings().then(() => { page.initOpenedTabs().then(() => { diff --git a/keepassxc-browser/background/keepass.js b/keepassxc-browser/background/keepass.js index d7edd2f..6dec6aa 100755 --- a/keepassxc-browser/background/keepass.js +++ b/keepassxc-browser/background/keepass.js @@ -18,6 +18,7 @@ keepass.keySize = 24; keepass.latestVersionUrl = 'https://api.github.com/repos/keepassxreboot/keepassxc/releases/latest'; keepass.cacheTimeout = 30 * 1000; // milliseconds keepass.databaseHash = 'no-hash'; //no-hash = KeePassXC is too old and does not return a hash value +keepass.previousDatabaseHash = 'no-hash'; keepass.keyId = 'keepassxc-browser-cryptokey-name'; keepass.keyBody = 'keepassxc-browser-key'; keepass.messageTimeout = 500; // milliseconds @@ -835,11 +836,22 @@ keepass.onNativeMessage = function(response) { // Handle database lock/unlock status if (response.action === kpActions.DATABASE_LOCKED || response.action === kpActions.DATABASE_UNLOCKED) { - keepass.testAssociation((response) => { + keepass.testAssociation((associationResponse) => { keepass.isConfigured().then((configured) => { let data = page.tabs[page.currentTabId].stack[page.tabs[page.currentTabId].stack.length - 1]; data.iconType = configured ? 'normal' : 'cross'; browserAction.show(null, {'id': page.currentTabId}); + + // Send message to content script + browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => { + if (tabs.length) { + browser.tabs.sendMessage(tabs[0].id, { + action: 'check_database_hash', + hash: {old: kpxcEvent.previousDatabaseHash, new: keepass.databaseHash} + }); + keepass.previousDatabaseHash = keepass.databaseHash; + } + }); }); }, null); } diff --git a/keepassxc-browser/background/page.js b/keepassxc-browser/background/page.js index 2d6a2d1..60be892 100755 --- a/keepassxc-browser/background/page.js +++ b/keepassxc-browser/background/page.js @@ -1,3 +1,5 @@ +'use strict'; + const defaultSettings = { checkUpdateKeePassXC: 3, autoCompleteUsernames: true, @@ -11,9 +13,9 @@ const defaultSettings = { }; var page = {}; -page.tabs = {}; +page.tabs = []; page.currentTabId = -1; -page.blockedTabs = {}; +page.blockedTabs = []; page.initSettings = function() { return new Promise((resolve, reject) => { @@ -109,7 +111,7 @@ page.createTabEntry = function(tabId) { page.tabs[tabId] = { 'stack': [], 'errorMessage': null, - 'loginList': {} + 'loginList': [] }; }; diff --git a/keepassxc-browser/global.js b/keepassxc-browser/global.js index 558dc9d..55456cd 100755 --- a/keepassxc-browser/global.js +++ b/keepassxc-browser/global.js @@ -1,3 +1,5 @@ +'use strict'; + var isFirefox = function() { if (!(/Chrome/.test(navigator.userAgent) && /Google/.test(navigator.vendor))) { return true; diff --git a/keepassxc-browser/keepassxc-browser.js b/keepassxc-browser/keepassxc-browser.js index c9561b8..dab0c74 100755 --- a/keepassxc-browser/keepassxc-browser.js +++ b/keepassxc-browser/keepassxc-browser.js @@ -1,3 +1,5 @@ +'use strict'; + // contains already called method names var _called = {}; _called.retrieveCredentials = false; @@ -73,6 +75,9 @@ browser.runtime.onMessage.addListener(function(req, sender, callback) { cip.initCredentialFields(true); }); } + else if (req.action === 'check_database_hash' && 'hash' in req) { + cip.detectDatabaseChange(req.hash); + } } }); @@ -814,7 +819,7 @@ cipFields.prepareId = function(id) { // Check aria-hidden attribute by looping the parent elements of input field cipFields.getAriaHidden = function(field) { let $par = jQuery(field).parents(); - for (p of $par) { + for (const p of $par) { const val = $(p).attr('aria-hidden'); if (val) { return val; @@ -825,7 +830,7 @@ cipFields.getAriaHidden = function(field) { cipFields.getOverflowHidden = function(field) { let $par = jQuery(field).parents(); - for (p of $par) { + for (const p of $par) { const val = $(p).css('overflow'); if (val === 'hidden') { return true; @@ -1155,7 +1160,6 @@ cip.credentials = []; jQuery(function() { cip.init(); cip.detectNewActiveFields(); - cip.detectDatabaseChange(); }); cip.init = function() { @@ -1182,46 +1186,36 @@ cip.detectNewActiveFields = function() { }; // Switch credentials if database is changed or closed -cip.detectDatabaseChange = function() { - let dbDetectInterval = setInterval(function() { - if (document.visibilityState !== 'hidden') { +cip.detectDatabaseChange = function(response) { + if (document.visibilityState !== 'hidden') { + if (response.new === 'no-hash' && response.old !== 'no-hash') { + cipEvents.clearCredentials(); + browser.runtime.sendMessage({ - action: 'check_databasehash' + action: 'page_clear_logins' + }); + + // Switch back to default popup + browser.runtime.sendMessage({ + action: 'get_status', + args: [ true ] // Set polling to true, this is an internal function call + }); + } else if (response.new !== 'no-hash' && response.new !== response.old) { + browser.runtime.sendMessage({ + action: 'load_settings', }).then((response) => { - if (response.new === 'no-hash' && response.old !== 'no-hash') { - cipEvents.clearCredentials(); + cip.settings = response; + cip.initCredentialFields(true); - browser.runtime.sendMessage({ - action: 'page_clear_logins' - }); - - // Switch back to default popup - browser.runtime.sendMessage({ - action: 'get_status', - args: [ true ] // Set polling to true, this is an internal function call - }); - } else { - if (response.new !== 'no-hash' && response.new !== response.old) { - browser.runtime.sendMessage({ - action: 'load_settings', - }).then((response) => { - cip.settings = response; - cip.initCredentialFields(true); - - // If user has requested a manual fill through context menu the actual credential filling - // is handled here when the opened database has been regognized. It's not a pretty hack. - if (_called.manualFillRequested && _called.manualFillRequested !== 'none') { - cip.fillInFromActiveElement(false, (_called.manualFillRequested === 'pass' ? true : false)); - _called.manualFillRequested = 'none'; - } - }); - } + // If user has requested a manual fill through context menu the actual credential filling + // is handled here when the opened database has been regognized. It's not a pretty hack. + if (_called.manualFillRequested && _called.manualFillRequested !== 'none') { + cip.fillInFromActiveElement(false, _called.manualFillRequested === 'pass'); + _called.manualFillRequested = 'none'; } - }).catch((e) => { - console.log(e); }); } - }, 1000); + } }; cip.initCredentialFields = function(forceCall) { diff --git a/keepassxc-browser/options/options.js b/keepassxc-browser/options/options.js index e7db3aa..2b5cad3 100644 --- a/keepassxc-browser/options/options.js +++ b/keepassxc-browser/options/options.js @@ -1,3 +1,5 @@ +'use strict'; + if (jQuery) { var $ = jQuery.noConflict(true); } diff --git a/keepassxc-browser/popups/popup.js b/keepassxc-browser/popups/popup.js index be96e5c..98511aa 100644 --- a/keepassxc-browser/popups/popup.js +++ b/keepassxc-browser/popups/popup.js @@ -1,3 +1,5 @@ +'use strict'; + function status_response(r) { $('#initial-state').hide(); $('#error-encountered').hide(); diff --git a/keepassxc-browser/popups/popup_functions.js b/keepassxc-browser/popups/popup_functions.js index 1eee4ac..83bd82d 100644 --- a/keepassxc-browser/popups/popup_functions.js +++ b/keepassxc-browser/popups/popup_functions.js @@ -1,3 +1,5 @@ +'use strict'; + var $ = jQuery.noConflict(true); function updateAvailableResponse(available) { diff --git a/keepassxc-browser/popups/popup_httpauth.js b/keepassxc-browser/popups/popup_httpauth.js index 9ce9271..cd68d91 100644 --- a/keepassxc-browser/popups/popup_httpauth.js +++ b/keepassxc-browser/popups/popup_httpauth.js @@ -1,3 +1,5 @@ +'use strict'; + $(function() { browser.runtime.getBackgroundPage().then((global) => { browser.tabs.query({'active': true, 'currentWindow': true}).then((tabs) => { diff --git a/keepassxc-browser/popups/popup_login.js b/keepassxc-browser/popups/popup_login.js index eae62d3..b0c2f74 100644 --- a/keepassxc-browser/popups/popup_login.js +++ b/keepassxc-browser/popups/popup_login.js @@ -1,3 +1,5 @@ +'use strict'; + $(function() { browser.runtime.getBackgroundPage().then((global) => { browser.tabs.query({'active': true, 'currentWindow': true}).then((tabs) => { diff --git a/keepassxc-browser/popups/popup_remember.js b/keepassxc-browser/popups/popup_remember.js index be79328..c8de9f1 100644 --- a/keepassxc-browser/popups/popup_remember.js +++ b/keepassxc-browser/popups/popup_remember.js @@ -1,3 +1,5 @@ +'use strict'; + var _tab; function _initialize(tab) {