Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
Re-add login saving exception when it is somehow removed
Browse files Browse the repository at this point in the history
- Add onLoginSavingChanged event to Logins API experiment to react to
  changes in login saving exceptions

- Watch for the removal of the login saving exception for this add-on's
  management pages. Re-add when removed.

Fixes #57
  • Loading branch information
lmorchard committed Feb 8, 2019
1 parent 2280b0c commit 59c1ce4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/background/environment.js
Expand Up @@ -4,11 +4,22 @@

export async function initializeEnvironment() {
// Issue #57: Disable login saving for extension pages.
const origin = browser.extension.getURL("").slice(0, -1);
const ourOrigin = browser.extension.getURL("").slice(0, -1);

// If login saving is enabled for us on startup, add an exception.
const savingEnabled = await browser.experiments.logins
.getLoginSavingEnabled(origin);
.getLoginSavingEnabled(ourOrigin);
if (savingEnabled) {
await browser.experiments.logins
.setLoginSavingEnabled(origin, false);
.setLoginSavingEnabled(ourOrigin, false);
}

// HACK: If our exception to login saving is removed, immediately re-add it.
browser.experiments.logins.onLoginSavingChanged
.addListener((origin, isEnabled) => {
if (origin === ourOrigin && !isEnabled) {
browser.experiments.logins
.setLoginSavingEnabled(ourOrigin, false);
}
});
}
28 changes: 28 additions & 0 deletions src/experiments/logins/api.js
Expand Up @@ -230,6 +230,34 @@ this.logins = class extends ExtensionAPI {
Services.obs.removeObserver(observer, "passwordmgr-storage-changed");
};
}).api(),
onLoginSavingChanged: new EventManager(context, "logins.onLoginSavingChanged", fire => {
const observer = {
observe: (permission, topic, type) => {
const { principal, type: permissionType } = permission;
const { origin } = principal;

if (permissionType != "login-saving") {
return;
}

let isEnabled;
if (type === "added") {
isEnabled = true;
} else if (type === "deleted") {
isEnabled = false;
} else {
return;
}

fire.async(origin, isEnabled);
},
};
const observedTopic = "perm-changed";
Services.obs.addObserver(observer, observedTopic);
return () => {
Services.obs.removeObserver(observer, observedTopic);
};
}).api(),
},
},
};
Expand Down
17 changes: 17 additions & 0 deletions src/experiments/logins/schema.json
Expand Up @@ -196,6 +196,23 @@
"name": "onAllRemoved",
"type": "function",
"description": "Fired when all Logins are removed."
},
{
"name": "onLoginSavingChanged",
"type": "function",
"description": "Fired when exceptions for login saving have changed",
"parameters": [
{
"name": "aHost",
"type": "string",
"description": "The origin for login saving exception"
},
{
"name": "isEnabled",
"type": "boolean",
"description": "Whether the exception was enabled (true) or removed (false)"
}
]
}
],
"functions": [
Expand Down

0 comments on commit 59c1ce4

Please sign in to comment.