Bug 778940 - Clean up our session history logic in Tab. r=mfinkle

This commit is contained in:
Margaret Leibovic 2012-08-02 14:15:17 -07:00
Родитель 1c5094b3b8
Коммит f483cfc41d
2 изменённых файлов: 41 добавлений и 31 удалений

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

@ -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;
}
}

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

@ -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;
},