Bug 1075069 - Backed out search term highlighting in the location bar (bug 1047469). r=ttaubert
authorDão Gottwald <dao@mozilla.com>
Wed, 01 Oct 2014 20:33:56 +0200
changeset 208184 fdcb83cd213946eeaf6cd7e41f402f30d62b0283
parent 208183 79211bb59624727f46a0d7febfe25b0b89c2c109
child 208185 f771fd927304f5ee9683f7a24173e4be297735b7
child 208431 c1aee3301e77b36007ef0be54c6e992b0e472270
push id27579
push userkwierso@gmail.com
push dateWed, 01 Oct 2014 23:02:13 +0000
treeherderautoland@f771fd927304 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersttaubert
bugs1075069, 1047469
milestone35.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 1075069 - Backed out search term highlighting in the location bar (bug 1047469). r=ttaubert
browser/base/content/test/general/browser_urlHighlight.js
browser/base/content/urlbarBindings.xml
--- a/browser/base/content/test/general/browser_urlHighlight.js
+++ b/browser/base/content/test/general/browser_urlHighlight.js
@@ -14,21 +14,17 @@ function testVal(aExpected) {
     let pos = value.indexOf(range);
     result += value.substring(0, pos) + "<" + range + ">";
     value = value.substring(pos + range.length);
   }
   result += value;
   is(result, aExpected);
 }
 
-add_task(function* () {
-  return new Promise(resolve => Services.search.init(resolve));
-});
-
-add_task(function* () {
+function test() {
   const prefname = "browser.urlbar.formatting.enabled";
 
   registerCleanupFunction(function () {
     Services.prefs.clearUserPref(prefname);
     URLBarSetURI();
   });
 
   Services.prefs.setBoolPref(prefname, true);
@@ -108,9 +104,9 @@ add_task(function* () {
   testVal("foo9://mozilla.org/");
   testVal("foo+://mozilla.org/");
   testVal("foo.://mozilla.org/");
   testVal("foo-://mozilla.org/");
 
   Services.prefs.setBoolPref(prefname, false);
 
   testVal("https://mozilla.org");
-});
+}
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -180,35 +180,21 @@
         <body><![CDATA[
           // This method must not modify the given URL such that calling
           // nsIURIFixup::createFixupURI with the result will produce a different URI.
           return this._mayTrimURLs ? trimURL(aURL) : aURL;
         ]]></body>
       </method>
 
       <field name="_formattingEnabled">true</field>
-      <field name="_searchServiceInitialized">false</field>
       <method name="formatValue">
         <body><![CDATA[
           if (!this._formattingEnabled || this.focused)
             return;
 
-          // Initialize the search service asynchronously if that hasn't
-          // happened yet. We will need it to highlight search terms later.
-          if (!this._searchServiceInitialized) {
-            Services.search.init(() => {
-              if (this.formatValue) {
-                this._searchServiceInitialized = true;
-                this.formatValue();
-              }
-            });
-
-            return;
-          }
-
           let controller = this.editor.selectionController;
           let selection = controller.getSelection(controller.SELECTION_URLSECONDARY);
           selection.removeAllRanges();
 
           let textNode = this.editor.rootElement.firstChild;
           let value = textNode.textContent;
 
           let protocol = value.match(/^[a-z\d.+\-]+:(?=[^\d])/);
@@ -233,39 +219,30 @@
                 baseDomain = IDNService.convertACEtoUTF8(baseDomain);
               }
             } catch (e) {}
           }
           if (baseDomain != domain) {
             subDomain = domain.slice(0, -baseDomain.length);
           }
 
-          function addSelectionRange(start, end) {
+          let rangeLength = preDomain.length + subDomain.length;
+          if (rangeLength) {
             let range = document.createRange();
-            range.setStart(textNode, start);
-            range.setEnd(textNode, end);
+            range.setStart(textNode, 0);
+            range.setEnd(textNode, rangeLength);
             selection.addRange(range);
           }
 
-          let rangeLength = preDomain.length + subDomain.length;
-          if (rangeLength) {
-            addSelectionRange(0, rangeLength);
-          }
-
-          let result = Services.search.parseSubmissionURL(value);
           let startRest = preDomain.length + domain.length;
-
-          // Format search terms in the URL, if any.
-          if (result.termsOffset > -1 && result.termsLength) {
-            addSelectionRange(startRest, result.termsOffset);
-            startRest = result.termsOffset + result.termsLength;
-          }
-
           if (startRest < value.length) {
-            addSelectionRange(startRest, value.length);
+            let range = document.createRange();
+            range.setStart(textNode, startRest);
+            range.setEnd(textNode, value.length);
+            selection.addRange(range);
           }
         ]]></body>
       </method>
 
       <method name="_clearFormatting">
         <body><![CDATA[
           if (!this._formattingEnabled)
             return;
@@ -645,17 +622,16 @@
                 break;
               case "autoFill":
                 this.completeDefaultIndex = this._prefs.getBoolPref(aData);
                 break;
               case "delay":
                 this.timeout = this._prefs.getIntPref(aData);
                 break;
               case "formatting.enabled":
-                this._clearFormatting();
                 this._formattingEnabled = this._prefs.getBoolPref(aData);
                 break;
               case "trimURLs":
                 this._mayTrimURLs = this._prefs.getBoolPref(aData);
                 break;
               case "unifiedcomplete":
                 let useUnifiedComplete = false;
                 try {