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

Commit

Permalink
Tabs implementation (#1963)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MortimerGoro committed Oct 22, 2019
1 parent d396a2e commit 6db51ca
Show file tree
Hide file tree
Showing 47 changed files with 2,800 additions and 1,816 deletions.
48 changes: 21 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 @@ -449,7 +449,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 +465,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 +676,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 +705,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 +773,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 +998,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 +1129,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 +1320,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 @@ -1386,7 +1380,7 @@ public void setCPULevel(int aCPULevel) {
public void openNewWindow(String uri) {
WindowWidget newWindow = mWindows.addWindow();
if (newWindow != null) {
newWindow.getSessionStack().newSessionWithUrl(uri);
newWindow.getSession().loadUri(uri);
}
}

Expand Down
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
Expand Up @@ -3,7 +3,7 @@
import org.mozilla.geckoview.GeckoSession;

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) {};
}
Loading

0 comments on commit 6db51ca

Please sign in to comment.