Bug 1549814 - Include a title with the login object that removes http(s) or www prefix. r?MattN draft
authorpulselistener
Sat, 18 May 2019 06:44:26 +0000
changeset 2008539 a4376acc05b7c94b226d14671f04b681b44ddb96
parent 2008538 e299c2edd5ed5295e9e5e66073f7d09ac131f9b7
child 2008540 af5c7a0c2cfa21e1b09a6eea005658e508357bc7
push id363921
push userreviewbot
push dateSat, 18 May 2019 06:44:53 +0000
treeherdertry@feb98ece6f65 [default view] [failures only]
reviewersMattN
bugs1549814
milestone68.0a1
Bug 1549814 - Include a title with the login object that removes http(s) or www prefix. r?MattN Differential Revision: https://phabricator.services.mozilla.com/D31711 Differential Diff: PHID-DIFF-l2bn72r3q7v7qrsmvtjo
browser/components/aboutlogins/AboutLoginsParent.jsm
browser/components/aboutlogins/content/components/login-item.js
--- a/browser/components/aboutlogins/AboutLoginsParent.jsm
+++ b/browser/components/aboutlogins/AboutLoginsParent.jsm
@@ -31,22 +31,36 @@ const EXPECTED_ABOUTLOGINS_REMOTE_TYPE =
   PRIVILEGED_PROCESS_ENABLED ? E10SUtils.PRIVILEGED_REMOTE_TYPE
                              : E10SUtils.DEFAULT_REMOTE_TYPE;
 
 const isValidLogin = login => {
   return !(login.hostname || "").startsWith("chrome://");
 };
 
 const convertSubjectToLogin = subject => {
-    subject.QueryInterface(Ci.nsILoginMetaInfo).QueryInterface(Ci.nsILoginInfo);
-    const login = LoginHelper.loginToVanillaObject(subject);
-    if (!isValidLogin(login)) {
-      return null;
-    }
-    return login;
+  subject.QueryInterface(Ci.nsILoginMetaInfo).QueryInterface(Ci.nsILoginInfo);
+  const login = LoginHelper.loginToVanillaObject(subject);
+  if (!isValidLogin(login)) {
+    return null;
+  }
+  return augmentVanillaLoginObject(login);
+};
+
+const augmentVanillaLoginObject = login => {
+  let title;
+  try {
+    title = (new URL(login.hostname)).host;
+  } catch (ex) {
+    title = login.hostname;
+  }
+  title = title.replace(/^http(s)?:\/\//, "").
+                replace(/^www\d*\./, "");
+  return Object.assign({}, login, {
+    title,
+  });
 };
 
 var AboutLoginsParent = {
   _subscribers: new WeakSet(),
 
   // Listeners are added in BrowserGlue.jsm
   receiveMessage(message) {
     // Only respond to messages sent from about:logins.
@@ -155,11 +169,12 @@ var AboutLoginsParent = {
       } catch (ex) {}
     }
   },
 
   getAllLogins() {
     return Services.logins
                    .getAllLogins()
                    .filter(isValidLogin)
-                   .map(LoginHelper.loginToVanillaObject);
+                   .map(LoginHelper.loginToVanillaObject)
+                   .map(augmentVanillaLoginObject);
   },
 };
--- a/browser/components/aboutlogins/content/components/login-item.js
+++ b/browser/components/aboutlogins/content/components/login-item.js
@@ -105,18 +105,17 @@ class LoginItem extends ReflectedFluentE
 
   render() {
     let l10nArgs = {
       timeCreated: this._login.timeCreated || "",
       timeChanged: this._login.timePasswordChanged || "",
       timeUsed: this._login.timeLastUsed || "",
     };
     document.l10n.setAttributes(this, "login-item", l10nArgs);
-    let hostnameNoScheme = this._login.hostname && new URL(this._login.hostname).hostname;
-    this.shadowRoot.querySelector(".title").textContent = hostnameNoScheme || "";
+    this.shadowRoot.querySelector(".title").textContent = this._login.title || "";
     this.shadowRoot.querySelector(".hostname").textContent = this._login.hostname || "";
     this.shadowRoot.querySelector("modal-input[name='username']").setAttribute("value", this._login.username || "");
     this.shadowRoot.querySelector("modal-input[name='password']").setAttribute("value", this._login.password || "");
   }
 
   handleEvent(event) {
     switch (event.type) {
       case "AboutLoginsLoginSelected": {