Bug 852787 - Do keyword DB lookup on background thread r=bnicholson

This commit is contained in:
Mark Finkle 2013-04-08 16:56:18 -04:00
parent 7a8a0a3313
commit 51c8294c45

View File

@ -383,28 +383,33 @@ public class AwesomeBar extends GeckoActivity {
finishWithResult(resultIntent);
}
private void openUserEnteredAndFinish(String url) {
int index = url.indexOf(' ');
String keywordUrl = null;
String keywordSearch = null;
private void openUserEnteredAndFinish(final String url) {
final int index = url.indexOf(' ');
// Check for a keyword if the URL looks like a search query
if (StringUtils.isSearchQuery(url, true)) {
if (index == -1) {
keywordUrl = BrowserDB.getUrlForKeyword(getContentResolver(), url);
keywordSearch = "";
} else {
keywordUrl = BrowserDB.getUrlForKeyword(getContentResolver(), url.substring(0, index));
keywordSearch = url.substring(index + 1);
}
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
String keywordUrl = null;
String keywordSearch = "";
if (index == -1) {
keywordUrl = BrowserDB.getUrlForKeyword(getContentResolver(), url);
} else {
keywordUrl = BrowserDB.getUrlForKeyword(getContentResolver(), url.substring(0, index));
keywordSearch = url.substring(index + 1);
}
if (keywordUrl == null) {
openUrlAndFinish(url, "", true);
} else {
String search = URLEncoder.encode(keywordSearch);
openUrlAndFinish(keywordUrl.replace("%s", search), "", true);
}
}
});
} else {
openUrlAndFinish(url, "", true);
}
if (keywordUrl != null) {
String search = URLEncoder.encode(keywordSearch);
url = keywordUrl.replace("%s", search);
}
openUrlAndFinish(url, "", true);
}
private void openSearchAndFinish(String url, String engine) {