Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 35f9ae8

Browse files
keianhzoMortimerGoro
authored andcommitted
Fixes sessions restore crashes when the session is null (#1598)
1 parent b41a82c commit 35f9ae8

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ private void handlePoorPerformance() {
929929
if (mPoorPerformanceWhiteList.contains(originalUrl)) {
930930
return;
931931
}
932-
window.getSessionStack().loadUri("about:blank");
932+
window.getSessionStack().loadHomePage();
933933
final String[] buttons = {getString(R.string.ok_button), getString(R.string.performance_unblock_page)};
934934
window.showButtonPrompt(getString(R.string.performance_title), getString(R.string.performance_message), buttons, new ConfirmPromptWidget.ConfirmPromptDelegate() {
935935
@Override

app/src/common/shared/org/mozilla/vrbrowser/browser/engine/SessionStack.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public class SessionStack implements ContentBlocking.Delegate, GeckoSession.Navi
5858
private static final String LOGTAG = "VRB";
5959

6060
// You can test a local file using: "resource://android/assets/webvr/index.html"
61-
public static final String PRIVATE_BROWSING_URI = "about:privatebrowsing";
61+
private static final String PRIVATE_BROWSING_URI = "about:privatebrowsing";
62+
private static final String BLANK_BROWSING_URI = "about:blank";
6263
public static final int NO_SESSION = -1;
6364

6465
private transient LinkedList<GeckoSession.NavigationDelegate> mNavigationListeners;
@@ -314,6 +315,10 @@ public void restore(SessionStack store, int currentSessionId) {
314315

315316
if (mUsePrivateMode) {
316317
loadPrivateBrowsingPage();
318+
319+
} else if(state.mSessionState == null || state.mUri.equals(BLANK_BROWSING_URI) ||
320+
(state.mSessionState != null && state.mSessionState.size() == 0)) {
321+
loadHomePage();
317322
}
318323

319324
dumpAllState(state.mSession);
@@ -641,6 +646,14 @@ public void loadUri(String aUri) {
641646
mCurrentSession.loadUri(aUri);
642647
}
643648

649+
public void loadHomePage() {
650+
if (mCurrentSession == null) {
651+
return;
652+
}
653+
654+
mCurrentSession.loadUri(getHomeUri());
655+
}
656+
644657
public void loadPrivateBrowsingPage() {
645658
if (mCurrentSession == null) {
646659
return;

app/src/common/shared/org/mozilla/vrbrowser/browser/engine/SessionState.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import java.io.IOException;
1818
import java.util.ArrayList;
1919

20-
@JsonAdapter(SessionState.SafeTypeAdapterFactory.class)
20+
@JsonAdapter(SessionState.SessionStateAdapterFactory.class)
2121
public class SessionState {
2222

2323
public boolean mCanGoBack;
@@ -53,7 +53,7 @@ public GeckoSession.SessionState read(JsonReader in) {
5353
}
5454
}
5555

56-
public class SafeTypeAdapterFactory implements TypeAdapterFactory {
56+
public class SessionStateAdapterFactory implements TypeAdapterFactory {
5757
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
5858
final TypeAdapter<T> delegate = gson.getDelegateAdapter(this, type);
5959
final TypeAdapter<GeckoSession.SessionState> gsDelegate = new GeckoSessionStateAdapter();
@@ -77,7 +77,12 @@ public void write(JsonWriter out, T value) throws IOException {
7777
out.name("mSessionState").jsonValue(null);
7878

7979
} else {
80-
out.name("mSessionState").jsonValue(gsDelegate.toJson(session.mSessionState));
80+
if (session.mSessionState != null) {
81+
out.name("mSessionState").jsonValue(gsDelegate.toJson(session.mSessionState));
82+
83+
} else {
84+
out.name("mSessionState").jsonValue(null);
85+
}
8186
}
8287
out.endObject();
8388

0 commit comments

Comments
 (0)