Skip to content

Commit

Permalink
Fix content type values being null after deserializing
Browse files Browse the repository at this point in the history
When we restore the window state from a JSON file, the content type
field may be null if the GSON library was not able to map it to one
of the enum values.

Igalia#1644 changed the type of the
WindowState.panelType field from integer to enum. This meant that
the serialized values did not match the new type, causing the
restored field to unexpectedly become NULL. This caused a crash.

The solution is to change the name of the field to
WindowState.contentType so it will not cause a clash when serializing
and deserializing. Additionally, this PR adds checks to ensure that
the restored value is not NULL.

Fixes Igalia#1648
  • Loading branch information
felipeerias authored and svillar committed Nov 29, 2024
1 parent f784a21 commit 91873b5
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions app/src/common/shared/com/igalia/wolvic/ui/widgets/Windows.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ class WindowState {
int textureHeight;
float worldWidth;
int tabIndex = -1;
ContentType panelType = ContentType.WEB_CONTENT;
// NOTE: Enum values may be null when deserialized by GSON.
ContentType contentType = ContentType.WEB_CONTENT;

public void load(@NonNull WindowWidget aWindow, WindowsState aState, int aTabIndex) {
WidgetPlacement widgetPlacement;
Expand All @@ -118,10 +119,10 @@ public void load(@NonNull WindowWidget aWindow, WindowsState aState, int aTabInd
worldWidth = widgetPlacement.worldWidth;
tabIndex = aTabIndex;
if (aWindow.isNativeContentVisible()) {
panelType = aWindow.getSelectedPanel();
contentType = aWindow.getSelectedPanel();

} else {
panelType = ContentType.WEB_CONTENT;
contentType = ContentType.WEB_CONTENT;
}
}
}
Expand Down Expand Up @@ -171,9 +172,10 @@ public enum ContentType {
DOWNLOADS(UrlUtils.ABOUT_DOWNLOADS),
ADDONS(UrlUtils.ABOUT_ADDONS),
NOTIFICATIONS(UrlUtils.ABOUT_NOTIFICATIONS);
public final String URL;

ContentType(String url) {
@NonNull
public final String URL;
ContentType(@NonNull String url) {
this.URL = url;
}
}
Expand Down Expand Up @@ -365,13 +367,16 @@ private WindowWidget addRestoredWindow(@NonNull WindowState aState, @Nullable Se
if (aSession != null) {
aSession.setActive(true);
}
if (aState.contentType == null) {
aState.contentType = ContentType.WEB_CONTENT;
}
WindowWidget newWindow = createWindow(aSession);
newWindow.getPlacement().width = aState.textureWidth;
newWindow.getPlacement().height = aState.textureHeight;
newWindow.getPlacement().worldWidth = aState.worldWidth;
placeWindow(newWindow, aState.placement);
if (newWindow.getSession() != null) {
switch (aState.panelType) {
switch (aState.contentType) {
case BOOKMARKS:
newWindow.getSession().loadUri(UrlUtils.ABOUT_BOOKMARKS);
break;
Expand Down

0 comments on commit 91873b5

Please sign in to comment.