Bug 1550131 - Show a notification when master password login is cancelled while about:logins is open. r=jaws
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Tue, 21 May 2019 13:15:46 +0000
changeset 474734 9dbb7bb20ca334f6eaf8925a48df005006c745eb
parent 474733 d84f90dcd58473413b5600543c6781aff060118c
child 474735 1e40a8e7a40409f7098c442b9023be5703d106cd
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 - 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;