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

Commit

Permalink
Tabs implementation (#2051)
Browse files Browse the repository at this point in the history
* Tabs implementation (#1963)

Merging and opening issues for the above after talking to @MortimerGoro 

* Tabs implementation

* Refactor session restore code. Fix nits.

* Rename isComposited method

* Fix potential NullPointerException crash when focus changed after a the TabWidget is released without hiding it before

* Update session last use when changing active windows

* Correctly sync tabs after closing

* Close the TabsWidget when the active window changes.

* Tabs polish (#2028)

* Tabs UI polish

* Set correct tab title for contend feed

* Correctly handle onNewSession (e.g window.open())

* Fix onDestroy crash

* Implement BitmapCache for tab snapshots

* Use a single instance of TabWidget. Improve dismiss detection.

* Add open new tab notificaion and context menu action.

* Dispatch BitmapCache callbacks on the Main Thread. Scale bitmaps before saving them to disk.

* Tab UI polish

* Get rid of max window error alert. Update tabs tray dialog

* Fix rebase issue
  • Loading branch information
MortimerGoro authored and keianhzo committed Oct 24, 2019
1 parent 6870f1b commit 940479a
Show file tree
Hide file tree
Showing 64 changed files with 3,414 additions and 1,877 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@ dependencies {
// SQLite helper to handle DBs from assets
implementation deps.sqlite.sqlite

// DiskLRUCache used to cache snapshots
implementation deps.disklrucache.disklrucache

// Testing
testImplementation deps.junit
androidTestImplementation deps.atsl.runner
Expand Down
62 changes: 35 additions & 27 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
import org.mozilla.vrbrowser.audio.AudioEngine;
import org.mozilla.vrbrowser.browser.PermissionDelegate;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.browser.engine.Session;
import org.mozilla.vrbrowser.browser.engine.SessionStore;
import org.mozilla.vrbrowser.browser.engine.SessionStack;
import org.mozilla.vrbrowser.crashreporting.CrashReporterService;
import org.mozilla.vrbrowser.crashreporting.GlobalExceptionHandler;
import org.mozilla.vrbrowser.geolocation.GeolocationWrapper;
Expand Down Expand Up @@ -271,6 +271,7 @@ protected void initializeWidgets() {
@Override
public void onFocusedWindowChanged(@NonNull WindowWidget aFocusedWindow, @Nullable WindowWidget aPrevFocusedWindow) {
attachToWindow(aFocusedWindow, aPrevFocusedWindow);
mTray.setAddWindowVisible(mWindows.canOpenNewWindow());
}
@Override
public void onWindowBorderChanged(@NonNull WindowWidget aChangeWindow) {
Expand All @@ -284,6 +285,7 @@ public void onWindowsMoved() {

@Override
public void onWindowClosed() {
mTray.setAddWindowVisible(mWindows.canOpenNewWindow());
updateWidget(mTray);
}
});
Expand All @@ -307,6 +309,7 @@ public void onWindowClosed() {

// Add widget listeners
mTray.addListeners(mWindows);
mTray.setAddWindowVisible(mWindows.canOpenNewWindow());

attachToWindow(mWindows.getFocusedWindow(), null);

Expand Down Expand Up @@ -449,7 +452,7 @@ void loadFromIntent(final Intent intent) {
uri = Uri.parse(intent.getExtras().getString("url"));
}

SessionStack activeStore = SessionStore.get().getActiveStore();
Session activeSession = SessionStore.get().getActiveSession();

Bundle extras = intent.getExtras();
if (extras != null && extras.containsKey("homepage")) {
Expand All @@ -465,16 +468,10 @@ void loadFromIntent(final Intent intent) {
}
}

if (activeStore != null) {
if (activeStore.getCurrentSession() == null) {
String url = (uri != null ? uri.toString() : null);
activeStore.newSessionWithUrl(url);
Log.d(LOGTAG, "Creating session and loading URI from intent: " + url);

} else if (uri != null) {
if (activeSession != null) {
if (uri != null) {
Log.d(LOGTAG, "Loading URI from intent: " + uri.toString());
activeStore.loadUri(uri.toString());

activeSession.loadUri(uri.toString());
} else {
mWindows.getFocusedWindow().loadHomeIfNotRestored();
}
Expand Down Expand Up @@ -682,8 +679,8 @@ void dispatchCreateWidget(final int aHandle, final SurfaceTexture aTexture, fina
Log.d(LOGTAG, "Widget: " + aHandle + " (" + aWidth + "x" + aHeight + ") received a null surface texture.");
} else {
Runnable aFirstDrawCallback = () -> {
if (!widget.getFirstDraw()) {
widget.setFirstDraw(true);
if (!widget.isFirstPaintReady()) {
widget.setFirstPaintReady(true);
updateWidget(widget);
}
};
Expand Down Expand Up @@ -711,8 +708,8 @@ void dispatchCreateWidgetLayer(final int aHandle, final Surface aSurface, final
if (aNativeCallback != 0) {
queueRunnable(() -> runCallbackNative(aNativeCallback));
}
if (aSurface != null && !widget.getFirstDraw()) {
widget.setFirstDraw(true);
if (aSurface != null && !widget.isFirstPaintReady()) {
widget.setFirstPaintReady(true);
updateWidget(widget);
}
};
Expand Down Expand Up @@ -779,12 +776,12 @@ void handleGesture(final int aType) {
boolean consumed = false;
if ((aType == GestureSwipeLeft) && (mLastGesture == GestureSwipeLeft)) {
Log.d(LOGTAG, "Go back!");
SessionStore.get().getActiveStore().goBack();
SessionStore.get().getActiveSession().goBack();

consumed = true;
} else if ((aType == GestureSwipeRight) && (mLastGesture == GestureSwipeRight)) {
Log.d(LOGTAG, "Go forward!");
SessionStore.get().getActiveStore().goForward();
SessionStore.get().getActiveSession().goForward();
consumed = true;
}
if (mLastRunnable != null) {
Expand Down Expand Up @@ -1004,18 +1001,18 @@ private void handlePoorPerformance() {
if (window == null) {
return;
}
final String originalUrl = window.getSessionStack().getCurrentUri();
if (mPoorPerformanceWhiteList.contains(originalUrl)) {
final String originalUri = window.getSession().getCurrentUri();
if (mPoorPerformanceWhiteList.contains(originalUri)) {
return;
}
window.getSessionStack().loadHomePage();
window.getSession().loadHomePage();
final String[] buttons = {getString(R.string.ok_button), getString(R.string.performance_unblock_page)};
window.showButtonPrompt(getString(R.string.performance_title), getString(R.string.performance_message), buttons, new ConfirmPromptWidget.ConfirmPromptDelegate() {
@Override
public void confirm(int index) {
if (index == GeckoSession.PromptDelegate.ButtonPrompt.Type.NEGATIVE) {
mPoorPerformanceWhiteList.add(originalUrl);
window.getSessionStack().loadUri(originalUrl);
mPoorPerformanceWhiteList.add(originalUri);
window.getSession().loadUri(originalUri);
}
}

Expand Down Expand Up @@ -1135,7 +1132,7 @@ public void updateWidget(final Widget aWidget) {
public void removeWidget(final Widget aWidget) {
mWidgets.remove(aWidget.getHandle());
mWidgetContainer.removeView((View) aWidget);
aWidget.setFirstDraw(false);
aWidget.setFirstPaintReady(false);
queueRunnable(() -> removeWidgetNative(aWidget.getHandle()));
if (aWidget == mActiveDialog) {
mActiveDialog = null;
Expand Down Expand Up @@ -1326,11 +1323,11 @@ public boolean isPermissionGranted(@NonNull String permission) {

@Override
public void requestPermission(String uri, @NonNull String permission, GeckoSession.PermissionDelegate.Callback aCallback) {
SessionStack activeStore = SessionStore.get().getActiveStore();
Session session = SessionStore.get().getActiveSession();
if (uri != null && !uri.isEmpty()) {
mPermissionDelegate.onAppPermissionRequest(activeStore.getCurrentSession(), uri, permission, aCallback);
mPermissionDelegate.onAppPermissionRequest(session.getGeckoSession(), uri, permission, aCallback);
} else {
mPermissionDelegate.onAndroidPermissionsRequest(activeStore.getCurrentSession(), new String[]{permission}, aCallback);
mPermissionDelegate.onAndroidPermissionsRequest(session.getGeckoSession(), new String[]{permission}, aCallback);
}
}

Expand Down Expand Up @@ -1382,14 +1379,25 @@ public void setCPULevel(int aCPULevel) {
queueRunnable(() -> setCPULevelNative(aCPULevel));
}

@Override
public boolean canOpenNewWindow() {
return mWindows.canOpenNewWindow();
}

@Override
public void openNewWindow(String uri) {
WindowWidget newWindow = mWindows.addWindow();
if (newWindow != null) {
newWindow.getSessionStack().newSessionWithUrl(uri);
newWindow.getSession().loadUri(uri);
}
}

@Override
public void openNewTab(@NonNull String uri) {
mWindows.addBackgroundTab(mWindows.getFocusedWindow(), uri);
mTray.showTabAddedNotification();
}

@Override
public WindowWidget getFocusedWindow() {
return mWindows.getFocusedWindow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
import org.mozilla.vrbrowser.db.AppDatabase;
import org.mozilla.vrbrowser.db.DataRepository;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.utils.BitmapCache;
import org.mozilla.vrbrowser.utils.LocaleUtils;

public class VRBrowserApplication extends Application {

private AppExecutors mAppExecutors;
private BitmapCache mBitmapCache;
private Places mPlaces;

@Override
Expand All @@ -26,6 +28,7 @@ public void onCreate() {

mAppExecutors = new AppExecutors();
mPlaces = new Places(this);
mBitmapCache = new BitmapCache(this, mAppExecutors.diskIO(), mAppExecutors.mainThread());

TelemetryWrapper.init(this);
}
Expand Down Expand Up @@ -57,4 +60,8 @@ public AppExecutors getExecutors() {
public DataRepository getRepository() {
return DataRepository.getInstance(getDatabase(), mAppExecutors);
}

public BitmapCache getBitmapCache() {
return mBitmapCache;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void attachToWindow(@NonNull WindowWidget window) {
detachFromWindow();

mAttachedWindow = window;
mAttachedWindow.getSessionStack().setPromptDelegate(this);
mAttachedWindow.getSession().setPromptDelegate(this);
mViewModel.getAll().observeForever(mObserver);
}

Expand Down Expand Up @@ -215,9 +215,8 @@ public GeckoResult<PromptResponse> onPopupPrompt(@NonNull GeckoSession geckoSess

if (!SettingsStore.getInstance(mContext).isPopUpsBlockingEnabled()) {
result.complete(popupPrompt.confirm(AllowOrDeny.ALLOW));

} else {
String uri = mAttachedWindow.getSessionStack().getUriFromSession(geckoSession);
String uri = mAttachedWindow.getSession().getCurrentUri();
PopUpRequest request = PopUpRequest.newRequest(uri, popupPrompt, result);
handlePopUpRequest(request);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.mozilla.vrbrowser.browser;

import org.mozilla.geckoview.GeckoSession;
import org.mozilla.vrbrowser.browser.engine.Session;

public interface SessionChangeListener {
default void onNewSession(GeckoSession aSession, int aId) {};
default void onRemoveSession(GeckoSession aSession, int aId) {};
default void onCurrentSessionChange(GeckoSession aSession, int aId) {};
default void onNewSession(GeckoSession aSession) {};
default void onRemoveSession(GeckoSession aSession) {};
default void onCurrentSessionChange(GeckoSession aOldSession, GeckoSession aSession) {};
default void onNewTab(Session aTab) {};
}
Loading

0 comments on commit 940479a

Please sign in to comment.