From e488e3c1cfbdf3f9b57a88fc8b5da9f64a2c009e Mon Sep 17 00:00:00 2001 From: Margaret Leibovic Date: Wed, 10 Apr 2013 11:02:05 -0700 Subject: [PATCH] Bug 823230 - (Part 2) Remember search terms and show them again when returning to the awesomescreen. r=mfinkle --- mobile/android/base/GeckoApp.java | 13 ++++++++----- mobile/android/base/Tab.java | 12 ++++++++++++ mobile/android/chrome/content/browser.js | 22 +++++++++++++++++++--- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index aac84c22116..63b63125768 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -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); } - } } diff --git a/mobile/android/base/Tab.java b/mobile/android/base/Tab.java index 2ab8d5dfac8..1fa7aa12ab6 100644 --- a/mobile/android/base/Tab.java +++ b/mobile/android/base/Tab.java @@ -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")) { diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index 7a6e02f0134..85232b69f18 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -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