From f483cfc41da8e63b4fe6289fc96adaf94edc60a3 Mon Sep 17 00:00:00 2001 From: Margaret Leibovic Date: Thu, 2 Aug 2012 14:15:17 -0700 Subject: [PATCH 1/2] Bug 778940 - Clean up our session history logic in Tab. r=mfinkle --- mobile/android/base/Tab.java | 46 +++++++++++++----------- mobile/android/chrome/content/browser.js | 26 ++++++++------ 2 files changed, 41 insertions(+), 31 deletions(-) diff --git a/mobile/android/base/Tab.java b/mobile/android/base/Tab.java index bf5ac26eff2a..c388e03cf184 100644 --- a/mobile/android/base/Tab.java +++ b/mobile/android/base/Tab.java @@ -454,39 +454,39 @@ public final class Tab { GeckoApp.mAppContext.loadUrl("about:reader?url=" + Uri.encode(getURL())); } - public boolean doReload() { + public void doReload() { GeckoEvent e = GeckoEvent.createBroadcastEvent("Session:Reload", ""); GeckoAppShell.sendEventToGecko(e); - return true; } + // Our version of nsSHistory::GetCanGoBack public boolean canDoBack() { - return (mHistoryIndex < 1 ? false : true); + return mHistoryIndex > 0; } public boolean doBack() { - if (mHistoryIndex < 1) { + if (!canDoBack()) return false; - } + GeckoEvent e = GeckoEvent.createBroadcastEvent("Session:Back", ""); GeckoAppShell.sendEventToGecko(e); return true; } - public boolean doStop() { + public void doStop() { GeckoEvent e = GeckoEvent.createBroadcastEvent("Session:Stop", ""); GeckoAppShell.sendEventToGecko(e); - return true; } + // Our version of nsSHistory::GetCanGoForward public boolean canDoForward() { - return (mHistoryIndex + 1 < mHistorySize); + return mHistoryIndex < mHistorySize - 1; } public boolean doForward() { - if (mHistoryIndex + 1 >= mHistorySize) { + if (!canDoForward()) return false; - } + GeckoEvent e = GeckoEvent.createBroadcastEvent("Session:Forward", ""); GeckoAppShell.sendEventToGecko(e); return true; @@ -531,22 +531,22 @@ public final class Tab { void handleSessionHistoryMessage(String event, JSONObject message) throws JSONException { if (event.equals("New")) { - final String uri = message.getString("uri"); + final String url = message.getString("url"); mHistoryIndex++; mHistorySize = mHistoryIndex + 1; GeckoAppShell.getHandler().post(new Runnable() { public void run() { - GlobalHistory.getInstance().add(uri); + GlobalHistory.getInstance().add(url); } }); } else if (event.equals("Back")) { - if (mHistoryIndex - 1 < 0) { + if (!canDoBack()) { Log.e(LOGTAG, "Received unexpected back notification"); return; } mHistoryIndex--; } else if (event.equals("Forward")) { - if (mHistoryIndex + 1 >= mHistorySize) { + if (!canDoForward()) { Log.e(LOGTAG, "Received unexpected forward notification"); return; } @@ -559,14 +559,20 @@ public final class Tab { } mHistoryIndex = index; } else if (event.equals("Purge")) { - int numEntries = message.getInt("index"); + int numEntries = message.getInt("numEntries"); + if (numEntries > mHistorySize) { + Log.e(LOGTAG, "Received unexpectedly large number of history entries to purge"); + mHistoryIndex = -1; + mHistorySize = 0; + return; + } + mHistorySize -= numEntries; mHistoryIndex -= numEntries; - if (mHistorySize < 0 || mHistoryIndex < -1) { - Log.e(LOGTAG, "Unexpected history state: index = " + mHistoryIndex + ", size = " + mHistorySize); - mHistorySize = 0; - mHistoryIndex = -1; - } + + // If we weren't at the last history entry, mHistoryIndex may have become too small + if (mHistoryIndex < -1) + mHistoryIndex = -1; } } diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index f1c49f33bc82..7d385bd4e912 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -2971,33 +2971,37 @@ Tab.prototype = { onStatusChange: function(aBrowser, aWebProgress, aRequest, aStatus, aMessage) { }, - _sendHistoryEvent: function(aMessage, aIndex, aUri) { + _sendHistoryEvent: function(aMessage, aParams) { let message = { gecko: { type: "SessionHistory:" + aMessage, tabID: this.id, } }; - if (aIndex != -1) { - message.gecko.index = aIndex; - } - if (aUri != null) { - message.gecko.uri = aUri; + + if (aParams) { + if ("url" in aParams) + message.gecko.url = aParams.url; + if ("index" in aParams) + message.gecko.index = aParams.index; + if ("numEntries" in aParams) + message.gecko.numEntries = aParams.numEntries; } + sendMessageToJava(message); }, OnHistoryNewEntry: function(aUri) { - this._sendHistoryEvent("New", -1, aUri.spec); + this._sendHistoryEvent("New", { url: aUri.spec }); }, OnHistoryGoBack: function(aUri) { - this._sendHistoryEvent("Back", -1, null); + this._sendHistoryEvent("Back"); return true; }, OnHistoryGoForward: function(aUri) { - this._sendHistoryEvent("Forward", -1, null); + this._sendHistoryEvent("Forward"); return true; }, @@ -3008,12 +3012,12 @@ Tab.prototype = { }, OnHistoryGotoIndex: function(aIndex, aUri) { - this._sendHistoryEvent("Goto", aIndex, null); + this._sendHistoryEvent("Goto", { index: aIndex }); return true; }, OnHistoryPurge: function(aNumEntries) { - this._sendHistoryEvent("Purge", aNumEntries, null); + this._sendHistoryEvent("Purge", { numEntries: aNumEntries }); return true; }, From 69a9d2fd42f26f0da4bdd749829eb6ce6d8ab422 Mon Sep 17 00:00:00 2001 From: Margaret Leibovic Date: Thu, 2 Aug 2012 14:16:54 -0700 Subject: [PATCH 2/2] Bug 779007 - Don't make about: pages privileged if they don't need to be. r=mfinkle --- mobile/android/components/AboutRedirector.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mobile/android/components/AboutRedirector.js b/mobile/android/components/AboutRedirector.js index 77d61f904269..265be6a1cbb7 100644 --- a/mobile/android/components/AboutRedirector.js +++ b/mobile/android/components/AboutRedirector.js @@ -39,17 +39,17 @@ let modules = { }, blocked: { uri: "chrome://browser/content/blockedSite.xhtml", - privileged: true, + privileged: false, hide: true }, certerror: { uri: "chrome://browser/content/aboutCertError.xhtml", - privileged: true, + privileged: false, hide: true }, home: { uri: "chrome://browser/content/aboutHome.xhtml", - privileged: true + privileged: false }, apps: { uri: "chrome://browser/content/aboutApps.xhtml",