Skip to content

Commit

Permalink
Kiosk mode uses a regular session, without history and without saving…
Browse files Browse the repository at this point in the history
… the window state
  • Loading branch information
felipeerias committed Jan 4, 2024
1 parent f070274 commit ac98a61
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,8 @@ void loadFromIntent(final Intent intent) {

if (openInKioskMode) {
// FIXME this might not work as expected if the app was already running
// this needs to work as if it was a different profile, so it operates as a PWA
// but it can not update the history, for example
mWindows.openInKioskMode(targetUri.toString());
} else {
if (openInWindow) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import androidx.preference.PreferenceManager;
import android.util.Log;
import android.view.Surface;
import android.view.inputmethod.CursorAnchorInfo;
Expand All @@ -22,6 +21,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import androidx.preference.PreferenceManager;

import com.igalia.wolvic.BuildConfig;
import com.igalia.wolvic.R;
Expand Down Expand Up @@ -1637,6 +1637,7 @@ public void onHistoryStateChange(@NonNull WSession aSession, @NonNull WSession.H
@Nullable
@Override
public WResult<Boolean> onVisited(@NonNull WSession aSession, @NonNull String url, @Nullable String lastVisitedURL, int flags) {
// this is where history items are saved
if (mState.mSession == aSession) {
if (mHistoryDelegate != null) {
return mHistoryDelegate.onVisited(aSession, url, lastVisitedURL, flags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import android.graphics.RectF;
import android.graphics.SurfaceTexture;
import android.net.Uri;
import androidx.preference.PreferenceManager;
import android.text.format.Formatter;
import android.util.Log;
import android.util.Pair;
Expand All @@ -37,6 +36,7 @@
import androidx.annotation.UiThread;
import androidx.core.content.FileProvider;
import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager;

import com.igalia.wolvic.R;
import com.igalia.wolvic.VRBrowserActivity;
Expand Down Expand Up @@ -1998,6 +1998,7 @@ public WResult<Boolean> onVisited(@NonNull WSession session, @NonNull String url
}

// Check if we want this type of url.
// Maybe here we should check if we are in kiosk mode
if (!shouldStoreUri(url)) {
return WResult.fromValue(false);
}
Expand Down Expand Up @@ -2052,6 +2053,11 @@ public WResult<Boolean> onVisited(@NonNull WSession session, @NonNull String url
* See https://dxr.mozilla.org/mozilla-central/source/mobile/android/components/build/nsAndroidHistory.cpp#326
*/
private boolean shouldStoreUri(@NonNull String uri) {
// In kiosk mode, we don't add entries to the general history.
if (isKioskMode()) {
return false;
}

Uri parsedUri = Uri.parse(uri);
String scheme = parsedUri.getScheme();
if (scheme == null) {
Expand Down
18 changes: 14 additions & 4 deletions app/src/common/shared/com/igalia/wolvic/ui/widgets/Windows.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class Windows implements TrayListener, TopBarWidget.Delegate, TitleBarWid
public static final int OPEN_IN_BACKGROUND = 1;
public static final int OPEN_IN_NEW_WINDOW = 2;


// this is the windows state file, maybe we need a different one for each installed app?
private static final String WINDOWS_SAVE_FILENAME = "windows_state.json";

private static final int TAB_ADDED_NOTIFICATION_ID = 0;
Expand Down Expand Up @@ -136,6 +136,7 @@ class WindowsState {
private WindowWidget mFullscreenWindow;
private WindowPlacement mRegularWindowPlacement;
private WindowPlacement mPrivateWindowPlacement;
private boolean mKioskMode = false;
private boolean mStoredCurvedMode = false;
private boolean mForcedCurvedMode = false;
private boolean mCenterWindows;
Expand Down Expand Up @@ -215,6 +216,8 @@ public Windows(Context aContext) {
restoreWindows();
}

// this is where the state of the open windows is saved
// we should save the state of kiosk mode separately
public void saveState() {
File file = new File(mContext.getFilesDir(), WINDOWS_SAVE_FILENAME);
try (Writer writer = new FileWriter(file)) {
Expand All @@ -228,8 +231,13 @@ public void saveState() {
sessionState.mUri != null && sessionState.mUri.startsWith(uri)
))
.collect(Collectors.toCollection(ArrayList::new));

if (mKioskMode) {
// don't overwrite the old file?
}

for (WindowWidget window : mRegularWindows) {
if (window.getSession() != null) {
if (window.getSession() != null && mKioskMode) {
WindowState windowState = new WindowState();
windowState.load(window, state, state.tabs.indexOf(window.getSession().getSessionState()));
state.regularWindowsState.add(windowState);
Expand Down Expand Up @@ -1356,7 +1364,7 @@ public void onFullScreen(@NonNull WindowWidget aWindow, boolean aFullScreen) {

@Override
public void onKioskMode(WindowWidget aWindow, boolean isKioskMode) {
// TODO
mKioskMode = isKioskMode;
}

public void selectTab(@NonNull Session aTab) {
Expand Down Expand Up @@ -1449,7 +1457,9 @@ private void openNewTab(@NonNull String aUri, @NewTabLocation int aLocation) {
}

public void openInKioskMode(@NonNull String aUri) {
Session session = SessionStore.get().createSuspendedSession(aUri, true);
// is it enough to set it to false?
Session session = SessionStore.get().createSuspendedSession(aUri, false);
// this needs to be a new session
setFirstPaint(mFocusedWindow, session);
mFocusedWindow.setSession(session, WindowWidget.DEACTIVATE_CURRENT_SESSION);
mFocusedWindow.setKioskMode(true);
Expand Down

0 comments on commit ac98a61

Please sign in to comment.