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

Commit

Permalink
Fixes sessions restore crashes when the session is null (#1598)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo authored and MortimerGoro committed Aug 20, 2019
1 parent b41a82c commit 35f9ae8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ private void handlePoorPerformance() {
if (mPoorPerformanceWhiteList.contains(originalUrl)) {
return;
}
window.getSessionStack().loadUri("about:blank");
window.getSessionStack().loadHomePage();
final String[] buttons = {getString(R.string.ok_button), getString(R.string.performance_unblock_page)};
window.showButtonPrompt(getString(R.string.performance_title), getString(R.string.performance_message), buttons, new ConfirmPromptWidget.ConfirmPromptDelegate() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public class SessionStack implements ContentBlocking.Delegate, GeckoSession.Navi
private static final String LOGTAG = "VRB";

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

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

if (mUsePrivateMode) {
loadPrivateBrowsingPage();

} else if(state.mSessionState == null || state.mUri.equals(BLANK_BROWSING_URI) ||
(state.mSessionState != null && state.mSessionState.size() == 0)) {
loadHomePage();
}

dumpAllState(state.mSession);
Expand Down Expand Up @@ -641,6 +646,14 @@ public void loadUri(String aUri) {
mCurrentSession.loadUri(aUri);
}

public void loadHomePage() {
if (mCurrentSession == null) {
return;
}

mCurrentSession.loadUri(getHomeUri());
}

public void loadPrivateBrowsingPage() {
if (mCurrentSession == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.io.IOException;
import java.util.ArrayList;

@JsonAdapter(SessionState.SafeTypeAdapterFactory.class)
@JsonAdapter(SessionState.SessionStateAdapterFactory.class)
public class SessionState {

public boolean mCanGoBack;
Expand Down Expand Up @@ -53,7 +53,7 @@ public GeckoSession.SessionState read(JsonReader in) {
}
}

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

} else {
out.name("mSessionState").jsonValue(gsDelegate.toJson(session.mSessionState));
if (session.mSessionState != null) {
out.name("mSessionState").jsonValue(gsDelegate.toJson(session.mSessionState));

} else {
out.name("mSessionState").jsonValue(null);
}
}
out.endObject();

Expand Down

0 comments on commit 35f9ae8

Please sign in to comment.