Skip to content

Commit

Permalink
OlgaTPark#14 — M1520960 M1660998 - Allow saving passwords in private …
Browse files Browse the repository at this point in the history
…windows with a dismissed-by-default doorhanger and fix preferences accordingly (#637)

Testcases aren't included because they require async/await.

References:
https://bugzilla.mozilla.org/show_bug.cgi?id=1520960 (Allow saving passwords in private windows with a dismissed-by-default doorhanger)
https://hg.mozilla.org/mozilla-central/rev/b4645dc802f9 (Allow login capture from form submissions in private browsing when pref'd on.)
https://hg.mozilla.org/mozilla-central/rev/5656f8b5c547 (Allow login capture from HTTP auth prompts in private browsing when pref'd on.)
https://bugzilla.mozilla.org/show_bug.cgi?id=1660998 (Option to save logins does not keep state in private mode)
https://hg.mozilla.org/mozilla-central/rev/d67d3463b4aa (Don't disable the password manager checkbox in permanent private browsing mode.)
  • Loading branch information
OlgaTPark authored Mar 12, 2021
1 parent a750ff0 commit fcfba09
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 23 deletions.
2 changes: 2 additions & 0 deletions browser/app/profile/firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,8 @@ pref("browser.pocket.oAuthConsumerKey", "40249-e88c401e1b1f2242d9e441c4");
pref("browser.pocket.useLocaleList", true);
pref("browser.pocket.enabledLocales", "cs de en-GB en-US en-ZA es-ES es-MX fr hu it ja ja-JP-mac ko nl pl pt-BR pt-PT ru zh-CN zh-TW");

pref("signon.privateBrowsingCapture.enabled", true);

pref("view_source.tab", true);

pref("dom.webnotifications.serviceworker.enabled", true);
Expand Down
18 changes: 5 additions & 13 deletions browser/components/preferences/in-content/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,15 @@ var gSecurityPane = {

/**
* Enables/disables the Exceptions button used to configure sites where
* passwords are never saved. When browser is set to start in Private
* Browsing mode, the "Remember passwords" UI is useless, so we disable it.
* passwords are never saved.
*/
readSavePasswords: function ()
{
var pref = document.getElementById("signon.rememberSignons");
var excepts = document.getElementById("passwordExceptions");
var prefValue = document.getElementById("signon.rememberSignons").value;
document.getElementById("passwordExceptions").disabled = !prefValue;

if (PrivateBrowsingUtils.permanentPrivateBrowsing) {
document.getElementById("savePasswords").disabled = true;
excepts.disabled = true;
return false;
} else {
excepts.disabled = !pref.value;
// don't override pref value in UI
return undefined;
}
// don't override pref value in UI
return undefined;
},

/**
Expand Down
1 change: 1 addition & 0 deletions modules/libpref/init/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -4098,6 +4098,7 @@ pref("signon.rememberSignons.visibilityToggle", false);
#endif
pref("signon.autofillForms", true);
pref("signon.autologin.proxy", false);
pref("signon.privateBrowsingCapture.enabled", false);
pref("signon.storeWhenAutocompleteOff", true);
pref("signon.ui.experimental", false);
pref("signon.debug", false);
Expand Down
4 changes: 4 additions & 0 deletions toolkit/components/passwordmgr/LoginHelper.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ this.LoginHelper = {
* Warning: this only updates if a logger was created.
*/
debug: Services.prefs.getBoolPref("signon.debug"),
privateBrowsingCaptureEnabled:
Services.prefs.getBoolPref("signon.privateBrowsingCapture.enabled"),

createLogger(aLogPrefix) {
let getMaxLogLevel = () => {
Expand All @@ -54,6 +56,8 @@ this.LoginHelper = {
// Watch for pref changes and update this.debug and the maxLogLevel for created loggers
Services.prefs.addObserver("signon.", () => {
this.debug = Services.prefs.getBoolPref("signon.debug");
this.privateBrowsingCaptureEnabled =
Services.prefs.getBoolPref("signon.privateBrowsingCapture.enabled");
logger.maxLogLevel = getMaxLogLevel();
}, false);

Expand Down
3 changes: 2 additions & 1 deletion toolkit/components/passwordmgr/LoginManagerContent.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,8 @@ var LoginManagerContent = {
var doc = form.ownerDocument;
var win = doc.defaultView;

if (PrivateBrowsingUtils.isContentWindowPrivate(win)) {
if (PrivateBrowsingUtils.isContentWindowPrivate(win) &&
!LoginHelper.privateBrowsingCaptureEnabled) {
// We won't do anything in private browsing mode anyway,
// so there's no need to perform further checks.
log("(form submission ignored in private browsing mode)");
Expand Down
6 changes: 6 additions & 0 deletions toolkit/components/passwordmgr/LoginManagerParent.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "LoginDoorhangers",
"resource://gre/modules/LoginDoorhangers.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "LoginHelper",
"resource://gre/modules/LoginHelper.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
"resource://gre/modules/PrivateBrowsingUtils.jsm");

XPCOMUtils.defineLazyGetter(this, "log", () => {
let logger = LoginHelper.createLogger("LoginManagerParent");
Expand Down Expand Up @@ -435,6 +437,10 @@ var LoginManagerParent = {
}

function recordLoginUse(login) {
if (!target || PrivateBrowsingUtils.isBrowserPrivate(target)) {
// don't record non-interactive use in private browsing
return;
}
// Update the lastUsed timestamp and increment the use count.
let propBag = Cc["@mozilla.org/hash-property-bag;1"].
createInstance(Ci.nsIWritablePropertyBag);
Expand Down
24 changes: 15 additions & 9 deletions toolkit/components/passwordmgr/nsLoginManagerPrompter.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,12 @@ LoginManagerPrompter.prototype = {
}
},

get _allowRememberLogin() {
if (!this._inPrivateBrowsing) {
return true;
}
return LoginHelper.privateBrowsingCaptureEnabled;
},



Expand Down Expand Up @@ -376,10 +382,8 @@ LoginManagerPrompter.prototype = {

// If hostname is null, we can't save this login.
if (hostname) {
var canRememberLogin;
if (this._inPrivateBrowsing)
canRememberLogin = false;
else
var canRememberLogin = false;
if (this._allowRememberLogin)
canRememberLogin = (aSavePassword ==
Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY) &&
this._pwmgr.getLoginSavingEnabled(hostname);
Expand Down Expand Up @@ -614,7 +618,7 @@ LoginManagerPrompter.prototype = {
}

var canRememberLogin = this._pwmgr.getLoginSavingEnabled(hostname);
if (this._inPrivateBrowsing)
if (!this._allowRememberLogin)
canRememberLogin = false;

// if checkboxLabel is null, the checkbox won't be shown at all.
Expand Down Expand Up @@ -828,7 +832,7 @@ LoginManagerPrompter.prototype = {
* This is "password-save" or "password-change" depending on the
* original notification type. This is used for telemetry and tests.
*/
_showLoginCaptureDoorhanger(login, type) {
_showLoginCaptureDoorhanger(login, type, options = {}) {
let { browser } = this._getNotifyWindow();

let saveMsgNames = {
Expand Down Expand Up @@ -1036,7 +1040,7 @@ LoginManagerPrompter.prototype = {
"password-notification-icon",
mainAction,
secondaryActions,
{
Object.assign({
timeout: Date.now() + 10000,
displayURI: Services.io.newURI(login.hostname, null, null),
persistWhileVisible: true,
Expand Down Expand Up @@ -1080,7 +1084,7 @@ LoginManagerPrompter.prototype = {
}
return false;
},
}
}, options)
);
},

Expand Down Expand Up @@ -1120,7 +1124,9 @@ LoginManagerPrompter.prototype = {

// Notification is a PopupNotification
if (aNotifyObj == this._getPopupNote()) {
this._showLoginCaptureDoorhanger(aLogin, "password-save");
this._showLoginCaptureDoorhanger(aLogin, "password-save", {
dismissed: this._inPrivateBrowsing,
});
} else {
var notNowButtonText =
this._getLocalizedString("notifyBarNotNowButtonText");
Expand Down

0 comments on commit fcfba09

Please sign in to comment.