Bug 823230 - (Part 2) Remember search terms and show them again when returning to the awesomescreen. r=mfinkle

This commit is contained in:
Margaret Leibovic 2013-04-10 11:02:05 -07:00
parent 5939abd93c
commit e488e3c1cf
3 changed files with 39 additions and 8 deletions

View File

@ -2232,19 +2232,22 @@ abstract public class GeckoApp
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.putExtra(AwesomeBar.TARGET_KEY, aTarget.name());
// if we were passed in a url, show it
// If we were passed in a URL, show it.
if (aUrl != null && !TextUtils.isEmpty(aUrl)) {
intent.putExtra(AwesomeBar.CURRENT_URL_KEY, aUrl);
} else if (aTarget == AwesomeBar.Target.CURRENT_TAB) {
// otherwise, if we're editing the current tab, show its url
// Otherwise, if we're editing the current tab, show its URL.
Tab tab = Tabs.getInstance().getSelectedTab();
if (tab != null) {
aUrl = tab.getURL();
// Check to see if there's a user-entered search term, which we save
// whenever the user performs a search.
aUrl = tab.getUserSearch();
if (TextUtils.isEmpty(aUrl)) {
aUrl = tab.getURL();
}
if (aUrl != null) {
intent.putExtra(AwesomeBar.CURRENT_URL_KEY, aUrl);
}
}
}

View File

@ -35,6 +35,7 @@ public class Tab {
private final int mId;
private long mLastUsed;
private String mUrl;
private String mUserSearch;
private String mTitle;
private Bitmap mFavicon;
private String mFaviconUrl;
@ -72,6 +73,7 @@ public class Tab {
mId = id;
mLastUsed = 0;
mUrl = url;
mUserSearch = "";
mExternal = external;
mParentId = parentId;
mTitle = title == null ? "" : title;
@ -125,6 +127,11 @@ public class Tab {
return mUrl;
}
// mUserSearch should never be null, but it may be an empty string
public synchronized String getUserSearch() {
return mUserSearch;
}
// mTitle should never be null, but it may be an empty string
public synchronized String getTitle() {
return mTitle;
@ -232,6 +239,10 @@ public class Tab {
}
}
private synchronized void updateUserSearch(String userSearch) {
mUserSearch = userSearch;
}
public void setDocumentURI(String documentURI) {
mDocumentURI = documentURI;
}
@ -527,6 +538,7 @@ public class Tab {
final String uri = message.getString("uri");
mEnteringReaderMode = ReaderModeUtils.isEnteringReaderMode(mUrl, uri);
updateURL(uri);
updateUserSearch(message.getString("userSearch"));
setDocumentURI(message.getString("documentURI"));
if (message.getBoolean("sameDocument")) {

View File

@ -242,6 +242,7 @@ var BrowserApp = {
Services.obs.addObserver(this, "FormHistory:Init", false);
Services.obs.addObserver(this, "ToggleProfiling", false);
Services.obs.addObserver(this, "gather-telemetry", false);
Services.obs.addObserver(this, "keyword-search", false);
Services.obs.addObserver(this, "sessionstore-state-purge-complete", false);
@ -687,10 +688,12 @@ var BrowserApp = {
let referrerURI = "referrerURI" in aParams ? aParams.referrerURI : null;
let charset = "charset" in aParams ? aParams.charset : null;
if ("showProgress" in aParams) {
if ("showProgress" in aParams || "userSearch" in aParams) {
let tab = this.getTabForBrowser(aBrowser);
if (tab)
tab.showProgress = aParams.showProgress;
if (tab) {
if ("showProgress" in aParams) tab.showProgress = aParams.showProgress;
if ("userSearch" in aParams) tab.userSearch = aParams.userSearch;
}
}
try {
@ -1199,6 +1202,7 @@ var BrowserApp = {
if (data.engine) {
let engine = Services.search.getEngineByName(data.engine);
if (engine) {
params.userSearch = url;
let submission = engine.getSubmission(url);
url = submission.uri.spec;
params.postData = submission.postData;
@ -1224,6 +1228,11 @@ var BrowserApp = {
this._handleTabClosed(this.getTabForId(parseInt(aData)));
break;
case "keyword-search":
// This assumes the user can only perform a keyword serach on the selected tab.
this.selectedTab.userSearch = aData;
break;
case "Browser:Quit":
this.quit();
break;
@ -2444,6 +2453,9 @@ Tab.prototype = {
// This determines whether or not we show the progress throbber in the urlbar
this.showProgress = "showProgress" in aParams ? aParams.showProgress : true;
// The search term the user entered to load the current URL
this.userSearch = "userSearch" in aParams ? aParams.userSearch : "";
try {
this.browser.loadURIWithFlags(aURL, flags, referrerURI, charset, postData);
} catch(e) {
@ -3283,6 +3295,7 @@ Tab.prototype = {
type: "Content:LocationChange",
tabID: this.id,
uri: fixedURI.spec,
userSearch: this.userSearch || "",
documentURI: documentURI,
contentType: (contentType ? contentType : ""),
sameDocument: sameDocument
@ -3290,6 +3303,9 @@ Tab.prototype = {
sendMessageToJava(message);
// The search term is only valid for this location change event, so reset it here.
this.userSearch = "";
if (!sameDocument) {
// XXX This code assumes that this is the earliest hook we have at which
// browser.contentDocument is changed to the new document we're loading