Bug 1301093 - Part 2: sanity check that delayed Enter applies to the expected search string. r=adw
MozReview-Commit-ID: KiZJeztffR8
--- 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>