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

Commit 5cecc09

Browse files
keianhzobluemarvin
andauthored
Restore library panels (#2639)
Co-authored-by: Randall E. Barker <simstorm@mac.com>
1 parent 6d038c9 commit 5cecc09

4 files changed

Lines changed: 83 additions & 15 deletions

File tree

app/src/common/shared/org/mozilla/vrbrowser/browser/engine/Session.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,10 @@ public void onCanGoForward(@NonNull GeckoSession aSession, boolean aCanGoForward
942942
}
943943
}
944944

945+
if (UrlUtils.isAboutPage(aRequest.uri)) {
946+
return GeckoResult.DENY;
947+
}
948+
945949
return result;
946950
}
947951

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import org.mozilla.vrbrowser.ui.widgets.menus.ContextMenuWidget;
6161
import org.mozilla.vrbrowser.ui.widgets.menus.LibraryMenuWidget;
6262
import org.mozilla.vrbrowser.utils.StringUtils;
63+
import org.mozilla.vrbrowser.utils.UrlUtils;
6364
import org.mozilla.vrbrowser.utils.ViewUtils;
6465

6566
import java.util.Arrays;
@@ -439,11 +440,11 @@ public void switchBookmarks() {
439440
}
440441
}
441442

442-
public void showBookmarks() {
443+
private void showBookmarks() {
443444
showBookmarks(true);
444445
}
445446

446-
public void showBookmarks(boolean switchSurface) {
447+
private void showBookmarks(boolean switchSurface) {
447448
if (mView == null) {
448449
setView(mBookmarksView, switchSurface);
449450
mBookmarksView.onShow();
@@ -456,7 +457,7 @@ public void hideBookmarks() {
456457
hideBookmarks(true);
457458
}
458459

459-
public void hideBookmarks(boolean switchSurface) {
460+
private void hideBookmarks(boolean switchSurface) {
460461
if (mView != null) {
461462
unsetView(mBookmarksView, switchSurface);
462463
mViewModel.setIsBookmarksVisible(false);
@@ -485,11 +486,11 @@ private void hideLibraryPanels() {
485486
}
486487
}
487488

488-
public void showHistory() {
489+
private void showHistory() {
489490
showHistory(true);
490491
}
491492

492-
public void showHistory(boolean switchSurface) {
493+
private void showHistory(boolean switchSurface) {
493494
if (mView == null) {
494495
setView(mHistoryView, switchSurface);
495496
mHistoryView.onShow();
@@ -1555,14 +1556,6 @@ public void onPlaybackStateChange(@NonNull MediaElement mediaElement, int state)
15551556
public void onPageStart(@NonNull GeckoSession geckoSession, @NonNull String aUri) {
15561557
mCaptureOnPageStop = true;
15571558

1558-
if (isHistoryVisible()) {
1559-
hideHistory();
1560-
}
1561-
1562-
if (isBookmarksVisible()) {
1563-
hideBookmarks();
1564-
}
1565-
15661559
mViewModel.setUrl(aUri);
15671560
mViewModel.setIsLoading(true);
15681561
}
@@ -1611,6 +1604,18 @@ public void onCanGoForward(@NonNull GeckoSession geckoSession, boolean canGoForw
16111604
final GeckoResult<AllowOrDeny> result = new GeckoResult<>();
16121605

16131606
Uri uri = Uri.parse(aRequest.uri);
1607+
if (UrlUtils.isAboutPage(uri.toString())) {
1608+
if(UrlUtils.isBookmarksUrl(uri.toString())) {
1609+
showBookmarks();
1610+
1611+
} else if (UrlUtils.isHistoryUrl(uri.toString())) {
1612+
showHistory();
1613+
1614+
} else {
1615+
hideLibraryPanels();
1616+
}
1617+
}
1618+
16141619
if ("file".equalsIgnoreCase(uri.getScheme()) &&
16151620
!mWidgetManager.isPermissionGranted(android.Manifest.permission.READ_EXTERNAL_STORAGE)) {
16161621
mWidgetManager.requestPermission(

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.mozilla.vrbrowser.utils.BitmapCache;
2828
import org.mozilla.vrbrowser.utils.ConnectivityReceiver;
2929
import org.mozilla.vrbrowser.utils.SystemUtils;
30+
import org.mozilla.vrbrowser.utils.UrlUtils;
3031

3132
import java.io.File;
3233
import java.io.FileReader;
@@ -65,6 +66,7 @@ class WindowState {
6566
int textureHeight;
6667
float worldWidth;
6768
int tabIndex = -1;
69+
PanelType panelType;
6870

6971
public void load(WindowWidget aWindow, WindowsState aState, int aTabIndex) {
7072
WidgetPlacement widgetPlacement;
@@ -83,6 +85,13 @@ public void load(WindowWidget aWindow, WindowsState aState, int aTabIndex) {
8385
textureHeight = widgetPlacement.height;
8486
worldWidth = widgetPlacement.worldWidth;
8587
tabIndex = aTabIndex;
88+
if (aWindow.isBookmarksVisible()) {
89+
panelType = PanelType.BOOKMARKS;
90+
} else if (aWindow.isHistoryVisible()) {
91+
panelType = PanelType.HISTORY;
92+
} else {
93+
panelType = PanelType.NONE;
94+
}
8695
}
8796
}
8897

@@ -113,6 +122,12 @@ class WindowsState {
113122
private Services mServices;
114123
private PromptDialogWidget mNoInternetDialog;
115124

125+
private enum PanelType {
126+
NONE,
127+
BOOKMARKS,
128+
HISTORY
129+
}
130+
116131
public enum WindowPlacement{
117132
FRONT(0),
118133
LEFT(1),
@@ -280,6 +295,16 @@ private WindowWidget addRestoredWindow(@NonNull WindowState aState, @NonNull Ses
280295
newWindow.getPlacement().worldWidth = aState.worldWidth;
281296
newWindow.setRestored(true);
282297
placeWindow(newWindow, aState.placement);
298+
if (aState.panelType != null) {
299+
switch (aState.panelType) {
300+
case BOOKMARKS:
301+
newWindow.getSession().loadUri(UrlUtils.ABOUT_BOOKMARKS);
302+
break;
303+
case HISTORY:
304+
newWindow.getSession().loadUri(UrlUtils.ABOUT_HISTORY);
305+
break;
306+
}
307+
}
283308
updateCurvedMode(true);
284309

285310
mWidgetManager.addWidget(newWindow);
@@ -873,11 +898,11 @@ public void onAuthenticated(@NonNull OAuthAccount oAuthAccount, @NonNull AuthTyp
873898

874899
switch (mAccounts.getLoginOrigin()) {
875900
case BOOKMARKS:
876-
getFocusedWindow().showBookmarks();
901+
mFocusedWindow.getSession().loadUri(UrlUtils.ABOUT_BOOKMARKS);
877902
break;
878903

879904
case HISTORY:
880-
getFocusedWindow().showHistory();
905+
mFocusedWindow.getSession().loadUri(UrlUtils.ABOUT_HISTORY);
881906
break;
882907

883908
case SETTINGS:

app/src/common/shared/org/mozilla/vrbrowser/utils/UrlUtils.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,38 @@ public static String titleBarUrl(@Nullable String aUri) {
115115
return aUri;
116116
}
117117
}
118+
119+
public static final String ABOUT_HISTORY = "about://history";
120+
121+
public static boolean isHistoryUrl(@Nullable String url) {
122+
if (url == null) {
123+
return false;
124+
}
125+
126+
return url.equalsIgnoreCase(ABOUT_HISTORY);
127+
}
128+
129+
public static final String ABOUT_BOOKMARKS = "about://bookmarks";
130+
131+
public static boolean isBookmarksUrl(@Nullable String url) {
132+
if (url == null) {
133+
return false;
134+
}
135+
136+
return url.equalsIgnoreCase(ABOUT_BOOKMARKS);
137+
}
138+
139+
public static final String ABOUT_PRIVATE = "about://privatebrowsing";
140+
141+
public static boolean isPrivateUrl(@Nullable String url) {
142+
if (url == null) {
143+
return false;
144+
}
145+
146+
return url.equalsIgnoreCase(ABOUT_PRIVATE);
147+
}
148+
149+
public static boolean isAboutPage(@Nullable String url) {
150+
return isHistoryUrl(url) || isBookmarksUrl(url) || isPrivateUrl(url);
151+
}
118152
}

0 commit comments

Comments
 (0)