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

Commit

Permalink
Restore library panels (#2639)
Browse files Browse the repository at this point in the history
Co-authored-by: Randall E. Barker <[email protected]>
  • Loading branch information
keianhzo and bluemarvin authored Feb 11, 2020
1 parent 6d038c9 commit 5cecc09
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,10 @@ public void onCanGoForward(@NonNull GeckoSession aSession, boolean aCanGoForward
}
}

if (UrlUtils.isAboutPage(aRequest.uri)) {
return GeckoResult.DENY;
}

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.mozilla.vrbrowser.ui.widgets.menus.ContextMenuWidget;
import org.mozilla.vrbrowser.ui.widgets.menus.LibraryMenuWidget;
import org.mozilla.vrbrowser.utils.StringUtils;
import org.mozilla.vrbrowser.utils.UrlUtils;
import org.mozilla.vrbrowser.utils.ViewUtils;

import java.util.Arrays;
Expand Down Expand Up @@ -439,11 +440,11 @@ public void switchBookmarks() {
}
}

public void showBookmarks() {
private void showBookmarks() {
showBookmarks(true);
}

public void showBookmarks(boolean switchSurface) {
private void showBookmarks(boolean switchSurface) {
if (mView == null) {
setView(mBookmarksView, switchSurface);
mBookmarksView.onShow();
Expand All @@ -456,7 +457,7 @@ public void hideBookmarks() {
hideBookmarks(true);
}

public void hideBookmarks(boolean switchSurface) {
private void hideBookmarks(boolean switchSurface) {
if (mView != null) {
unsetView(mBookmarksView, switchSurface);
mViewModel.setIsBookmarksVisible(false);
Expand Down Expand Up @@ -485,11 +486,11 @@ private void hideLibraryPanels() {
}
}

public void showHistory() {
private void showHistory() {
showHistory(true);
}

public void showHistory(boolean switchSurface) {
private void showHistory(boolean switchSurface) {
if (mView == null) {
setView(mHistoryView, switchSurface);
mHistoryView.onShow();
Expand Down Expand Up @@ -1555,14 +1556,6 @@ public void onPlaybackStateChange(@NonNull MediaElement mediaElement, int state)
public void onPageStart(@NonNull GeckoSession geckoSession, @NonNull String aUri) {
mCaptureOnPageStop = true;

if (isHistoryVisible()) {
hideHistory();
}

if (isBookmarksVisible()) {
hideBookmarks();
}

mViewModel.setUrl(aUri);
mViewModel.setIsLoading(true);
}
Expand Down Expand Up @@ -1611,6 +1604,18 @@ public void onCanGoForward(@NonNull GeckoSession geckoSession, boolean canGoForw
final GeckoResult<AllowOrDeny> result = new GeckoResult<>();

Uri uri = Uri.parse(aRequest.uri);
if (UrlUtils.isAboutPage(uri.toString())) {
if(UrlUtils.isBookmarksUrl(uri.toString())) {
showBookmarks();

} else if (UrlUtils.isHistoryUrl(uri.toString())) {
showHistory();

} else {
hideLibraryPanels();
}
}

if ("file".equalsIgnoreCase(uri.getScheme()) &&
!mWidgetManager.isPermissionGranted(android.Manifest.permission.READ_EXTERNAL_STORAGE)) {
mWidgetManager.requestPermission(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.mozilla.vrbrowser.utils.BitmapCache;
import org.mozilla.vrbrowser.utils.ConnectivityReceiver;
import org.mozilla.vrbrowser.utils.SystemUtils;
import org.mozilla.vrbrowser.utils.UrlUtils;

import java.io.File;
import java.io.FileReader;
Expand Down Expand Up @@ -65,6 +66,7 @@ class WindowState {
int textureHeight;
float worldWidth;
int tabIndex = -1;
PanelType panelType;

public void load(WindowWidget aWindow, WindowsState aState, int aTabIndex) {
WidgetPlacement widgetPlacement;
Expand All @@ -83,6 +85,13 @@ public void load(WindowWidget aWindow, WindowsState aState, int aTabIndex) {
textureHeight = widgetPlacement.height;
worldWidth = widgetPlacement.worldWidth;
tabIndex = aTabIndex;
if (aWindow.isBookmarksVisible()) {
panelType = PanelType.BOOKMARKS;
} else if (aWindow.isHistoryVisible()) {
panelType = PanelType.HISTORY;
} else {
panelType = PanelType.NONE;
}
}
}

Expand Down Expand Up @@ -113,6 +122,12 @@ class WindowsState {
private Services mServices;
private PromptDialogWidget mNoInternetDialog;

private enum PanelType {
NONE,
BOOKMARKS,
HISTORY
}

public enum WindowPlacement{
FRONT(0),
LEFT(1),
Expand Down Expand Up @@ -280,6 +295,16 @@ private WindowWidget addRestoredWindow(@NonNull WindowState aState, @NonNull Ses
newWindow.getPlacement().worldWidth = aState.worldWidth;
newWindow.setRestored(true);
placeWindow(newWindow, aState.placement);
if (aState.panelType != null) {
switch (aState.panelType) {
case BOOKMARKS:
newWindow.getSession().loadUri(UrlUtils.ABOUT_BOOKMARKS);
break;
case HISTORY:
newWindow.getSession().loadUri(UrlUtils.ABOUT_HISTORY);
break;
}
}
updateCurvedMode(true);

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

switch (mAccounts.getLoginOrigin()) {
case BOOKMARKS:
getFocusedWindow().showBookmarks();
mFocusedWindow.getSession().loadUri(UrlUtils.ABOUT_BOOKMARKS);
break;

case HISTORY:
getFocusedWindow().showHistory();
mFocusedWindow.getSession().loadUri(UrlUtils.ABOUT_HISTORY);
break;

case SETTINGS:
Expand Down
34 changes: 34 additions & 0 deletions app/src/common/shared/org/mozilla/vrbrowser/utils/UrlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,38 @@ public static String titleBarUrl(@Nullable String aUri) {
return aUri;
}
}

public static final String ABOUT_HISTORY = "about://history";

public static boolean isHistoryUrl(@Nullable String url) {
if (url == null) {
return false;
}

return url.equalsIgnoreCase(ABOUT_HISTORY);
}

public static final String ABOUT_BOOKMARKS = "about://bookmarks";

public static boolean isBookmarksUrl(@Nullable String url) {
if (url == null) {
return false;
}

return url.equalsIgnoreCase(ABOUT_BOOKMARKS);
}

public static final String ABOUT_PRIVATE = "about://privatebrowsing";

public static boolean isPrivateUrl(@Nullable String url) {
if (url == null) {
return false;
}

return url.equalsIgnoreCase(ABOUT_PRIVATE);
}

public static boolean isAboutPage(@Nullable String url) {
return isHistoryUrl(url) || isBookmarksUrl(url) || isPrivateUrl(url);
}
}

0 comments on commit 5cecc09

Please sign in to comment.