Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions keepassxc-browser/background/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ kpxcEvent.showStatus = async function(tab, configured, internalPoll) {
browserAction.showDefault(tab);
}

const errorMessage = page.tabs[tab.id]?.errorMessage ?? undefined;
const usernameFieldDetected = page.tabs[tab.id]?.usernameFieldDetected ?? false;
const iframeDetected = page.tabs[tab.id]?.iframeDetected ?? false;
const errorMessage = await page.getTabErrorMessage(tab);
const usernameFieldDetected = await page.isUsernameFieldDetected(tab);
const iframeDetected = await page.isIframeDetected(tab);

return {
associated: keepass.isAssociated(),

configured: configured,
databaseClosed: keepass.isDatabaseClosed,
encryptionKeyUnrecognized: keepass.isEncryptionKeyUnrecognized,
Expand Down Expand Up @@ -117,8 +116,7 @@ kpxcEvent.lockDatabase = async function(tab) {
};

kpxcEvent.onGetTabInformation = async function(tab) {
const id = tab?.id || page.currentTabId;
return page.tabs[id];
return await page.getTabInformation(tab);
};

kpxcEvent.onGetConnectedDatabase = async function() {
Expand Down Expand Up @@ -176,8 +174,8 @@ kpxcEvent.onHTTPAuthPopup = async function(tab, data) {
await browserAction.show(tab, popupData);
};

kpxcEvent.onUsernameFieldDetected = async function(tab, detected) {
page.tabs[tab.id].usernameFieldDetected = detected;
kpxcEvent.onUsernameFieldDetected = async function(tab, args = []) {
await page.setUsernameFieldDetected(tab, args[0], args[1]);
};

kpxcEvent.onIframeDetected = async function(tab, detected) {
Expand Down
24 changes: 24 additions & 0 deletions keepassxc-browser/background/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,30 @@ page.isIframeAllowed = async function(tab, args = []) {
return hostname.endsWith(baseDomain) && tabUrl.hostname?.endsWith(baseDomain);
};

page.isIframeDetected = async function(tab) {
return page.tabs[tab.id]?.iframeDetected ?? false;
};

page.isUsernameFieldDetected = async function(tab) {
return page.tabs[tab.id]?.usernameFieldDetected ?? false;
};

// Only set if the content script URL matches
page.setUsernameFieldDetected = async function(tab, detected, url) {
if (url === tab?.url) {
page.tabs[tab.id].usernameFieldDetected = detected;
}
};

page.getTabErrorMessage = async function(tab) {
return page.tabs[tab.id]?.errorMessage ?? undefined;
};

page.getTabInformation = async function(tab) {
const id = tab?.id || page.currentTabId;
return page.tabs[id];
};

/**
* Gets the top level domain from URL.
* @param {string} domain Current iframe's hostname
Expand Down
4 changes: 2 additions & 2 deletions keepassxc-browser/content/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ kpxcFields.getAllPageInputs = async function(previousInputs = []) {
if (!kpxc.singleInputEnabledForPage
&& ((fields.length === 1 && fields[0].getLowerCaseAttribute('type') !== 'password')
|| (previousInputs.length === 1 && previousInputs[0].getLowerCaseAttribute('type') !== 'password'))) {
sendMessage('username_field_detected', true);
await sendMessage('username_field_detected', [ true, document.location.href ]);
} else {
sendMessage('username_field_detected', false);
await sendMessage('username_field_detected', [ false, document.location.href ]);
}

await kpxc.initCombinations(inputs);
Expand Down
3 changes: 2 additions & 1 deletion keepassxc-browser/popups/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ const sendMessageToTab = async function(message) {
}

statusResponse(await browser.runtime.sendMessage({
action: 'get_status'
action: 'get_status',
args: [ true ]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This boolean changes the request to an internal call without sending messages to KeePassXC.

}));
});

Expand Down