mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 865005 - Part 4: Merge multiple session strings before restoring. r=mfinkle
This commit is contained in:
parent
c06317a64d
commit
59156efda0
@ -1649,8 +1649,8 @@ abstract public class GeckoApp
|
||||
flags |= (tabObject.optBoolean("desktopMode") ? Tabs.LOADURL_DESKTOP : 0);
|
||||
flags |= (tabObject.optBoolean("isPrivate") ? Tabs.LOADURL_PRIVATE : 0);
|
||||
|
||||
Tab tab = Tabs.getInstance().loadUrl(sessionTab.getSelectedUrl(), flags);
|
||||
tab.updateTitle(sessionTab.getSelectedTitle());
|
||||
Tab tab = Tabs.getInstance().loadUrl(sessionTab.getUrl(), flags);
|
||||
tab.updateTitle(sessionTab.getTitle());
|
||||
|
||||
try {
|
||||
tabObject.put("tabId", tab.getId());
|
||||
@ -1661,9 +1661,10 @@ abstract public class GeckoApp
|
||||
}
|
||||
};
|
||||
|
||||
parser.parse(sessionString);
|
||||
if (mPrivateBrowsingSession != null) {
|
||||
parser.parse(mPrivateBrowsingSession);
|
||||
if (mPrivateBrowsingSession == null) {
|
||||
parser.parse(sessionString);
|
||||
} else {
|
||||
parser.parse(sessionString, mPrivateBrowsingSession);
|
||||
}
|
||||
|
||||
if (tabs.length() > 0) {
|
||||
|
@ -9,6 +9,8 @@
|
||||
|
||||
package org.mozilla.gecko;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@ -19,24 +21,24 @@ public abstract class SessionParser {
|
||||
private static final String LOGTAG = "GeckoSessionParser";
|
||||
|
||||
public class SessionTab {
|
||||
String mSelectedTitle;
|
||||
String mSelectedUrl;
|
||||
boolean mIsSelected;
|
||||
JSONObject mTabObject;
|
||||
final private String mTitle;
|
||||
final private String mUrl;
|
||||
final private JSONObject mTabObject;
|
||||
private boolean mIsSelected;
|
||||
|
||||
private SessionTab(String selectedTitle, String selectedUrl, boolean isSelected, JSONObject tabObject) {
|
||||
mSelectedTitle = selectedTitle;
|
||||
mSelectedUrl = selectedUrl;
|
||||
private SessionTab(String title, String url, boolean isSelected, JSONObject tabObject) {
|
||||
mTitle = title;
|
||||
mUrl = url;
|
||||
mIsSelected = isSelected;
|
||||
mTabObject = tabObject;
|
||||
}
|
||||
|
||||
public String getSelectedTitle() {
|
||||
return mSelectedTitle;
|
||||
public String getTitle() {
|
||||
return mTitle;
|
||||
}
|
||||
|
||||
public String getSelectedUrl() {
|
||||
return mSelectedUrl;
|
||||
public String getUrl() {
|
||||
return mUrl;
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
@ -50,41 +52,48 @@ public abstract class SessionParser {
|
||||
|
||||
abstract public void onTabRead(SessionTab tab);
|
||||
|
||||
public void parse(String sessionString) {
|
||||
final JSONArray tabs;
|
||||
final JSONObject window;
|
||||
int selected = -1;
|
||||
public void parse(String... sessionStrings) {
|
||||
final LinkedList<SessionTab> sessionTabs = new LinkedList<SessionTab>();
|
||||
int totalCount = 0;
|
||||
int selectedIndex = -1;
|
||||
try {
|
||||
window = new JSONObject(sessionString).getJSONArray("windows").getJSONObject(0);
|
||||
tabs = window.getJSONArray("tabs");
|
||||
selected = window.optInt("selected", -1);
|
||||
for (String sessionString : sessionStrings) {
|
||||
final JSONObject window = new JSONObject(sessionString).getJSONArray("windows").getJSONObject(0);
|
||||
final JSONArray tabs = window.getJSONArray("tabs");
|
||||
final int optSelected = window.optInt("selected", -1);
|
||||
|
||||
for (int i = 0; i < tabs.length(); i++) {
|
||||
final JSONObject tab = tabs.getJSONObject(i);
|
||||
final int index = tab.getInt("index");
|
||||
final JSONObject entry = tab.getJSONArray("entries").getJSONObject(index - 1);
|
||||
final String url = entry.getString("url");
|
||||
|
||||
String title = entry.optString("title");
|
||||
if (title.length() == 0) {
|
||||
title = url;
|
||||
}
|
||||
|
||||
totalCount++;
|
||||
boolean selected = false;
|
||||
if (optSelected == i+1) {
|
||||
selected = true;
|
||||
selectedIndex = totalCount;
|
||||
}
|
||||
sessionTabs.add(new SessionTab(title, url, selected, tab));
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.e(LOGTAG, "JSON error", e);
|
||||
return;
|
||||
}
|
||||
|
||||
int numTabs = tabs.length();
|
||||
if (selected < 1 || selected > numTabs) {
|
||||
selected = 1;
|
||||
// If no selected index was found, select the first tab.
|
||||
if (selectedIndex == -1 && sessionTabs.size() > 0) {
|
||||
sessionTabs.getFirst().mIsSelected = true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < numTabs; i++) {
|
||||
try {
|
||||
JSONObject tab = tabs.getJSONObject(i);
|
||||
int index = tab.getInt("index");
|
||||
JSONObject entry = tab.getJSONArray("entries").getJSONObject(index - 1);
|
||||
String url = entry.getString("url");
|
||||
|
||||
String title = entry.optString("title");
|
||||
if (title.length() == 0) {
|
||||
title = url;
|
||||
}
|
||||
|
||||
onTabRead(new SessionTab(title, url, (selected == i+1), tab));
|
||||
} catch (JSONException e) {
|
||||
Log.e(LOGTAG, "error reading json file", e);
|
||||
return;
|
||||
}
|
||||
for (SessionTab tab : sessionTabs) {
|
||||
onTabRead(tab);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public class LastTabsSection extends AboutHomeSection {
|
||||
new SessionParser() {
|
||||
@Override
|
||||
public void onTabRead(final SessionTab tab) {
|
||||
final String url = tab.getSelectedUrl();
|
||||
final String url = tab.getUrl();
|
||||
// don't show last tabs for about:home
|
||||
if (url.equals("about:home")) {
|
||||
return;
|
||||
@ -69,7 +69,7 @@ public class LastTabsSection extends AboutHomeSection {
|
||||
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
final Bitmap favicon = BrowserDB.getFaviconForUrl(resolver, url);
|
||||
final String title = tab.getSelectedTitle();
|
||||
final String title = tab.getTitle();
|
||||
lastTabs.add(new TabInfo(url, title, favicon));
|
||||
}
|
||||
}.parse(jsonString);
|
||||
|
Loading…
Reference in New Issue
Block a user