From 3fd578fde2a7b9df860aaaf90f69244c6b467e71 Mon Sep 17 00:00:00 2001 From: Matthew Noorenberghe Date: Wed, 31 Jul 2019 04:36:39 +0000 Subject: [PATCH] Bug 1569093 - Use getLoginOrigin instead of documentURI in LoginManagerContextMenu. r=jaws This properly handles the userPass portion of the URI. Differential Revision: https://phabricator.services.mozilla.com/D39937 --HG-- extra : moz-landing-system : lando --- browser/base/content/nsContextMenu.js | 3 +- .../passwordmgr/LoginManagerContextMenu.jsm | 35 ++++++++++--------- .../test/unit/test_context_menu.js | 4 +-- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/browser/base/content/nsContextMenu.js b/browser/base/content/nsContextMenu.js index c1fd8666ce32..2e57b7396721 100644 --- a/browser/base/content/nsContextMenu.js +++ b/browser/base/content/nsContextMenu.js @@ -1021,10 +1021,11 @@ nsContextMenu.prototype = { } let documentURI = gContextMenuContentData.documentURIObject; + let formOrigin = LoginHelper.getLoginOrigin(documentURI.spec); let fragment = LoginManagerContextMenu.addLoginsToMenu( this.targetIdentifier, this.browser, - documentURI + formOrigin ); let isGeneratedPasswordEnabled = LoginHelper.generationAvailable && LoginHelper.generationEnabled; diff --git a/toolkit/components/passwordmgr/LoginManagerContextMenu.jsm b/toolkit/components/passwordmgr/LoginManagerContextMenu.jsm index 0a03bd881734..42a708b0a442 100644 --- a/toolkit/components/passwordmgr/LoginManagerContextMenu.jsm +++ b/toolkit/components/passwordmgr/LoginManagerContextMenu.jsm @@ -36,14 +36,14 @@ this.LoginManagerContextMenu = { * An identifier generated for the input element via ContentDOMReference. * @param {xul:browser} browser * The browser for the document the context menu was open on. - * @param {nsIURI} documentURI - * The URI of the document that the context menu was activated from. - * This isn't the same as the browser's top-level document URI + * @param {string} formOrigin + * The origin of the document that the context menu was activated from. + * This isn't the same as the browser's top-level document origin * when subframes are involved. * @returns {DocumentFragment} a document fragment with all the login items. */ - addLoginsToMenu(inputElementIdentifier, browser, documentURI) { - let foundLogins = this._findLogins(documentURI); + addLoginsToMenu(inputElementIdentifier, browser, formOrigin) { + let foundLogins = this._findLogins(formOrigin); if (!foundLogins.length) { return null; @@ -77,7 +77,7 @@ this.LoginManagerContextMenu = { login, inputElementIdentifier, browser, - documentURI + formOrigin ); }.bind(this, login) ); @@ -130,18 +130,18 @@ this.LoginManagerContextMenu = { }, /** - * Find logins for the current URI. + * Find logins for the specified origin.. * - * @param {nsIURI} documentURI - * URI object with the origin of the logins we want to find. + * @param {string} formOrigin + * Origin of the logins we want to find that has be sanitized by `getLoginOrigin`. * This isn't the same as the browser's top-level document URI * when subframes are involved. * * @returns {nsILoginInfo[]} a login list */ - _findLogins(documentURI) { + _findLogins(formOrigin) { let searchParams = { - origin: documentURI.displayPrePath, + origin: formOrigin, schemeUpgrades: LoginHelper.schemeUpgrades, }; let logins = LoginHelper.searchLoginsWithObject(searchParams); @@ -150,7 +150,7 @@ this.LoginManagerContextMenu = { logins, ["username", "password"], resolveBy, - documentURI.displayPrePath + formOrigin ); // Sort logins in alphabetical order and by date. @@ -204,16 +204,17 @@ this.LoginManagerContextMenu = { * An identifier generated for the input element via ContentDOMReference. * @param {xul:browser} browser * The target tab browser. - * @param {nsIURI} documentURI - * URI of the document owning the form we want to fill. + * @param {string} formOrigin + * Origin of the document we're filling after sanitization via + * `getLoginOrigin`. * This isn't the same as the browser's top-level - * document URI when subframes are involved. + * origin when subframes are involved. */ - _fillTargetField(login, inputElementIdentifier, browser, documentURI) { + _fillTargetField(login, inputElementIdentifier, browser, formOrigin) { LoginManagerParent.fillForm({ browser, inputElementIdentifier, - loginFormOrigin: documentURI.displayPrePath, + loginFormOrigin: formOrigin, login, }).catch(Cu.reportError); }, diff --git a/toolkit/components/passwordmgr/test/unit/test_context_menu.js b/toolkit/components/passwordmgr/test/unit/test_context_menu.js index a90816068713..0c2c5e8f02d8 100644 --- a/toolkit/components/passwordmgr/test/unit/test_context_menu.js +++ b/toolkit/components/passwordmgr/test/unit/test_context_menu.js @@ -88,13 +88,13 @@ function createLoginsFragment(url, content, elementQuery) { ownerDocument: document, }; - let URI = Services.io.newURI(url); + let formOrigin = LoginHelper.getLoginOrigin(url); return { document, fragment: LoginManagerContextMenu.addLoginsToMenu( inputElement, browser, - URI + formOrigin ), }; }