Bug 1294733 - Awesomebar search buttons show auto completed text not user input. r?florian draft
authorDrew Willcoxon <adw@mozilla.com>
Sat, 13 Aug 2016 12:20:42 -0700
changeset 400463 80f8829913ac94a3337078402cd2b2e54679d5bf
parent 399976 6f2ba7787816fd01f77c30e3bdb68400db74bf0c
child 528206 4476ff706673ee24fda594ab1c59f113872e6c73
push id26148
push userdwillcoxon@mozilla.com
push dateSat, 13 Aug 2016 19:21:02 +0000
reviewersflorian
bugs1294733
milestone51.0a1
Bug 1294733 - Awesomebar search buttons show auto completed text not user input. r?florian MozReview-Commit-ID: BmxFd7fgdA6
browser/base/content/urlbarBindings.xml
browser/components/search/content/search.xml
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -430,22 +430,17 @@ file, You can obtain one at http://mozil
                           matchLastLocationChange, mayInheritPrincipal);
             return;
           }
 
           // If there's a selected one-off button and the input value is a
           // search query (or "keyword" in URI-fixup terminology), then load a
           // search using the one-off's engine.
           if (selectedOneOff && selectedOneOff.engine) {
-            // `url` (which is this.value) may be an autofilled string.  Search
-            // only with the portion that the user typed, if any, by preferring
-            // the autocomplete controller's searchString.
-            let value = this._searchStringOnHandleEnter ||
-                        this.mController.searchString ||
-                        url;
+            let value = this.oneOffSearchQuery;
             let fixup;
             try {
               fixup = Services.uriFixup.getFixupURIInfo(
                 value,
                 Services.uriFixup.FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP
               );
             } catch (ex) {}
             if (fixup && fixup.keywordProviderName) {
@@ -466,16 +461,27 @@ file, You can obtain one at http://mozil
                 gBrowser.selectedBrowser.lastLocationChange;
               this._loadURL(url, postData, where, openUILinkParams,
                             matchLastLocationChange, mayInheritPrincipal);
             }
           });
         ]]></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 ||
+                 this.mController.searchString ||
+                 this.textValue;
+        ]]></getter>
+      </property>
+
       <method name="_loadURL">
         <parameter name="url"/>
         <parameter name="postData"/>
         <parameter name="openUILinkWhere"/>
         <parameter name="openUILinkParams"/>
         <parameter name="matchLastLocationChange"/>
         <parameter name="mayInheritPrincipal"/>
         <body><![CDATA[
--- a/browser/components/search/content/search.xml
+++ b/browser/components/search/content/search.xml
@@ -1272,22 +1272,21 @@
 
       <!-- This handles events outside the one-off buttons, like on the popup
            and textbox. -->
       <method name="handleEvent">
         <parameter name="event"/>
         <body><![CDATA[
           switch (event.type) {
             case "input":
-              // The urlbar's value property can be a moz-action URI, but we
-              // want the value that the user sees, which is textValue.  So see
-              // if the textbox has a textValue property, and use it if so.
-              this.query = typeof(event.target.textValue) == "string" ?
-                           event.target.textValue :
-                           event.target.value;
+              // Allow the consumer's input to override its value property with
+              // a oneOffSearchQuery property.  That way if the value is not
+              // actually what the user typed (e.g., it's autofilled, or it's a
+              // mozaction URI), the consumer has some way of providing it.
+              this.query = event.target.oneOffSearchQuery || event.target.value;
               break;
             case "popupshowing":
               this._rebuild();
               break;
             case "popuphidden":
               Services.tm.mainThread.dispatch(() => {
                 this.selectedButton = null;
               }, Ci.nsIThread.DISPATCH_NORMAL);