Backout f118b840cabe, 8f90c8059733, d440fa8a1568 because bug 946074 breaks a test

This commit is contained in:
Mark Finkle 2013-12-06 01:41:50 -05:00
Родитель 9c69d68f9d
Коммит 9822fac053
2 изменённых файлов: 42 добавлений и 151 удалений

Просмотреть файл

@ -325,67 +325,19 @@ public class BrowserSearch extends HomeFragment
}
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) {
@ -393,62 +345,36 @@ public class BrowserSearch extends HomeFragment
return null;
}
final int searchLength = searchTerm.length();
final int urlIndex = c.getColumnIndexOrThrow(URLColumns.URL);
int searchCount = 0;
do {
final String url = c.getString(urlIndex);
final Uri url = Uri.parse(c.getString(urlIndex));
final String host = StringUtils.stripCommonSubdomains(url.getHost());
if (searchCount == 0) {
// Prefetch the first item in the list since it's weighted the highest
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Session:Prefetch", url.toString()));
}
// 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 StringBuilder hostBuilder = new StringBuilder(host);
if (hostBuilder.indexOf(searchTerm) == 0) {
return hostBuilder.append("/").toString();
}
final String strippedHost = StringUtils.stripCommonSubdomains(host);
if (strippedHost.startsWith(searchTerm)) {
return strippedHost + "/";
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();
}
}
}
++searchCount;
if (!searchPath) {
continue;
}
// 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;
}
// 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;
@ -861,7 +787,7 @@ public class BrowserSearch extends HomeFragment
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);

Просмотреть файл

@ -4283,9 +4283,7 @@ var BrowserEventHandler = {
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);
}
@ -6709,9 +6707,7 @@ var SearchEngines = {
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) {
@ -8113,63 +8109,34 @@ var Distribution = {
};
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");
}
},
@ -8177,32 +8144,30 @@ var Tabs = {
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) {
@ -8214,7 +8179,7 @@ var Tabs = {
return false;
},
// For debugging
// for debugging
dump: function(aPrefix) {
let tabs = BrowserApp.tabs;
for (let i = 0; i < tabs.length; i++) {