Bug 1294733 - Awesomebar search buttons show auto completed text not user input. r=florian
authorDrew Willcoxon <adw@mozilla.com>
Sat, 13 Aug 2016 12:20:42 -0700
changeset 400811 e79a975ce7b7b7ac7cf4c1e9325e7696dbf64d45
parent 400810 23ca0cdcf3b07ec6433cc6b1785404ed89cf4c19
child 400812 b20c524ca0c476169855e301ed32474a28a3c630
push id26289
push userbmo:npancholi@mozilla.com
push dateMon, 15 Aug 2016 22:10: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
@@ -429,22 +429,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) {
@@ -465,16 +460,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);