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:49:16 +0000
changeset 2008572 5d36f520c456447f354447c462c5c6364d85c04d
parent 2008571 3ebd89cfd9b0912b860c3e94adaa3c595d5f22cd
child 2008573 7b25b65910f86ee3f7534cd2aca748c90fcb9fbf
push id363923
push userreviewbot
push dateSat, 18 May 2019 06:49:52 +0000
treeherdertry@6eb4ec2cb49f [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": {