Bug 1382170 - Only run gSearchResultsPane.initializeCategories() when search is used for the first time, r=jaws draft
authorTimothy Guan-tin Chien <timdream@gmail.com>
Thu, 27 Jul 2017 12:02:56 +0800
changeset 618271 653f068cec6d7a42d406ea0109358d0c48e195bf
parent 618186 6d1b50a370b4adffbb1ee73b9f51707c90d6a2b1
child 640017 18eb5e5086ac0ae9a3122786b7e0aff882638045
push id71277
push usertimdream@gmail.com
push dateMon, 31 Jul 2017 05:23:05 +0000
reviewersjaws
bugs1382170, 1374852
milestone56.0a1
Bug 1382170 - Only run gSearchResultsPane.initializeCategories() when search is used for the first time, r=jaws This shuffled what bug 1374852 did a little bit; instead of initialize all panes when the page loads, the call will happen inside an idle callback. An the event listener is added to ensure that even if idle callback doesn't run soon enough, the function is run already when the user starts search. MozReview-Commit-ID: LU4Nb8lql36
browser/components/preferences/in-content-new/findInPage.js
--- a/browser/components/preferences/in-content-new/findInPage.js
+++ b/browser/components/preferences/in-content-new/findInPage.js
@@ -14,31 +14,32 @@ var gSearchResultsPane = {
     if (this.inited) {
       return;
     }
     this.inited = true;
     this.searchInput = document.getElementById("searchInput");
     this.searchInput.hidden = !Services.prefs.getBoolPref("browser.preferences.search");
     if (!this.searchInput.hidden) {
       this.searchInput.addEventListener("command", this);
-      window.addEventListener("load", () => {
+      window.addEventListener("DOMContentLoaded", () => {
         this.searchInput.focus();
-        this.initializeCategories();
       });
+      // Initialize other panes in an idle callback.
+      window.requestIdleCallback(() => this.initializeCategories());
     }
     let strings = this.strings;
     this.searchInput.placeholder = AppConstants.platform == "win" ?
       strings.getString("searchInput.labelWin") :
       strings.getString("searchInput.labelUnix");
   },
 
   handleEvent(event) {
-    if (event.type === "command") {
-      this.searchFunction(event);
-    }
+    // Ensure categories are initialized if idle callback didn't run sooo enough.
+    this.initializeCategories();
+    this.searchFunction(event);
   },
 
   /**
    * Check that the passed string matches the filter arguments.
    *
    * @param String str
    *    to search for filter words in.
    * @param String filter