Bug 1301093 - Part 2: sanity check that delayed Enter applies to the expected search string. r=adw draft
authorMarco Bonardo <mbonardo@mozilla.com>
Wed, 07 Sep 2016 18:22:23 +0200
changeset 413739 b1175292d466c9d00f04ff57bfbe0522c2f7e062
parent 413738 39144a190f27257b190178308b26fa3f7bea15a2
child 413740 7b544bfe695cd6c3a19326c71cf603b265213963
push id29482
push usermak77@bonardo.net
push dateWed, 14 Sep 2016 18:58:13 +0000
reviewersadw
bugs1301093
milestone51.0a1
Bug 1301093 - Part 2: sanity check that delayed Enter applies to the expected search string. r=adw MozReview-Commit-ID: KiZJeztffR8
browser/base/content/urlbarBindings.xml
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -121,17 +121,23 @@ file, You can obtain one at http://mozil
         this.inputField.removeEventListener("mousemove", this, false);
         this.inputField.removeEventListener("mouseout", this, false);
         this.inputField.removeEventListener("overflow", this, false);
         this.inputField.removeEventListener("underflow", this, false);
       ]]></destructor>
 
       <field name="_value">""</field>
       <field name="gotResultForCurrentQuery">false</field>
-      <field name="handleEnterWhenGotResult">false</field>
+
+      <!--
+        This is set around HandleHenter so it can be used in handleCommand.
+        It is also used to track whether we must handle a delayed handleEnter,
+        by checking if it has been cleared.
+      -->
+      <field name="searchStringOnHandleEnter">""</field>
 
       <!--
         For performance reasons we want to limit the size of the text runs we
         build and show to the user.
       -->
       <field name="textRunsMaxLen">255</field>
 
       <!--
@@ -464,18 +470,18 @@ file, You can obtain one at http://mozil
           });
         ]]></body>
       </method>
 
       <property name="oneOffSearchQuery">
         <getter><![CDATA[
           // this.textValue may be an autofilled string.  Search only with the
           // portion that the user typed, if any, by preferring the autocomplete
-          // controller's searchString (including _searchStringOnHandleEnter).
-          return this._searchStringOnHandleEnter ||
+          // controller's searchString (including searchStringOnHandleEnter).
+          return this.searchStringOnHandleEnter ||
                  this.mController.searchString ||
                  this.textValue;
         ]]></getter>
       </property>
 
       <method name="_loadURL">
         <parameter name="url"/>
         <parameter name="postData"/>
@@ -1028,28 +1034,29 @@ file, You can obtain one at http://mozil
           // result selected.
           // If anything other than the default (first) result is selected, then
           // it must have been manually selected by the human. We let this
           // explicit choice be used, even if it may be related to a previous
           // input.
           // However, if the default result is automatically selected, we
           // ensure that it corresponds to the current input.
 
+          // Store the current search string so it can be used in
+          // handleCommand, which will be called as a result of
+          // mController.handleEnter().
+          // Note this is also used to detect if we should perform a delayed
+          // handleEnter, in such a case it won't have been cleared.
+          this.searchStringOnHandleEnter = this.mController.searchString;
+
           if (this.popup.selectedIndex != 0 || this.gotResultForCurrentQuery) {
-            // Store the current search string so it can be used in
-            // handleCommand, which will be called as a result of
-            // mController.handleEnter().  handleEnter will reset it.
-            this._searchStringOnHandleEnter = this.mController.searchString;
             let rv = this.mController.handleEnter(false, event);
-            delete this._searchStringOnHandleEnter;
+            this.searchStringOnHandleEnter = "";
             return rv;
           }
 
-          this.handleEnterWhenGotResult = true;
-
           return true;
         ]]></body>
       </method>
 
       <method name="handleDelete">
         <body><![CDATA[
           // If the heuristic result is selected, then the autocomplete
           // controller's handleDelete implementation will remove it, which is
@@ -1764,19 +1771,27 @@ file, You can obtain one at http://mozil
               this.richlistbox.suppressMenuItemEvent = true;
 
               this.selectedIndex = 0;
               this.richlistbox.suppressMenuItemEvent = false;
               this._ignoreNextSelect = false;
             }
 
             this.input.gotResultForCurrentQuery = true;
-            if (this.input.handleEnterWhenGotResult) {
-              this.input.handleEnterWhenGotResult = false;
-              this.input.mController.handleEnter(false);
+
+            // Check if we should perform a delayed handleEnter.
+            if (this.input.searchStringOnHandleEnter) {
+              try {
+                // Safety check: handle only if the search string didn't change.
+                if (this.input.mController.searchString == this.input.searchStringOnHandleEnter) {
+                  this.input.mController.handleEnter(false);
+                }
+              } finally {
+                this.input.searchStringOnHandleEnter = "";
+              }
             }
           ]]>
         </body>
       </method>
 
     </implementation>
     <handlers>