Bug 1550131 - Show a notification when master password login is cancelled while about:logins is open. r=jaws
☠☠ backed out by d650f8a160f8 ☠ ☠
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Mon, 20 May 2019 02:56:05 +0000
changeset 474590 32ff6a0b84360340e1e2fff213a8e0065586272a
parent 474589 b562886d574d225ceeae632b98285110fdc80a64
child 474591 97eabc06294643214ff8d88a432e39c9e2242391
push id36042
push userdvarga@mozilla.com
push dateTue, 21 May 2019 04:19:40 +0000
treeherdermozilla-central@ca560ff55451 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1550131
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1550131 - Show a notification when master password login is cancelled while about:logins is open. r=jaws Depends on D31698 Differential Revision: https://phabricator.services.mozilla.com/D31699
browser/components/aboutlogins/AboutLoginsParent.jsm
--- a/browser/components/aboutlogins/AboutLoginsParent.jsm
+++ b/browser/components/aboutlogins/AboutLoginsParent.jsm
@@ -14,16 +14,17 @@ ChromeUtils.defineModuleGetter(this, "Lo
 ChromeUtils.defineModuleGetter(this, "Services",
                                "resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyGetter(this, "log", () => {
   return LoginHelper.createLogger("AboutLoginsParent");
 });
 
 const ABOUT_LOGINS_ORIGIN = "about:logins";
+const MASTER_PASSWORD_NOTIFICATION_ID = "master-password-login-required";
 
 const PRIVILEGED_PROCESS_PREF =
   "browser.tabs.remote.separatePrivilegedContentProcess";
 const PRIVILEGED_PROCESS_ENABLED =
   Services.prefs.getBoolPref(PRIVILEGED_PROCESS_PREF, false);
 
 // When the privileged content process is enabled, we expect about:logins
 // to load in it. Otherwise, it's in a normal web content process.
@@ -69,16 +70,17 @@ var AboutLoginsParent = {
           return;
         }
 
         message.target.ownerGlobal.openWebLinkIn(logins[0].hostname, "tab", {relatedToCurrent: true});
         break;
       }
       case "AboutLogins:Subscribe": {
         if (!ChromeUtils.nondeterministicGetWeakSetKeys(this._subscribers).length) {
+          Services.obs.addObserver(this, "passwordmgr-crypto-loginCanceled");
           Services.obs.addObserver(this, "passwordmgr-storage-changed");
         }
         this._subscribers.add(message.target);
 
         let messageManager = message.target.messageManager;
         messageManager.sendAsyncMessage("AboutLogins:AllLogins", this.getAllLogins());
         break;
       }
@@ -101,20 +103,26 @@ var AboutLoginsParent = {
         Services.logins.modifyLogin(logins[0], modifiedLogin);
         break;
       }
     }
   },
 
   observe(subject, topic, type) {
     if (!ChromeUtils.nondeterministicGetWeakSetKeys(this._subscribers).length) {
+      Services.obs.removeObserver(this, "passwordmgr-crypto-loginCanceled");
       Services.obs.removeObserver(this, "passwordmgr-storage-changed");
       return;
     }
 
+    if (topic == "passwordmgr-crypto-loginCanceled") {
+      this.showMasterPasswordLoginNotifications();
+      return;
+    }
+
     switch (type) {
       case "addLogin": {
         const login = convertSubjectToLogin(subject);
         if (!login) {
           return;
         }
         this.messageSubscribers("AboutLogins:LoginAdded", login);
         break;
@@ -136,16 +144,46 @@ var AboutLoginsParent = {
         this.messageSubscribers("AboutLogins:LoginRemoved", login);
       }
       default: {
         break;
       }
     }
   },
 
+  showMasterPasswordLoginNotifications() {
+    let messageString = "You must enter your Master Password to view saved logins"; // TODO
+    for (let subscriber of this._subscriberIterator()) {
+      // If there's already an existing notification bar, don't do anything.
+      let {gBrowser} = subscriber.ownerGlobal;
+      let browser = subscriber;
+      let notificationBox = gBrowser.getNotificationBox(browser);
+      let notification = notificationBox.getNotificationWithValue(MASTER_PASSWORD_NOTIFICATION_ID);
+      if (notification) {
+        continue;
+      }
+
+      // Configure the notification bar
+      let priority = notificationBox.PRIORITY_WARNING_MEDIUM;
+      let iconURL = "chrome://browser/skin/login.svg";
+      let reloadLabel = "Log in"; // TODO
+      let reloadKey   = "L"; // TODO
+
+      let buttons = [{
+        label: reloadLabel,
+        accessKey: reloadKey,
+        popup: null,
+        callback() { browser.reload(); },
+      }];
+
+      notification = notificationBox.appendNotification(messageString, MASTER_PASSWORD_NOTIFICATION_ID,
+                                                        iconURL, priority, buttons);
+    }
+  },
+
   * _subscriberIterator() {
     let subscribers = ChromeUtils.nondeterministicGetWeakSetKeys(this._subscribers);
     for (let subscriber of subscribers) {
       if (subscriber.remoteType != EXPECTED_ABOUTLOGINS_REMOTE_TYPE ||
           !subscriber.contentPrincipal ||
           subscriber.contentPrincipal.originNoSuffix != ABOUT_LOGINS_ORIGIN) {
         this._subscribers.delete(subscriber);
         continue;