Bug 1522508 - Notify Omnibox WebExtensions when the user cancels a search via blur. r=dao
authorMark Banner <standard8@mozilla.com>
Thu, 28 Feb 2019 09:33:08 +0000
changeset 519589 c944e14b8944735a857b9c9f8a3e1213f3383b56
parent 519588 3049be83e02d6a79118eb045831e3502196245f9
child 519590 ff76466ee236c1d23bed762eb5de658db038147e
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1522508
milestone67.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 1522508 - Notify Omnibox WebExtensions when the user cancels a search via blur. r=dao Differential Revision: https://phabricator.services.mozilla.com/D21004
browser/components/urlbar/UrlbarController.jsm
browser/components/urlbar/UrlbarInput.jsm
browser/components/urlbar/UrlbarUtils.jsm
browser/components/urlbar/UrlbarView.jsm
--- a/browser/components/urlbar/UrlbarController.jsm
+++ b/browser/components/urlbar/UrlbarController.jsm
@@ -8,16 +8,17 @@ var EXPORTED_SYMBOLS = [
   "UrlbarController",
 ];
 
 const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 XPCOMUtils.defineLazyModuleGetters(this, {
   AppConstants: "resource://gre/modules/AppConstants.jsm",
   BrowserUsageTelemetry: "resource:///modules/BrowserUsageTelemetry.jsm",
+  ExtensionSearchHandler: "resource://gre/modules/ExtensionSearchHandler.jsm",
   PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
   UrlbarPrefs: "resource:///modules/UrlbarPrefs.jsm",
   UrlbarProvidersManager: "resource:///modules/UrlbarProvidersManager.jsm",
   UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
   URLBAR_SELECTED_RESULT_TYPES: "resource:///modules/BrowserUsageTelemetry.jsm",
 });
 
 const TELEMETRY_1ST_RESULT = "PLACES_AUTOCOMPLETE_1ST_RESULT_TIME_MS";
@@ -103,29 +104,37 @@ class UrlbarController {
     this._notify("onQueryStarted", queryContext);
     await this.manager.startQuery(queryContext, this);
     this._notify("onQueryFinished", queryContext);
     return queryContext;
   }
 
   /**
    * Cancels an in-progress query. Note, queries may continue running if they
-   * can't be canceled.
+   * can't be cancelled.
+   *
+   * @param {UrlbarUtils.CANCEL_REASON} [reason]
+   *   The reason the query was cancelled.
    */
-  cancelQuery() {
+  cancelQuery(reason) {
     if (!this._lastQueryContext) {
       return;
     }
 
     TelemetryStopwatch.cancel(TELEMETRY_1ST_RESULT, this._lastQueryContext);
     TelemetryStopwatch.cancel(TELEMETRY_6_FIRST_RESULTS, this._lastQueryContext);
 
     this.manager.cancelQuery(this._lastQueryContext);
     this._notify("onQueryCancelled", this._lastQueryContext);
     delete this._lastQueryContext;
+
+    if (reason == UrlbarUtils.CANCEL_REASON.BLUR &&
+        ExtensionSearchHandler.hasActiveInputSession()) {
+      ExtensionSearchHandler.handleInputCancelled();
+    }
   }
 
   /**
    * Receives results from a query.
    *
    * @param {UrlbarQueryContext} queryContext The query details.
    */
   receiveResults(queryContext) {
--- a/browser/components/urlbar/UrlbarInput.jsm
+++ b/browser/components/urlbar/UrlbarInput.jsm
@@ -148,17 +148,16 @@ class UrlbarInput {
   /**
    * Applies styling to the text in the urlbar input, depending on the text.
    */
   formatValue() {
     this.valueFormatter.update();
   }
 
   closePopup() {
-    this.controller.cancelQuery();
     this.view.close();
   }
 
   focus() {
     this.inputField.focus();
   }
 
   blur() {
@@ -948,17 +947,17 @@ class UrlbarInput {
 
     insertLocation.insertAdjacentElement("afterend", pasteAndGo);
   }
 
   // Event handlers below.
 
   _on_blur(event) {
     this.formatValue();
-    this.closePopup();
+    this.view.close(UrlbarUtils.CANCEL_REASON.BLUR);
   }
 
   _on_focus(event) {
     this._updateUrlTooltip();
 
     this.formatValue();
   }
 
--- a/browser/components/urlbar/UrlbarUtils.jsm
+++ b/browser/components/urlbar/UrlbarUtils.jsm
@@ -109,16 +109,22 @@ var UrlbarUtils = {
 
   // IME composition states.
   COMPOSITION: {
     NONE: 1,
     COMPOSING: 2,
     COMMIT: 3,
   },
 
+  // This defines possible reasons for canceling a query.
+  CANCEL_REASON: {
+    // 1 is intentionally left in case we want a none/undefined/other later.
+    BLUR: 2,
+  },
+
   /**
    * Adds a url to history as long as it isn't in a private browsing window,
    * and it is valid.
    *
    * @param {string} url The url to add to history.
    * @param {nsIDomWindow} window The window from where the url is being added.
    */
   addToUrlbarHistory(url, window) {
--- a/browser/components/urlbar/UrlbarView.jsm
+++ b/browser/components/urlbar/UrlbarView.jsm
@@ -167,19 +167,24 @@ class UrlbarView {
         break;
       }
       row = next;
     }
     this._selectItem(row);
   }
 
   /**
-   * Closes the autocomplete results popup.
+   * Closes the autocomplete popup, cancelling the query if necessary.
+   *
+   * @param {UrlbarUtils.CANCEL_REASON} [cancelReason]
+   *   Indicates if this close is being triggered as a result of a user action
+   *   which would cancel a query, e.g. on blur.
    */
-  close() {
+  close(cancelReason) {
+    this.controller.cancelQuery(cancelReason);
     this.panel.hidePopup();
   }
 
   // UrlbarController listener methods.
   onQueryStarted(queryContext) {
     this._rows.style.minHeight = this._getBoundsWithoutFlushing(this._rows).height + "px";
   }