Bug 1550131 - Remove about:logins master password login notifications when the user logs in. r=jaws
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Tue, 21 May 2019 13:15:53 +0000
changeset 474735 1e40a8e7a40409f7098c442b9023be5703d106cd
parent 474734 9dbb7bb20ca334f6eaf8925a48df005006c745eb
child 474736 4ff5f1d8f9c43dcd1d127554729f4c2c4efd6d9f
push id36046
push useraiakab@mozilla.com
push dateTue, 21 May 2019 21:45:52 +0000
treeherdermozilla-central@257f2c96cef5 [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 - Remove about:logins master password login notifications when the user logs in. r=jaws Depends on D31699 Differential Revision: https://phabricator.services.mozilla.com/D31700
browser/components/aboutlogins/AboutLoginsParent.jsm
--- a/browser/components/aboutlogins/AboutLoginsParent.jsm
+++ b/browser/components/aboutlogins/AboutLoginsParent.jsm
@@ -70,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-login");
           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;
@@ -103,21 +104,28 @@ 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-login");
       Services.obs.removeObserver(this, "passwordmgr-crypto-loginCanceled");
       Services.obs.removeObserver(this, "passwordmgr-storage-changed");
       return;
     }
 
+    if (topic == "passwordmgr-crypto-login") {
+      this.removeMasterPasswordLoginNotifications();
+      this.messageSubscribers("AboutLogins:AllLogins", this.getAllLogins());
+      return;
+    }
+
     if (topic == "passwordmgr-crypto-loginCanceled") {
       this.showMasterPasswordLoginNotifications();
       return;
     }
 
     switch (type) {
       case "addLogin": {
         const login = convertSubjectToLogin(subject);
@@ -174,16 +182,29 @@ var AboutLoginsParent = {
         callback() { browser.reload(); },
       }];
 
       notification = notificationBox.appendNotification(messageString, MASTER_PASSWORD_NOTIFICATION_ID,
                                                         iconURL, priority, buttons);
     }
   },
 
+  removeMasterPasswordLoginNotifications() {
+    for (let subscriber of this._subscriberIterator()) {
+      let {gBrowser} = subscriber.ownerGlobal;
+      let browser = subscriber;
+      let notificationBox = gBrowser.getNotificationBox(browser);
+      let notification = notificationBox.getNotificationWithValue(MASTER_PASSWORD_NOTIFICATION_ID);
+      if (!notification) {
+        continue;
+      }
+      notificationBox.removeNotification(notification);
+    }
+  },
+
   * _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;