diff --git a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java index 402478c56..270fc8e94 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java @@ -93,9 +93,11 @@ import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; +import java.util.Objects; import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Consumer; +import java.util.function.Function; import static org.mozilla.vrbrowser.ui.widgets.UIWidget.REMOVE_WIDGET; @@ -392,6 +394,20 @@ public void onWindowVideoAvailabilityChanged(@NonNull WindowWidget aWindow) { mWhatsNewWidget.getPlacement().parentHandle = mWindows.getFocusedWindow().getHandle(); mWhatsNewWidget.show(UIWidget.REQUEST_FOCUS); } + + EngineProvider.INSTANCE.loadExtensions() + .thenAcceptAsync(aVoid -> { + Log.d(LOGTAG, "WebExtensions loaded"); + mWindows.restoreSessions(); + }, getServicesProvider().getExecutors().mainThread()) + .exceptionally(throwable -> { + String msg = throwable.getLocalizedMessage(); + if (msg != null) { + Log.e(LOGTAG, "Extensions load error: " + msg); + } + mWindows.restoreSessions(); + return null; + }); } private void attachToWindow(@NonNull WindowWidget aWindow, @Nullable WindowWidget aPrevWindow) { diff --git a/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/EngineProvider.kt b/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/EngineProvider.kt index a646e6c7b..bcf68bf5c 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/EngineProvider.kt +++ b/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/EngineProvider.kt @@ -11,6 +11,7 @@ import org.mozilla.vrbrowser.browser.SettingsStore import org.mozilla.vrbrowser.browser.content.TrackingProtectionPolicy import org.mozilla.vrbrowser.browser.content.TrackingProtectionStore import org.mozilla.vrbrowser.crashreporting.CrashReporterService +import java.util.concurrent.CompletableFuture object EngineProvider { @@ -54,15 +55,23 @@ object EngineProvider { } runtime = GeckoRuntime.create(context, builder.build()) - for (extension in WEB_EXTENSIONS) { - val path = "resource://android/assets/web_extensions/$extension/" - runtime!!.registerWebExtension(WebExtension(path, runtime!!.webExtensionController)) - } } return runtime!! } + fun loadExtensions() : CompletableFuture { + val futures : List> = WEB_EXTENSIONS.map { + val future = CompletableFuture() + val url = "resource://android/assets/web_extensions/$it/" + runtime!!.webExtensionController.installBuiltIn(url).accept { + future.complete(null) + } + future + } + return CompletableFuture.allOf(*futures.toTypedArray()) + } + fun createGeckoWebExecutor(context: Context): GeckoWebExecutor { return GeckoWebExecutor(getOrCreateRuntime(context)) } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java index 4a077cd9c..d9625282f 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java @@ -39,7 +39,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -134,6 +133,8 @@ class WindowsState { private Services mServices; private PromptDialogWidget mNoInternetDialog; private boolean mCompositorPaused = false; + private WindowsState mWindowsState; + private boolean mIsRestoreEnabled; public enum PanelType { NONE, @@ -182,6 +183,8 @@ public Windows(Context aContext) { mWidgetManager.addConnectivityListener(mConnectivityDelegate); + mIsRestoreEnabled = SettingsStore.getInstance(mContext).isRestoreTabsEnabled(); + mWindowsState = restoreState(); restoreWindows(); } @@ -698,35 +701,12 @@ private WindowWidget getRightWindow() { } private void restoreWindows() { - boolean restoreEnabled = SettingsStore.getInstance(mContext).isRestoreTabsEnabled(); - WindowsState windowsState = restoreState(); - if (restoreEnabled && windowsState != null) { - ArrayList restoredSessions = new ArrayList<>(); - if (windowsState.tabs != null) { - windowsState.tabs.forEach(state -> { - restoredSessions.add(SessionStore.get().createSuspendedSession(state)); - GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.PRE_EXISTING); - }); - } - mPrivateMode = false; - for (WindowState windowState : windowsState.regularWindowsState) { - if (windowState.tabIndex >= 0 && windowState.tabIndex < restoredSessions.size()) { - addRestoredWindow(windowState, restoredSessions.get(windowState.tabIndex)); - } else if (windowState.tabIndex < 0) { - WindowWidget widget = addRestoredWindow(windowState, null); - if ((widget != null) && (widget.getSession() != null)) { - widget.getSession().loadHomePage(); - } - } - } - mPrivateMode = !windowsState.privateMode; - if (windowsState.privateMode) { - enterPrivateMode(); - } else { - exitPrivateMode(); + if (mIsRestoreEnabled && mWindowsState != null) { + for (WindowState windowState : mWindowsState.regularWindowsState) { + addRestoredWindow(windowState, null); } - WindowWidget windowToFocus = getWindowWithPlacement(windowsState.focusedWindowPlacement); + WindowWidget windowToFocus = getWindowWithPlacement(mWindowsState.focusedWindowPlacement); if (windowToFocus == null) { windowToFocus = getFrontWindow(); if (windowToFocus == null && getCurrentWindows().size() > 0) { @@ -746,6 +726,43 @@ private void restoreWindows() { updateViews(); } + public void restoreSessions() { + if (mIsRestoreEnabled && mWindowsState != null) { + ArrayList restoredSessions = new ArrayList<>(); + if (mWindowsState.tabs != null) { + mWindowsState.tabs.forEach(state -> { + restoredSessions.add(SessionStore.get().createSuspendedSession(state)); + GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.PRE_EXISTING); + }); + } + + for (WindowState windowState : mWindowsState.regularWindowsState) { + WindowWidget targetWindow = getWindowWithPlacement(windowState.placement); + if (targetWindow != null) { + if (windowState.tabIndex >= 0 && windowState.tabIndex < restoredSessions.size()) { + Session defaultSession = targetWindow.getSession(); + Session session = restoredSessions.get(windowState.tabIndex); + targetWindow.setupListeners(session); + session.setActive(true); + targetWindow.setSession(session); + SessionStore.get().setActiveSession(session); + // Destroy the default blank session + SessionStore.get().destroySession(defaultSession); + + } else { + targetWindow.loadHome(); + } + } + } + + if (mWindowsState.privateMode) { + enterPrivateMode(); + } else { + exitPrivateMode(); + } + } + } + private void removeWindow(@NonNull WindowWidget aWindow) { BitmapCache.getInstance(mContext).removeBitmap(aWindow.getSession().getId()); mWidgetManager.removeWidget(aWindow); diff --git a/app/src/main/assets/web_extensions/webcompat_vimeo/manifest.json b/app/src/main/assets/web_extensions/webcompat_vimeo/manifest.json index 8713592a9..ce3262d41 100644 --- a/app/src/main/assets/web_extensions/webcompat_vimeo/manifest.json +++ b/app/src/main/assets/web_extensions/webcompat_vimeo/manifest.json @@ -3,6 +3,11 @@ "name": "Firefox Reality Vimeo.com WebCompat Enhancements", "version": "1.0", "description": "Fixes web-site compatibility quirks for Vimeo.com when using Firefox Reality.", + "browser_specific_settings": { + "gecko": { + "id": "fxr-webcompat_vimeo@mozilla.org" + } + }, "content_scripts": [ { "matches": [ diff --git a/app/src/main/assets/web_extensions/webcompat_youtube/manifest.json b/app/src/main/assets/web_extensions/webcompat_youtube/manifest.json index 34d24e240..a2e7527da 100644 --- a/app/src/main/assets/web_extensions/webcompat_youtube/manifest.json +++ b/app/src/main/assets/web_extensions/webcompat_youtube/manifest.json @@ -3,6 +3,11 @@ "name": "Firefox Reality YouTube.com WebCompat Enhancements", "version": "1.0", "description": "Fixes web-site compatibility quirks for YouTube.com when using Firefox Reality.", + "browser_specific_settings": { + "gecko": { + "id": "fxr-webcompat_youtube@mozilla.org" + } + }, "content_scripts": [ { "matches": [