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

Commit 940479a

Browse files
MortimerGorokeianhzo
authored andcommitted
Tabs implementation (#2051)
* 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
1 parent 6870f1b commit 940479a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+3414
-1877
lines changed

app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,9 @@ dependencies {
455455
// SQLite helper to handle DBs from assets
456456
implementation deps.sqlite.sqlite
457457

458+
// DiskLRUCache used to cache snapshots
459+
implementation deps.disklrucache.disklrucache
460+
458461
// Testing
459462
testImplementation deps.junit
460463
androidTestImplementation deps.atsl.runner

app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
import org.mozilla.vrbrowser.audio.AudioEngine;
4545
import org.mozilla.vrbrowser.browser.PermissionDelegate;
4646
import org.mozilla.vrbrowser.browser.SettingsStore;
47+
import org.mozilla.vrbrowser.browser.engine.Session;
4748
import org.mozilla.vrbrowser.browser.engine.SessionStore;
48-
import org.mozilla.vrbrowser.browser.engine.SessionStack;
4949
import org.mozilla.vrbrowser.crashreporting.CrashReporterService;
5050
import org.mozilla.vrbrowser.crashreporting.GlobalExceptionHandler;
5151
import org.mozilla.vrbrowser.geolocation.GeolocationWrapper;
@@ -271,6 +271,7 @@ protected void initializeWidgets() {
271271
@Override
272272
public void onFocusedWindowChanged(@NonNull WindowWidget aFocusedWindow, @Nullable WindowWidget aPrevFocusedWindow) {
273273
attachToWindow(aFocusedWindow, aPrevFocusedWindow);
274+
mTray.setAddWindowVisible(mWindows.canOpenNewWindow());
274275
}
275276
@Override
276277
public void onWindowBorderChanged(@NonNull WindowWidget aChangeWindow) {
@@ -284,6 +285,7 @@ public void onWindowsMoved() {
284285

285286
@Override
286287
public void onWindowClosed() {
288+
mTray.setAddWindowVisible(mWindows.canOpenNewWindow());
287289
updateWidget(mTray);
288290
}
289291
});
@@ -307,6 +309,7 @@ public void onWindowClosed() {
307309

308310
// Add widget listeners
309311
mTray.addListeners(mWindows);
312+
mTray.setAddWindowVisible(mWindows.canOpenNewWindow());
310313

311314
attachToWindow(mWindows.getFocusedWindow(), null);
312315

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

452-
SessionStack activeStore = SessionStore.get().getActiveStore();
455+
Session activeSession = SessionStore.get().getActiveSession();
453456

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

468-
if (activeStore != null) {
469-
if (activeStore.getCurrentSession() == null) {
470-
String url = (uri != null ? uri.toString() : null);
471-
activeStore.newSessionWithUrl(url);
472-
Log.d(LOGTAG, "Creating session and loading URI from intent: " + url);
473-
474-
} else if (uri != null) {
471+
if (activeSession != null) {
472+
if (uri != null) {
475473
Log.d(LOGTAG, "Loading URI from intent: " + uri.toString());
476-
activeStore.loadUri(uri.toString());
477-
474+
activeSession.loadUri(uri.toString());
478475
} else {
479476
mWindows.getFocusedWindow().loadHomeIfNotRestored();
480477
}
@@ -682,8 +679,8 @@ void dispatchCreateWidget(final int aHandle, final SurfaceTexture aTexture, fina
682679
Log.d(LOGTAG, "Widget: " + aHandle + " (" + aWidth + "x" + aHeight + ") received a null surface texture.");
683680
} else {
684681
Runnable aFirstDrawCallback = () -> {
685-
if (!widget.getFirstDraw()) {
686-
widget.setFirstDraw(true);
682+
if (!widget.isFirstPaintReady()) {
683+
widget.setFirstPaintReady(true);
687684
updateWidget(widget);
688685
}
689686
};
@@ -711,8 +708,8 @@ void dispatchCreateWidgetLayer(final int aHandle, final Surface aSurface, final
711708
if (aNativeCallback != 0) {
712709
queueRunnable(() -> runCallbackNative(aNativeCallback));
713710
}
714-
if (aSurface != null && !widget.getFirstDraw()) {
715-
widget.setFirstDraw(true);
711+
if (aSurface != null && !widget.isFirstPaintReady()) {
712+
widget.setFirstPaintReady(true);
716713
updateWidget(widget);
717714
}
718715
};
@@ -779,12 +776,12 @@ void handleGesture(final int aType) {
779776
boolean consumed = false;
780777
if ((aType == GestureSwipeLeft) && (mLastGesture == GestureSwipeLeft)) {
781778
Log.d(LOGTAG, "Go back!");
782-
SessionStore.get().getActiveStore().goBack();
779+
SessionStore.get().getActiveSession().goBack();
783780

784781
consumed = true;
785782
} else if ((aType == GestureSwipeRight) && (mLastGesture == GestureSwipeRight)) {
786783
Log.d(LOGTAG, "Go forward!");
787-
SessionStore.get().getActiveStore().goForward();
784+
SessionStore.get().getActiveSession().goForward();
788785
consumed = true;
789786
}
790787
if (mLastRunnable != null) {
@@ -1004,18 +1001,18 @@ private void handlePoorPerformance() {
10041001
if (window == null) {
10051002
return;
10061003
}
1007-
final String originalUrl = window.getSessionStack().getCurrentUri();
1008-
if (mPoorPerformanceWhiteList.contains(originalUrl)) {
1004+
final String originalUri = window.getSession().getCurrentUri();
1005+
if (mPoorPerformanceWhiteList.contains(originalUri)) {
10091006
return;
10101007
}
1011-
window.getSessionStack().loadHomePage();
1008+
window.getSession().loadHomePage();
10121009
final String[] buttons = {getString(R.string.ok_button), getString(R.string.performance_unblock_page)};
10131010
window.showButtonPrompt(getString(R.string.performance_title), getString(R.string.performance_message), buttons, new ConfirmPromptWidget.ConfirmPromptDelegate() {
10141011
@Override
10151012
public void confirm(int index) {
10161013
if (index == GeckoSession.PromptDelegate.ButtonPrompt.Type.NEGATIVE) {
1017-
mPoorPerformanceWhiteList.add(originalUrl);
1018-
window.getSessionStack().loadUri(originalUrl);
1014+
mPoorPerformanceWhiteList.add(originalUri);
1015+
window.getSession().loadUri(originalUri);
10191016
}
10201017
}
10211018

@@ -1135,7 +1132,7 @@ public void updateWidget(final Widget aWidget) {
11351132
public void removeWidget(final Widget aWidget) {
11361133
mWidgets.remove(aWidget.getHandle());
11371134
mWidgetContainer.removeView((View) aWidget);
1138-
aWidget.setFirstDraw(false);
1135+
aWidget.setFirstPaintReady(false);
11391136
queueRunnable(() -> removeWidgetNative(aWidget.getHandle()));
11401137
if (aWidget == mActiveDialog) {
11411138
mActiveDialog = null;
@@ -1326,11 +1323,11 @@ public boolean isPermissionGranted(@NonNull String permission) {
13261323

13271324
@Override
13281325
public void requestPermission(String uri, @NonNull String permission, GeckoSession.PermissionDelegate.Callback aCallback) {
1329-
SessionStack activeStore = SessionStore.get().getActiveStore();
1326+
Session session = SessionStore.get().getActiveSession();
13301327
if (uri != null && !uri.isEmpty()) {
1331-
mPermissionDelegate.onAppPermissionRequest(activeStore.getCurrentSession(), uri, permission, aCallback);
1328+
mPermissionDelegate.onAppPermissionRequest(session.getGeckoSession(), uri, permission, aCallback);
13321329
} else {
1333-
mPermissionDelegate.onAndroidPermissionsRequest(activeStore.getCurrentSession(), new String[]{permission}, aCallback);
1330+
mPermissionDelegate.onAndroidPermissionsRequest(session.getGeckoSession(), new String[]{permission}, aCallback);
13341331
}
13351332
}
13361333

@@ -1382,14 +1379,25 @@ public void setCPULevel(int aCPULevel) {
13821379
queueRunnable(() -> setCPULevelNative(aCPULevel));
13831380
}
13841381

1382+
@Override
1383+
public boolean canOpenNewWindow() {
1384+
return mWindows.canOpenNewWindow();
1385+
}
1386+
13851387
@Override
13861388
public void openNewWindow(String uri) {
13871389
WindowWidget newWindow = mWindows.addWindow();
13881390
if (newWindow != null) {
1389-
newWindow.getSessionStack().newSessionWithUrl(uri);
1391+
newWindow.getSession().loadUri(uri);
13901392
}
13911393
}
13921394

1395+
@Override
1396+
public void openNewTab(@NonNull String uri) {
1397+
mWindows.addBackgroundTab(mWindows.getFocusedWindow(), uri);
1398+
mTray.showTabAddedNotification();
1399+
}
1400+
13931401
@Override
13941402
public WindowWidget getFocusedWindow() {
13951403
return mWindows.getFocusedWindow();

app/src/common/shared/org/mozilla/vrbrowser/VRBrowserApplication.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
import org.mozilla.vrbrowser.db.AppDatabase;
1414
import org.mozilla.vrbrowser.db.DataRepository;
1515
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
16+
import org.mozilla.vrbrowser.utils.BitmapCache;
1617
import org.mozilla.vrbrowser.utils.LocaleUtils;
1718

1819
public class VRBrowserApplication extends Application {
1920

2021
private AppExecutors mAppExecutors;
22+
private BitmapCache mBitmapCache;
2123
private Places mPlaces;
2224

2325
@Override
@@ -26,6 +28,7 @@ public void onCreate() {
2628

2729
mAppExecutors = new AppExecutors();
2830
mPlaces = new Places(this);
31+
mBitmapCache = new BitmapCache(this, mAppExecutors.diskIO(), mAppExecutors.mainThread());
2932

3033
TelemetryWrapper.init(this);
3134
}
@@ -57,4 +60,8 @@ public AppExecutors getExecutors() {
5760
public DataRepository getRepository() {
5861
return DataRepository.getInstance(getDatabase(), mAppExecutors);
5962
}
63+
64+
public BitmapCache getBitmapCache() {
65+
return mBitmapCache;
66+
}
6067
}

app/src/common/shared/org/mozilla/vrbrowser/browser/PromptDelegate.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void attachToWindow(@NonNull WindowWidget window) {
5757
detachFromWindow();
5858

5959
mAttachedWindow = window;
60-
mAttachedWindow.getSessionStack().setPromptDelegate(this);
60+
mAttachedWindow.getSession().setPromptDelegate(this);
6161
mViewModel.getAll().observeForever(mObserver);
6262
}
6363

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

216216
if (!SettingsStore.getInstance(mContext).isPopUpsBlockingEnabled()) {
217217
result.complete(popupPrompt.confirm(AllowOrDeny.ALLOW));
218-
219218
} else {
220-
String uri = mAttachedWindow.getSessionStack().getUriFromSession(geckoSession);
219+
String uri = mAttachedWindow.getSession().getCurrentUri();
221220
PopUpRequest request = PopUpRequest.newRequest(uri, popupPrompt, result);
222221
handlePopUpRequest(request);
223222
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package org.mozilla.vrbrowser.browser;
22

33
import org.mozilla.geckoview.GeckoSession;
4+
import org.mozilla.vrbrowser.browser.engine.Session;
45

56
public interface SessionChangeListener {
6-
default void onNewSession(GeckoSession aSession, int aId) {};
7-
default void onRemoveSession(GeckoSession aSession, int aId) {};
8-
default void onCurrentSessionChange(GeckoSession aSession, int aId) {};
7+
default void onNewSession(GeckoSession aSession) {};
8+
default void onRemoveSession(GeckoSession aSession) {};
9+
default void onCurrentSessionChange(GeckoSession aOldSession, GeckoSession aSession) {};
10+
default void onNewTab(Session aTab) {};
911
}

0 commit comments

Comments
 (0)