Skip to content

Commit

Permalink
Bug 1858633 - Pass preselected login as attribute to opened tab. r=cr…
Browse files Browse the repository at this point in the history
…edential-management-reviewers,mtigley

Differential Revision: https://phabricator.services.mozilla.com/D191716
  • Loading branch information
issammani committed Oct 31, 2023
1 parent 5bf0590 commit 34c0bed
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 25 deletions.
9 changes: 9 additions & 0 deletions browser/components/aboutlogins/AboutLoginsParent.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ export class AboutLoginsParent extends JSWindowActorParent {
}
}

get preselectedLogin() {
const preselectedLogin =
this.#ownerGlobal.gBrowser.selectedTab.getAttribute("preselect-login") ||
this.browsingContext.currentURI?.ref;
this.#ownerGlobal.gBrowser.selectedTab.removeAttribute("preselect-login");
return preselectedLogin || null;
}

#deleteLogin(loginObject) {
let login = lazy.LoginHelper.vanillaObjectToLogin(loginObject);
Services.logins.removeLogin(login);
Expand Down Expand Up @@ -316,6 +324,7 @@ export class AboutLoginsParent extends JSWindowActorParent {
importVisible:
Services.policies.isAllowed("profileImport") &&
AppConstants.platform != "linux",
preselectedLogin: this.preselectedLogin,
});

await AboutLogins.sendAllLoginRelatedObjects(
Expand Down
9 changes: 3 additions & 6 deletions browser/components/aboutlogins/content/aboutLogins.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ window.addEventListener("AboutLoginsChromeToContent", event => {
break;
}
case "Setup": {
gElements.loginList.selectLoginByDomainOrGuid(
event.detail.value.preselectedLogin
);
handleAllLogins(event.detail.value.logins);
handleSyncState(event.detail.value.syncState);
gElements.loginList.setSortDirection(event.detail.value.selectedSort);
Expand Down Expand Up @@ -277,12 +280,6 @@ if (searchParamsChanged) {
}

if (!searchParamsChanged) {
if (document.location.hash) {
const loginDomainOrGuid = decodeURIComponent(
document.location.hash.slice(1)
);
gElements.loginList.selectLoginByDomainOrGuid(loginDomainOrGuid);
}
gElements.loginFilter.focus();
document.dispatchEvent(new CustomEvent("AboutLoginsInit", { bubbles: true }));
}
Original file line number Diff line number Diff line change
Expand Up @@ -874,11 +874,12 @@ export default class LoginList extends HTMLElement {
...this._loginGuidsSortedOrder,
].find(guid => visibleLoginsGuids.has(guid));

if (selectedLoginGuid && this._logins[selectedLoginGuid]) {
let { login } = this._logins[selectedLoginGuid];
const selectedLogin = this._logins[selectedLoginGuid]?.login;

if (selectedLogin) {
window.dispatchEvent(
new CustomEvent("AboutLoginsInitialLoginSelected", {
detail: login,
detail: selectedLogin,
})
);
this.updateSelectedLocationHash(selectedLoginGuid);
Expand Down
14 changes: 7 additions & 7 deletions toolkit/components/passwordmgr/LoginHelper.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,6 @@ export const LoginHelper = {
// Get currently active tab's origin
const openedFrom =
window.gBrowser?.selectedTab.linkedBrowser.currentURI.spec;

// If no loginGuid is set, get sanitized origin, this will return null for about:* uris
const preselectedLogin = loginGuid ?? this.getLoginOrigin(openedFrom);

Expand All @@ -1264,13 +1263,14 @@ export const LoginHelper = {
});

const paramsPart = params.toString() ? `?${params}` : "";
const fragmentsPart = preselectedLogin
? `#${window.encodeURIComponent(preselectedLogin)}`
: "";
const destination = `about:logins${paramsPart}${fragmentsPart}`;

// We assume that managementURL has a '?' already
window.openTrustedLinkIn(destination, "tab");
const browser = window.gBrowser ?? window.opener?.gBrowser;

const tab = browser.addTrustedTab(`about:logins${paramsPart}`, {
inBackground: false,
});

tab.setAttribute("preselect-login", preselectedLogin);
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ add_task(async function test_management_filter() {

add_task(
async function test_url_when_opening_password_manager_without_a_filterString() {
sinon.spy(window, "openTrustedLinkIn");
sinon.spy(window.gBrowser, "addTrustedTab");
const openingFunc = () =>
LoginHelper.openPasswordManager(window, {
filterString: "",
entryPoint: "mainmenu",
});
const passwordManager = await openPasswordManager(openingFunc);

const url = window.openTrustedLinkIn.lastCall.args[0];
const url = window.gBrowser.addTrustedTab.lastCall.args[0];

Assert.ok(
!url.includes("filter"),
Expand All @@ -86,21 +86,21 @@ add_task(

Assert.ok(passwordManager, "Login dialog was opened");
await passwordManager.close();
window.openTrustedLinkIn.restore();
window.gBrowser.addTrustedTab.restore();
}
);

add_task(
async function test_url_when_opening_password_manager_with_a_filterString() {
sinon.spy(window, "openTrustedLinkIn");
sinon.spy(window.gBrowser, "addTrustedTab");
const openingFunc = () =>
LoginHelper.openPasswordManager(window, {
filterString: "testFilter",
entryPoint: "mainmenu",
});
const passwordManager = await openPasswordManager(openingFunc);

const url = window.openTrustedLinkIn.lastCall.args[0];
const url = window.gBrowser.addTrustedTab.lastCall.args[0];

Assert.ok(
url.includes("filter"),
Expand All @@ -119,21 +119,21 @@ add_task(

Assert.ok(passwordManager, "Login dialog was opened");
await passwordManager.close();
window.openTrustedLinkIn.restore();
window.gBrowser.addTrustedTab.restore();
}
);

add_task(
async function test_url_when_opening_password_manager_without_filterString_or_entryPoint() {
sinon.spy(window, "openTrustedLinkIn");
sinon.spy(window.gBrowser, "addTrustedTab");
const openingFunc = () =>
LoginHelper.openPasswordManager(window, {
filterString: "",
entryPoint: "",
});
const passwordManager = await openPasswordManager(openingFunc);

const url = window.openTrustedLinkIn.lastCall.args[0];
const url = window.gBrowser.addTrustedTab.lastCall.args[0];

Assert.ok(
!url.includes("filter"),
Expand All @@ -156,6 +156,6 @@ add_task(

Assert.ok(passwordManager, "Login dialog was opened");
await passwordManager.close();
window.openTrustedLinkIn.restore();
window.gBrowser.addTrustedTab.restore();
}
);

0 comments on commit 34c0bed

Please sign in to comment.