Skip to content

Commit

Permalink
[Chromium] Implement form repost warning dialog
Browse files Browse the repository at this point in the history
Show form repost warning dialog by using the corresponding Chromium
method in TabWebContentsDelegate.java.
  • Loading branch information
zakharvoit committed Dec 11, 2023
1 parent 2db9bdf commit e439b5f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.chromium.wolvic.UserDialogManagerBridge;

import com.igalia.wolvic.browser.api.WAllowOrDeny;
import com.igalia.wolvic.browser.api.WResult;
import com.igalia.wolvic.browser.api.WSession;

import java.util.ArrayList;
Expand All @@ -23,9 +24,13 @@ class PromptDelegateImpl implements UserDialogManagerBridge.Delegate {
private final WSession.PromptDelegate mDelegate;
private final SessionImpl mSession;

private static class PromptResponseImpl implements WSession.PromptDelegate.PromptResponse {
public static class PromptResponseImpl implements WSession.PromptDelegate.PromptResponse {
public PromptResponseImpl() {
}

public WAllowOrDeny allowOrDeny() {
return WAllowOrDeny.DENY;
}
}

public PromptDelegateImpl(WSession.PromptDelegate mDelegate, SessionImpl mSession) {
Expand Down Expand Up @@ -60,6 +65,10 @@ public void onBeforeUnloadDialog(UserDialogManagerBridge.DialogCallback dialogCa
mDelegate.onBeforeUnloadPrompt(mSession, new BeforeUnloadPrompt(dialogCallback));
}

public WResult<PromptResponseImpl> onRepostConfirmWarningDialog() {
return mDelegate.onRepostConfirmPrompt(mSession, new RepostConfirmPrompt()).then(result -> WResult.fromValue((PromptResponseImpl) result));
}

public static class BasePromptImpl implements WSession.PromptDelegate.BasePrompt {
private WSession.PromptDelegate.PromptInstanceDelegate mDelegate;
protected boolean mIsCompleted;
Expand Down Expand Up @@ -208,6 +217,19 @@ public WSession.PromptDelegate.PromptResponse confirm(@Nullable WAllowOrDeny all
}
}

private static class RepostConfirmPrompt extends BasePromptImpl implements WSession.PromptDelegate.RepostConfirmPrompt {
@NonNull
@Override
public WSession.PromptDelegate.PromptResponse confirm(@Nullable WAllowOrDeny allowOrDeny) {
return new PromptResponseImpl() {
@Override
public WAllowOrDeny allowOrDeny() {
return allowOrDeny;
}
};
}
}

public class SelectPopupFactory implements SelectPopup.Factory {
public SelectPopup.Ui create(Context windowContext, Callback<int[]> selectionChangedCallback,
List<SelectPopupItem> items, boolean multiple, int[] selected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,11 @@ public PromptDelegate getPromptDelegate() {
return mPromptDelegate == null ? null : mPromptDelegate.getDelegate();
}

@Nullable
public PromptDelegateImpl getChromiumPromptDelegate() {
return mPromptDelegate;
}

@Override
public void setSelectionActionDelegate(@Nullable SelectionActionDelegate delegate) {
// TODO: Implement bridge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.igalia.wolvic.browser.api.WAllowOrDeny;
import com.igalia.wolvic.browser.api.WResult;
import com.igalia.wolvic.browser.api.WSession;

import org.chromium.base.task.PostTask;
Expand Down Expand Up @@ -117,4 +119,16 @@ public void onUpdateUrl(GURL url) {
delegate.onLocationChange(mSession, mWebContents.getVisibleUrl().getSpec());
}
}

@Override
public void showRepostFormWarningDialog() {
mSession.getChromiumPromptDelegate().onRepostConfirmWarningDialog().then(result -> {
if (result.allowOrDeny() == WAllowOrDeny.ALLOW) {
mWebContents.getNavigationController().continuePendingReload();
} else {
mWebContents.getNavigationController().cancelPendingReload();
}
return WResult.fromValue(null);
});
}
}

0 comments on commit e439b5f

Please sign in to comment.