Bug 1685222 - Move aboutAddonsExtra observer to MailGlue.jsm, where only one copy of it will be registered. r=ThomasD
authorGeoff Lankow <geoff@darktrojan.net>
Mon, 18 Jan 2021 21:47:19 +0000
changeset 40968 55562799bce858199dd0eaba4434e319c67b1f7e
parent 40967 b7d49fd655a6ee1dc7c457d1b262fac3db224d2f
child 40969 3189ba77bda2b8f101e76e24e4d156bdf1d18577
push id2937
push userthunderbird@calypsoblue.org
push dateMon, 25 Jan 2021 16:03:33 +0000
treeherdercomm-beta@cd42bfaeab51 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersThomasD
bugs1685222
Bug 1685222 - Move aboutAddonsExtra observer to MailGlue.jsm, where only one copy of it will be registered. r=ThomasD Differential Revision: https://phabricator.services.mozilla.com/D101538
mail/base/content/aboutAddonsExtra.js
mail/base/content/specialTabs.js
mail/components/MailGlue.jsm
--- a/mail/base/content/aboutAddonsExtra.js
+++ b/mail/base/content/aboutAddonsExtra.js
@@ -10,62 +10,46 @@ const THUNDERBIRD_THEME_PREVIEWS = new M
     "chrome://mozapps/content/extensions/firefox-compact-light.svg",
   ],
   [
     "thunderbird-compact-dark@mozilla.org",
     "chrome://mozapps/content/extensions/firefox-compact-dark.svg",
   ],
 ]);
 
-/* This file runs in both the outer window, which controls the categories list, search bar, etc.,
- * and the inner window which is the list of add-ons or the detail view. */
 (async function() {
-  if (window.location.href == "about:addons") {
-    // Fix the "Search on addons.mozilla.org" placeholder text in the searchbox.
-    let browser = document.getElementById("html-view-browser");
-    if (!/(interactive|complete)/.test(browser.contentDocument.readyState)) {
-      await new Promise(resolve =>
-        browser.contentWindow.addEventListener("DOMContentLoaded", resolve, {
-          once: true,
-        })
-      );
-    }
+  // Fix the "Search on addons.mozilla.org" placeholder text in the searchbox.
+  let textbox = document.querySelector("search-addons > search-textbox");
+  let placeholder = textbox.getAttribute("placeholder");
+  placeholder = placeholder.replace(
+    "addons.mozilla.org",
+    "addons.thunderbird.net"
+  );
+  textbox.setAttribute("placeholder", placeholder);
 
-    // Wait for custom elements and L10n.
-    await new Promise(resolve =>
-      browser.contentWindow.requestAnimationFrame(resolve)
-    );
-
-    let textbox = browser.contentDocument.querySelector(
-      "search-addons > search-textbox"
-    );
-    let placeholder = textbox.getAttribute("placeholder");
-    placeholder = placeholder.replace(
-      "addons.mozilla.org",
-      "addons.thunderbird.net"
-    );
-    textbox.setAttribute("placeholder", placeholder);
-    return;
-  }
-
+  // Add our stylesheet.
   let contentStylesheet = document.createProcessingInstruction(
     "xml-stylesheet",
     'href="chrome://messenger/content/aboutAddonsExtra.css" type="text/css"'
   );
   document.insertBefore(contentStylesheet, document.documentElement);
 
+  // Override logic for detecting unsigned add-ons.
   window.isCorrectlySigned = function() {
     return true;
   };
+  document.querySelectorAll("addon-card").forEach(card => card.updateMessage());
 
+  // Load our permissions strings.
   delete window.browserBundle;
   window.browserBundle = Services.strings.createBundle(
     "chrome://messenger/locale/addons.properties"
   );
 
+  // Load our theme screenshots.
   let _getScreenshotUrlForAddon = getScreenshotUrlForAddon;
   getScreenshotUrlForAddon = function(addon) {
     if (THUNDERBIRD_THEME_PREVIEWS.has(addon.id)) {
       return THUNDERBIRD_THEME_PREVIEWS.get(addon.id);
     }
     return _getScreenshotUrlForAddon(addon);
   };
 })();
