Bug 1559625 - Let SearchService init when called via -search. r=mikedeboer a=RyanVM
authorDale Harvey <dale@arandomurl.com>
Wed, 10 Jul 2019 14:36:15 +0000
changeset 544916 8510b616a4b457944d7cff86496c85f41944140a
parent 544915 57aa25b9aa2bb90e9c1883d00f77ce79190bae63
child 544917 fc7bf47dc68ad1ebb2303139ce170bb2926ac014
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer, RyanVM
bugs1559625
milestone69.0
Bug 1559625 - Let SearchService init when called via -search. r=mikedeboer a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D36176
browser/components/BrowserContentHandler.jsm
--- a/browser/components/BrowserContentHandler.jsm
+++ b/browser/components/BrowserContentHandler.jsm
@@ -223,16 +223,19 @@ function getPostUpdateOverridePage(defau
  *        loaded in a tab. postData will be ignored in this case.
  *        This can be a single url to load in the new window, provided as a string.
  *        postData will be used in this case if provided.
  * @param postData (optional)
  *        An nsIInputStream object to use as POST data when loading the provided
  *        url, or null.
  * @param forcePrivate (optional)
  *        Boolean. If set to true, the new window will be a private browsing one.
+ *
+ * @returns {ChromeWindow}
+ *          Returns the top level window opened.
  */
 function openBrowserWindow(
   cmdLine,
   triggeringPrincipal,
   urlOrUrlList,
   postData = null,
   forcePrivate = false
 ) {
@@ -312,17 +315,17 @@ function openBrowserWindow(
         win.docShell.QueryInterface(
           Ci.nsILoadContext
         ).usePrivateBrowsing = true;
       }
 
       win.location = chromeURL;
       win.arguments = args; // <-- needs to be a plain JS array here.
 
-      return;
+      return win;
     }
   }
 
   // We can't provide arguments to openWindow as a JS array.
   if (!urlOrUrlList) {
     // If we have a single string guaranteed to not contain '|' we can simply
     // wrap it in an nsISupportsString object.
     let [url] = args;
@@ -347,39 +350,41 @@ function openBrowserWindow(
   }
 
   let features =
     "chrome,dialog=no,all" + gBrowserContentHandler.getFeatures(cmdLine);
   if (forcePrivate) {
     features += ",private";
   }
 
-  Services.ww.openWindow(null, chromeURL, "_blank", features, args);
+  return Services.ww.openWindow(null, chromeURL, "_blank", features, args);
 }
 
 function openPreferences(cmdLine, extraArgs) {
   openBrowserWindow(cmdLine, gSystemPrincipal, "about:preferences");
 }
 
-function doSearch(searchTerm, cmdLine) {
-  var engine = Services.search.defaultEngine;
+async function doSearch(searchTerm, cmdLine) {
+  // XXXbsmedberg: use handURIToExistingBrowser to obey tabbed-browsing
+  // preferences, but need nsIBrowserDOMWindow extensions
+  // Open the window immediately as BrowserContentHandler needs to
+  // be handled synchronously. Then load the search URI when the
+  // SearchService has loaded.
+  let win = openBrowserWindow(cmdLine, gSystemPrincipal, "about:blank");
+  var engine = await Services.search.getDefault();
   var countId = (engine.identifier || "other-" + engine.name) + ".system";
   var count = Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS");
   count.add(countId);
 
   var submission = engine.getSubmission(searchTerm, null, "system");
 
-  // XXXbsmedberg: use handURIToExistingBrowser to obey tabbed-browsing
-  // preferences, but need nsIBrowserDOMWindow extensions
-  openBrowserWindow(
-    cmdLine,
-    gSystemPrincipal,
-    submission.uri.spec,
-    submission.postData
-  );
+  win.gBrowser.selectedBrowser.loadURI(submission.uri.spec, {
+    triggeringPrincipal: gSystemPrincipal,
+    postData: submission.postData,
+  });
 }
 
 function nsBrowserContentHandler() {
   if (!gBrowserContentHandler) {
     gBrowserContentHandler = this;
   }
   return gBrowserContentHandler;
 }