Bug 1382170 - Only run gSearchResultsPane.initializeCategories() when search is used for the first time, r=jaws
authorTimothy Guan-tin Chien <timdream@gmail.com>
Thu, 27 Jul 2017 12:02:56 +0800
changeset 420697 d10315bb91381dac99cc8ba609d875a04e6543cd
parent 420696 9dc714cc1d064ba31eb8b05d2867dd947e0b260e
child 420698 c8e26d0c9d9ac687d8568fd345c623698ecdd4c4
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1382170, 1374852
milestone56.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 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