Backout f118b840cabe, 8f90c8059733, d440fa8a1568 because bug 946074 breaks a test
authorMark Finkle <mfinkle@mozilla.com>
Fri, 06 Dec 2013 01:41:50 -0500
changeset 174812 871fab42fa64c317157640777071e65486d87d8d
parent 174811 2c42e70b08c2745d17217405a9863d3e3ea8f684
child 174813 497e5afa3a4db7acacf071998e8b25632f79f9cc
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs946074
milestone28.0a1
backs outf118b840cabe5a9bd752ea45081006358674566a
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
Backout f118b840cabe, 8f90c8059733, d440fa8a1568 because bug 946074 breaks a test
mobile/android/base/home/BrowserSearch.java
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/home/BrowserSearch.java
+++ b/mobile/android/base/home/BrowserSearch.java
@@ -320,140 +320,66 @@ public class BrowserSearch extends HomeF
     }
 
     @Override
     protected void load() {
         SearchLoader.init(getLoaderManager(), LOADER_ID_SEARCH, mCursorLoaderCallbacks, mSearchTerm);
     }
 
     private void handleAutocomplete(String searchTerm, Cursor c) {
-        if (c == null ||
-            mAutocompleteHandler == null ||
-            TextUtils.isEmpty(searchTerm)) {
+        if (TextUtils.isEmpty(mSearchTerm) || c == null || mAutocompleteHandler == null) {
             return;
         }
 
         // Avoid searching the path if we don't have to. Currently just
-        // decided by whether there is a '/' character in the string.
-        final boolean searchPath = searchTerm.indexOf('/') > 0;
+        // decided by if there is a '/' character in the string.
+        final boolean searchPath = (searchTerm.indexOf("/") > 0);
         final String autocompletion = findAutocompletion(searchTerm, c, searchPath);
 
-        if (autocompletion == null || mAutocompleteHandler == null) {
-            return;
+        if (autocompletion != null && mAutocompleteHandler != null) {
+            mAutocompleteHandler.onAutocomplete(autocompletion);
+            mAutocompleteHandler = null;
         }
-
-        // Prefetch auto-completed domain since it's a likely target
-        GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Session:Prefetch", "http://" + autocompletion));
-
-        mAutocompleteHandler.onAutocomplete(autocompletion);
-        mAutocompleteHandler = null;
-    }
-
-    /**
-     * Returns the substring of a provided URI, starting at the given offset,
-     * and extending up to the end of the path segment in which the provided
-     * index is found.
-     *
-     * For example, given
-     *
-     *   "www.reddit.com/r/boop/abcdef", 0, ?
-     *
-     * this method returns
-     *
-     *   ?=2:  "www.reddit.com/"
-     *   ?=17: "www.reddit.com/r/boop/"
-     *   ?=21: "www.reddit.com/r/boop/"
-     *   ?=22: "www.reddit.com/r/boop/abcdef"
-     *
-     */
-    private static String uriSubstringUpToMatchedPath(final String url, final int offset, final int begin) {
-        final int afterEnd = url.length();
-
-        // We want to include the trailing slash, but not other characters.
-        int chop = url.indexOf('/', begin);
-        if (chop != -1) {
-            ++chop;
-            if (chop < offset) {
-                // This isn't supposed to happen. Fall back to returning the whole damn thing.
-                return url;
-            }
-        } else {
-            chop = url.indexOf('?', begin);
-            if (chop == -1) {
-                chop = url.indexOf('#', begin);
-            }
-            if (chop == -1) {
-                chop = afterEnd;
-            }
-        }
-
-        return url.substring(offset, chop);
     }
 
     private String findAutocompletion(String searchTerm, Cursor c, boolean searchPath) {
         if (!c.moveToFirst()) {
             return null;
         }
 
-        final int searchLength = searchTerm.length();
         final int urlIndex = c.getColumnIndexOrThrow(URLColumns.URL);
         int searchCount = 0;
 
         do {
-            final String url = c.getString(urlIndex);
-
-            if (searchCount == 0) {
-                // Prefetch the first item in the list since it's weighted the highest
-                GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Session:Prefetch", url.toString()));
-            }
+            final Uri url = Uri.parse(c.getString(urlIndex));
+            final String host = StringUtils.stripCommonSubdomains(url.getHost());
 
-            // Does the completion match against the whole URL? This will match
-            // about: pages, as well as user input including "http://...".
-            if (url.startsWith(searchTerm)) {
-                return uriSubstringUpToMatchedPath(url, 0, searchLength);
-            }
-
-            final Uri uri = Uri.parse(url);
-            final String host = uri.getHost();
-
-            // Host may be null for about pages.
+            // Host may be null for about pages
             if (host == null) {
                 continue;
             }
 
-            if (host.startsWith(searchTerm)) {
-                return host + "/";
-            }
-
-            final String strippedHost = StringUtils.stripCommonSubdomains(host);
-            if (strippedHost.startsWith(searchTerm)) {
-                return strippedHost + "/";
-            }
-
-            ++searchCount;
-
-            if (!searchPath) {
-                continue;
+            final StringBuilder hostBuilder = new StringBuilder(host);
+            if (hostBuilder.indexOf(searchTerm) == 0) {
+                return hostBuilder.append("/").toString();
             }
 
-            // Otherwise, if we're matching paths, let's compare against the string itself.
-            final int hostOffset = url.indexOf(strippedHost);
-            if (hostOffset == -1) {
-                // This was a URL string that parsed to a different host (normalized?).
-                // Give up.
-                continue;
+            if (searchPath) {
+                final List<String> path = url.getPathSegments();
+
+                for (String s : path) {
+                    hostBuilder.append("/").append(s);
+
+                    if (hostBuilder.indexOf(searchTerm) == 0) {
+                        return hostBuilder.append("/").toString();
+                    }
+                }
             }
 
-            // We already matched the non-stripped host, so now we're
-            // substring-searching in the part of the URL without the common
-            // subdomains.
-            if (url.startsWith(searchTerm, hostOffset)) {
-                // Great! Return including the rest of the path segment.
-                return uriSubstringUpToMatchedPath(url, hostOffset, hostOffset + searchLength);
-            }
+            searchCount++;
         } while (searchCount < MAX_AUTOCOMPLETE_SEARCH && c.moveToNext());
 
         return null;
     }
 
     private void filterSuggestions() {
         if (mSuggestClient == null || !mSuggestionsEnabled) {
             return;
@@ -856,17 +782,17 @@ public class BrowserSearch extends HomeF
             return SearchLoader.createInstance(getActivity(), args);
         }
 
         @Override
         public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
             mAdapter.swapCursor(c);
 
             // We should handle autocompletion based on the search term
-            // associated with the loader that has just provided
+            // associated with the currently loader that has just provided
             // the results.
             SearchCursorLoader searchLoader = (SearchCursorLoader) loader;
             handleAutocomplete(searchLoader.getSearchTerm(), c);
         }
 
         @Override
         public void onLoaderReset(Loader<Cursor> loader) {
             mAdapter.swapCursor(null);
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -4278,19 +4278,17 @@ var BrowserEventHandler = {
       closest = ElementTouchHelper.elementFromPoint(aEvent.changedTouches[0].screenX,
                                                     aEvent.changedTouches[0].screenY);
     if (!closest)
       closest = aEvent.target;
 
     if (closest) {
       let uri = this._getLinkURI(closest);
       if (uri) {
-        try {
-          Services.io.QueryInterface(Ci.nsISpeculativeConnect).speculativeConnect(uri, null);
-        } catch (e) {}
+        Services.io.QueryInterface(Ci.nsISpeculativeConnect).speculativeConnect(uri, null);
       }
       this._doTapHighlight(closest);
     }
   },
 
   _getLinkURI: function(aElement) {
     if (aElement.nodeType == Ci.nsIDOMNode.ELEMENT_NODE &&
         ((aElement instanceof Ci.nsIDOMHTMLAnchorElement && aElement.href) ||
@@ -6704,19 +6702,17 @@ var SearchEngines = {
       }
     });
 
     // Send a speculative connection to the default engine.
     let connector = Services.io.QueryInterface(Ci.nsISpeculativeConnect);
     let searchURI = Services.search.defaultEngine.getSubmission("dummy").uri;
     let callbacks = window.QueryInterface(Ci.nsIInterfaceRequestor)
                           .getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsILoadContext);
-    try {
-      connector.speculativeConnect(searchURI, callbacks);
-    } catch (e) {}
+    connector.speculativeConnect(searchURI, callbacks);
   },
 
   _handleSearchEnginesGetAll: function _handleSearchEnginesGetAll(rv) {
     this._handleSearchEnginesGet(rv, true);
   },
   _handleSearchEnginesGetVisible: function _handleSearchEnginesGetVisible(rv) {
     this._handleSearchEnginesGet(rv, false)
   },
@@ -8108,117 +8104,86 @@ var Distribution = {
       if (!(reason instanceof OS.File.Error && reason.becauseNoSuchFile)) {
         Cu.reportError("Distribution: Could not read from " + aFile.leafName + " file");
       }
     });
   }
 };
 
 var Tabs = {
+  // This object provides functions to manage a most-recently-used list
+  // of tabs. Each tab has a timestamp associated with it that indicates when
+  // it was last touched.
+
   _enableTabExpiration: false,
-  _domains: new Set(),
 
   init: function() {
-    // On low-memory platforms, always allow tab expiration. On high-mem
-    // platforms, allow it to be turned on once we hit a low-mem situation.
+    // on low-memory platforms, always allow tab expiration. on high-mem
+    // platforms, allow it to be turned on once we hit a low-mem situation
     if (BrowserApp.isOnLowMemoryPlatform) {
       this._enableTabExpiration = true;
     } else {
       Services.obs.addObserver(this, "memory-pressure", false);
     }
-
-    Services.obs.addObserver(this, "Session:Prefetch", false);
-
-    BrowserApp.deck.addEventListener("pageshow", this, false);
   },
 
   uninit: function() {
     if (!this._enableTabExpiration) {
-      // If _enableTabExpiration is true then we won't have this
+      // if _enableTabExpiration is true then we won't have this
       // observer registered any more.
       Services.obs.removeObserver(this, "memory-pressure");
     }
-
-    Services.obs.removeObserver(this, "Session:Prefetch");
-
-    BrowserApp.deck.removeEventListener("pageshow", this);
   },
 
   observe: function(aSubject, aTopic, aData) {
-    switch (aTopic) {
-      case "memory-pressure":
-        if (aData != "heap-minimize") {
-          this._enableTabExpiration = true;
-          Services.obs.removeObserver(this, "memory-pressure");
-        }
-        break;
-      case "Session:Prefetch":
-        if (aData) {
-          let uri = Services.io.newURI(aData, null, null);
-          if (uri && !this._domains.has(uri.host)) {
-            try {
-              Services.io.QueryInterface(Ci.nsISpeculativeConnect).speculativeConnect(uri, null);
-              this._domains.add(uri.host);
-            } catch (e) {}
-          }
-        }
-        break;
-    }
-  },
-
-  handleEvent: function(aEvent) {
-    switch (aEvent.type) {
-      case "pageshow":
-        // Clear the domain cache whenever a page get loaded into any browser.
-        this._domains.clear();
-        break;
+    if (aTopic == "memory-pressure" && aData != "heap-minimize") {
+      this._enableTabExpiration = true;
+      Services.obs.removeObserver(this, "memory-pressure");
     }
   },
 
   touch: function(aTab) {
     aTab.lastTouchedAt = Date.now();
   },
 
-  // Manage the most-recently-used list of tabs. Each tab has a timestamp
-  // associated with it that indicates when it was last touched.
   expireLruTab: function() {
     if (!this._enableTabExpiration) {
       return false;
     }
     let expireTimeMs = Services.prefs.getIntPref("browser.tabs.expireTime") * 1000;
     if (expireTimeMs < 0) {
-      // This behaviour is disabled.
+      // this behaviour is disabled
       return false;
     }
     let tabs = BrowserApp.tabs;
     let selected = BrowserApp.selectedTab;
     let lruTab = null;
-    // Find the least recently used non-zombie tab.
+    // find the least recently used non-zombie tab
     for (let i = 0; i < tabs.length; i++) {
       if (tabs[i] == selected || tabs[i].browser.__SS_restore) {
-        // This tab is selected or already a zombie, skip it.
+        // this tab is selected or already a zombie, skip it
         continue;
       }
       if (lruTab == null || tabs[i].lastTouchedAt < lruTab.lastTouchedAt) {
         lruTab = tabs[i];
       }
     }
-    // If the tab was last touched more than browser.tabs.expireTime seconds ago,
-    // zombify it.
+    // if the tab was last touched more than browser.tabs.expireTime seconds ago,
+    // zombify it
     if (lruTab) {
       let tabAgeMs = Date.now() - lruTab.lastTouchedAt;
       if (tabAgeMs > expireTimeMs) {
         MemoryObserver.zombify(lruTab);
         Telemetry.addData("FENNEC_TAB_EXPIRED", tabAgeMs / 1000);
         return true;
       }
     }
     return false;
   },
 
-  // For debugging
+  // for debugging
   dump: function(aPrefix) {
     let tabs = BrowserApp.tabs;
     for (let i = 0; i < tabs.length; i++) {
       dump(aPrefix + " | " + "Tab [" + tabs[i].browser.contentWindow.location.href + "]: lastTouchedAt:" + tabs[i].lastTouchedAt + ", zombie:" + tabs[i].browser.__SS_restore);
     }
   },
 };