--- a/mail/base/content/specialTabs.js
+++ b/mail/base/content/specialTabs.js
@@ -378,22 +378,19 @@ var contentTabBaseType = {
     "about:*",
   ],
 
   // Code to run if a particular document is loaded in a tab.
   // The array members (functions) are for the respective document URLs
   // as specified in inContentWhitelist.
   inContentOverlays: [
     // about:addons
-    function(aDocument, aTab) {
-      Services.scriptloader.loadSubScript(
-        "chrome://messenger/content/aboutAddonsExtra.js",
-        aDocument.defaultView
-      );
-    },
+    // The add-ons page contains an inner document which is overlaid by
+    // MailGlue, since by the time we get here it's too late.
+    null,
 
     // Let's not mess with about:blank.
     null,
 
     // about:profiles
     function(aDocument, aTab) {
       let win = aDocument.defaultView;
       // Need a timeout to let the script run to create the needed buttons.
@@ -1700,26 +1697,8 @@ var specialTabs = {
     }
 
     // Save this off so we know about it later,
     aTab.browser.mIconURL = aIcon;
     // and display the new icon.
     document.getElementById("tabmail").setTabIcon(aTab, aIcon);
   },
 };
-
-let documentObserver = {
-  observe(document) {
-    if (
-      !document.location ||
-      document.location.href !=
-        "chrome://mozapps/content/extensions/aboutaddons.html"
-    ) {
-      return;
-    }
-
-    Services.scriptloader.loadSubScript(
-      "chrome://messenger/content/aboutAddonsExtra.js",
-      document.defaultView
-    );
-  },
-};
-Services.obs.addObserver(documentObserver, "chrome-document-interactive");
--- a/mail/components/MailGlue.jsm
+++ b/mail/components/MailGlue.jsm
@@ -114,29 +114,31 @@ MailGlue.prototype = {
   // init (called at app startup)
   _init() {
     Services.obs.addObserver(this, "xpcom-shutdown");
     Services.obs.addObserver(this, "final-ui-startup");
     Services.obs.addObserver(this, "intl:app-locales-changed");
     Services.obs.addObserver(this, "mail-startup-done");
     Services.obs.addObserver(this, "handle-xul-text-link");
     Services.obs.addObserver(this, "chrome-document-global-created");
+    Services.obs.addObserver(this, "chrome-document-interactive");
     Services.obs.addObserver(this, "document-element-inserted");
     Services.obs.addObserver(this, "handlersvc-store-initialized");
 
     ActorManagerParent.addJSWindowActors(JSWINDOWACTORS);
   },
 
   // cleanup (called at shutdown)
   _dispose() {
     Services.obs.removeObserver(this, "xpcom-shutdown");
     Services.obs.removeObserver(this, "final-ui-startup");
     Services.obs.removeObserver(this, "intl:app-locales-changed");
     Services.obs.removeObserver(this, "handle-xul-text-link");
     Services.obs.removeObserver(this, "chrome-document-global-created");
+    Services.obs.removeObserver(this, "chrome-document-interactive");
     Services.obs.removeObserver(this, "document-element-inserted");
     Services.obs.removeObserver(this, "handlersvc-store-initialized");
 
     ExtensionSupport.unregisterWindowListener(
       "Thunderbird-internal-BrowserConsole"
     );
 
     if (this._lateTasksIdleObserver) {
@@ -215,16 +217,27 @@ MailGlue.prototype = {
               )
             ) {
               new LightweightThemeConsumer(aSubject.document);
             }
           },
           { once: true }
         );
         break;
+      case "chrome-document-interactive":
+        if (
+          aSubject.location?.href ==
+          "chrome://mozapps/content/extensions/aboutaddons.html"
+        ) {
+          Services.scriptloader.loadSubScript(
+            "chrome://messenger/content/aboutAddonsExtra.js",
+            aSubject.defaultView
+          );
+        }
+        break;
       case "document-element-inserted":
         let doc = aSubject;
         if (
           doc.nodePrincipal.isSystemPrincipal &&
           (doc.contentType == "application/xhtml+xml" ||
             doc.contentType == "text/html") &&
           // People shouldn't be using our built-in custom elements in
           // system-principal about:blank anyway, and trying to support that