[extension] Redesign: the popup in layout C with the custos room, Custos's theme, a new password on sign-up and change-password forms, Save or Update

This commit is contained in:
2026-12-03 01:11:52 +01:00
parent f5dd4b0f54
commit 48dc3dde01
8 changed files with 788 additions and 179 deletions
+49 -5
View File
@@ -103,7 +103,22 @@ function showBadge(tabId) {
api.tabs.onRemoved.addListener((tabId) => offers.delete(tabId));
/** What the popup and the page may see of an offer: never its password. */
const offerView = (o) => (o ? { host: new URL(o.origin).host, username: o.username } : null);
const offerView = (o) => (o ? { host: new URL(o.origin).host, username: o.username, update: o.update } : null);
/**
* Whether Custos already has this login of the site (the offer then says Update), and the username a form without
* one means: a change-password form of a site with one login changes that login. Custos's card decides either way;
* a locked or unsure Custos just makes it a new one here.
*/
async function known(at, username) {
const r = await ask({ op: 'browser_match', ...at });
const logins = r?.ok && Array.isArray(r.logins) ? r.logins : [];
if (!username && logins.length === 1 && typeof logins[0].username === 'string') return { username: logins[0].username, update: true };
return { username, update: logins.some((l) => l.username === username) };
}
/** A message from the extension's own pages (the popup), not from a content script in some page. */
const fromPopup = (sender) => !sender.tab && typeof sender.url === 'string' && sender.url.startsWith(api.runtime.getURL(''));
async function save(tabId) {
const o = offerFor(tabId);
@@ -146,14 +161,22 @@ async function handle(msg, sender) {
if (!at || tabId == null || typeof msg.password !== 'string' || !msg.password || msg.password.length > 4096) {
return { ok: false, error: 'bad_request' };
}
const username = typeof msg.username === 'string' ? msg.username.slice(0, 1024) : '';
const typed = typeof msg.username === 'string' ? msg.username.slice(0, 1024) : '';
const title = new URL(at.origin).host;
offers.set(tabId, { ...at, username, password: msg.password, title, at: Date.now() });
// Kept at once (the page may be going away), then told whether it is an update.
const offer = { ...at, username: typed, password: msg.password, title, update: false, at: Date.now() };
offers.set(tabId, offer);
showBadge(tabId);
// The open connection keeps a service worker (Edge, Chrome) alive, and the offer with it.
void ask({ op: 'browser_status' });
// The open connection also keeps a service worker (Edge, Chrome) alive, and the offer with it.
Object.assign(offer, await known(at, typed));
return { ok: true, offer: offerView(offers.get(tabId)) };
}
case 'generate': {
// A sign-up or change-password field asks for a new password: by its frame's origin, nothing else.
const at = placeOf(sender);
if (!at) return { ok: false, error: 'no_match' };
return ask({ op: 'browser_generate', ...at });
}
case 'pending-save': {
// The top page of the tab that sent the form, on the same site, asks whether to show the offer.
const at = placeOf(sender);
@@ -171,6 +194,20 @@ async function handle(msg, sender) {
showBadge(sender.tab.id);
}
return { ok: true };
case 'match-tab':
case 'totp-tab':
case 'generate-tab':
case 'save-tab':
case 'dismiss-tab':
return fromPopup(sender) ? popupAsks(msg) : { ok: false, error: 'bad_request' };
default:
return { ok: false, error: 'bad_request' };
}
}
/** The popup's requests: always about the active tab's page. */
async function popupAsks(msg) {
switch (msg.kind) {
case 'match-tab': {
// From the popup: the logins for the active tab's page, and any login offered for saving there.
const tab = await activeTab();
@@ -186,6 +223,13 @@ async function handle(msg, sender) {
if (!origin || typeof msg.id !== 'string') return { ok: false, error: 'no_match' };
return ask({ op: 'browser_totp', id: msg.id, origin, top: origin });
}
case 'generate-tab': {
// A new password for the active page, shown in the popup; its Fill hands it to that page's top frame.
const tab = await activeTab();
const origin = tab && originOf(tab.url);
if (!origin) return { ok: false, error: 'no_match' };
return { ...(await ask({ op: 'browser_generate', origin, top: origin })), origin, tab: tab.id };
}
case 'save-tab': {
const tab = await activeTab();
return tab ? save(tab.id) : { ok: false, error: 'gone' };