mirror of
https://github.com/keepassxreboot/keepassxc-browser.git
synced 2026-03-11 08:54:43 +00:00
Fixes memory leaks on idle. Use strict on every script
This commit is contained in:
parent
2596660a6e
commit
358da84180
14 changed files with 71 additions and 50 deletions
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
const browserAction = {};
|
||||
|
||||
const BLINK_TIMEOUT_DEFAULT = 7500;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
const httpAuth = {};
|
||||
|
||||
httpAuth.requests = [];
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
keepass.migrateKeyRing().then(() => {
|
||||
page.initSettings().then(() => {
|
||||
page.initOpenedTabs().then(() => {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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': []
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
var isFirefox = function() {
|
||||
if (!(/Chrome/.test(navigator.userAgent) && /Google/.test(navigator.vendor))) {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
if (jQuery) {
|
||||
var $ = jQuery.noConflict(true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
function status_response(r) {
|
||||
$('#initial-state').hide();
|
||||
$('#error-encountered').hide();
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
var $ = jQuery.noConflict(true);
|
||||
|
||||
function updateAvailableResponse(available) {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
$(function() {
|
||||
browser.runtime.getBackgroundPage().then((global) => {
|
||||
browser.tabs.query({'active': true, 'currentWindow': true}).then((tabs) => {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
$(function() {
|
||||
browser.runtime.getBackgroundPage().then((global) => {
|
||||
browser.tabs.query({'active': true, 'currentWindow': true}).then((tabs) => {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
var _tab;
|
||||
|
||||
function _initialize(tab) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue