Skip to content

Commit

Permalink
Enable going forward from new tab
Browse files Browse the repository at this point in the history
  • Loading branch information
haanhvu committed Dec 3, 2024
1 parent f5b12a5 commit d89daeb
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.igalia.wolvic.browser.api.impl;

import androidx.annotation.Nullable;

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

import org.chromium.content_public.browser.WebContents;

import org.chromium.components.browser_ui.media.MediaImageManager;
import org.jni_zero.JNINamespace;
import org.chromium.components.find_in_page;

public class SessionFinderImpl implements WSession.SessionFinder {

private WebContents mWebContents;

@Override
public WResult<FinderResult> find(@Nullable String searchString, int flags) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class WindowViewModel extends AndroidViewModel {
private MutableLiveData<ObservableBoolean> isPopUpAvailable;
private MutableLiveData<ObservableBoolean> isPopUpBlocked;
private MutableLiveData<ObservableBoolean> canGoForward;
private MutableLiveData<ObservableBoolean> canGoForwardFromNewTab;
private MutableLiveData<ObservableBoolean> canGoBack;
private MutableLiveData<ObservableBoolean> isInVRVideo;
private MutableLiveData<ObservableBoolean> autoEnteredVRVideo;
Expand Down Expand Up @@ -154,6 +155,7 @@ public WindowViewModel(Application application) {
isPopUpAvailable = new MutableLiveData<>(new ObservableBoolean(false));
isPopUpBlocked = new MutableLiveData<>(new ObservableBoolean(false));
canGoForward = new MutableLiveData<>(new ObservableBoolean(false));
canGoForwardFromNewTab = new MutableLiveData<>(new ObservableBoolean(false));
canGoBack = new MutableLiveData<>(new ObservableBoolean(false));
isInVRVideo = new MutableLiveData<>(new ObservableBoolean(false));
autoEnteredVRVideo = new MutableLiveData<>(new ObservableBoolean(false));
Expand Down Expand Up @@ -359,6 +361,7 @@ public void refresh() {
isPopUpAvailable.postValue(isPopUpAvailable.getValue());
isPopUpBlocked.postValue(isPopUpBlocked.getValue());
canGoForward.postValue(canGoForward.getValue());
canGoForwardFromNewTab.postValue(canGoForwardFromNewTab.getValue());
canGoBack.postValue(canGoBack.getValue());
isInVRVideo.postValue(isInVRVideo.getValue());
autoEnteredVRVideo.postValue(autoEnteredVRVideo.getValue());
Expand Down Expand Up @@ -697,6 +700,15 @@ public void setCanGoForward(boolean canGoForward) {
this.canGoForward.postValue(new ObservableBoolean(canGoForward));
}

@NonNull
public MutableLiveData<ObservableBoolean> getCanGoForwardFromNewTab() {
return canGoForwardFromNewTab;
}

public void setCanGoForwardFromNewTab(boolean canGoForwardFromNewTab) {
this.canGoForwardFromNewTab.postValue(new ObservableBoolean(canGoForwardFromNewTab));
}

@NonNull
public MutableLiveData<ObservableBoolean> getCanGoBack() {
return canGoBack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ private void updateUI() {

mBinding.navigationBarNavigation.forwardButton.setOnClickListener(v -> {
v.requestFocusFromTouch();
if (mViewModel.getCanGoForwardFromNewTab().getValue().get()) {
getSession().loadUri(mAttachedWindow.uriForwardFromNewTab);
mViewModel.setCanGoForwardFromNewTab(false);
}
getSession().goForward();
if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.CLICK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public class WindowWidget extends UIWidget implements SessionChangeListener,
private SharedPreferences mPrefs;
private DownloadsManager mDownloadsManager;
private float mBrowserDensity;
public String uriForwardFromNewTab;

public interface WindowListener {
default void onFocusRequest(@NonNull WindowWidget aWindow) {}
Expand Down Expand Up @@ -558,7 +559,6 @@ public void showNewTab() {
mViewModel.setIsFindInPage(false);
mViewModel.setCurrentContentType(Windows.ContentType.NEW_TAB);
mViewModel.setUrl(Windows.ContentType.NEW_TAB.URL);
mViewModel.enableBackToNewTab(false);
setView(mNewTab, true);
if (mRestoreFirstPaint == null) {
onFirstContentfulPaint(mSession.getWSession());
Expand All @@ -574,6 +574,10 @@ public void showNewTab() {
};
}
}
if (mViewModel.getBackToNewTabEnabled().getValue().get()) {
mViewModel.enableBackToNewTab(false);
mViewModel.setCanGoForwardFromNewTab(true);
}
}

public void hidePanel() {
Expand Down Expand Up @@ -2076,6 +2080,9 @@ WResult<WAllowOrDeny> onLoadRequest(WSession aSession, @NonNull LoadRequest aReq
hideNewTab();
mViewModel.setCurrentContentType(Windows.ContentType.WEB_CONTENT);
mViewModel.setUrl(uri.toString());
if (mViewModel.lastContentType.getValue() == Windows.ContentType.NEW_TAB) {
uriForwardFromNewTab = uri.toString();
}
}

if ("file".equalsIgnoreCase(uri.getScheme())) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/navigation_bar_navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
android:layout_weight="0"
android:src="@drawable/ic_icon_forward"
android:tooltipText="@string/forward_tooltip"
android:enabled="@{viewmodel.canGoForward}"
android:enabled="@{viewmodel.canGoForward || viewmodel.canGoForwardFromNewTab}"
app:privateMode="@{viewmodel.isPrivateSession}"/>

<RelativeLayout
Expand Down

0 comments on commit d89daeb

Please sign in to comment.