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

Commit 38cba1e

Browse files
authored
Wait to load URI from intent until after session restore. (#3443)
Fixes #3431 This patch changes the behavior of launching or opening a URI from an intent. Previously the URI would be opened in the focuses window. With this patch it matches Fenix and desktop and creates a new tab in the focused window.
1 parent 97a9dca commit 38cba1e

File tree

2 files changed

+51
-28
lines changed

2 files changed

+51
-28
lines changed

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

+9-28
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,9 @@
9393
import java.util.HashMap;
9494
import java.util.HashSet;
9595
import java.util.LinkedList;
96-
import java.util.Objects;
9796
import java.util.Set;
9897
import java.util.concurrent.CopyOnWriteArrayList;
9998
import java.util.function.Consumer;
100-
import java.util.function.Function;
10199

102100
import static org.mozilla.vrbrowser.ui.widgets.UIWidget.REMOVE_WIDGET;
103101

@@ -549,12 +547,11 @@ protected void onNewIntent(final Intent intent) {
549547
Log.d(LOGTAG,"VRBrowserActivity onNewIntent");
550548
super.onNewIntent(intent);
551549
setIntent(intent);
552-
final String action = intent.getAction();
553-
if (Intent.ACTION_VIEW.equals(action)) {
554-
loadFromIntent(intent);
555550

556-
} else if (GeckoRuntime.ACTION_CRASHED.equals(intent.getAction())) {
551+
if (GeckoRuntime.ACTION_CRASHED.equals(intent.getAction())) {
557552
Log.e(LOGTAG, "Restarted after a crash");
553+
} else {
554+
loadFromIntent(intent);
558555
}
559556
}
560557

@@ -600,7 +597,6 @@ void loadFromIntent(final Intent intent) {
600597
Uri uri = intent.getData();
601598

602599
boolean openInWindow = false;
603-
boolean openInTab = false;
604600
boolean openInBackground = false;
605601

606602
Bundle extras = intent.getExtras();
@@ -616,14 +612,6 @@ void loadFromIntent(final Intent intent) {
616612
SettingsStore.getInstance(this).setHomepage(homepageUri.toString());
617613
}
618614

619-
// Open the provided URL in a new tab, if there is no URL provided we just open the homepage
620-
if (extras.containsKey("create_new_tab")) {
621-
openInTab = extras.getBoolean("create_new_tab", false);
622-
if (uri == null) {
623-
uri = Uri.parse(SettingsStore.getInstance(this).getHomepage());
624-
}
625-
}
626-
627615
// Open the tab in background/foreground, if there is no URL provided we just open the homepage
628616
if (extras.containsKey("background")) {
629617
openInBackground = extras.getBoolean("background", false);
@@ -659,21 +647,14 @@ void loadFromIntent(final Intent intent) {
659647
if (uri != null) {
660648
Log.d(LOGTAG, "Loading URI from intent: " + uri.toString());
661649

662-
if (openInWindow) {
663-
openNewWindow(uri.toString());
664-
665-
} else if (openInTab) {
666-
if (openInBackground) {
667-
openNewTab(uri.toString());
668-
669-
} else {
670-
openNewTabForeground(uri.toString());
671-
}
650+
int location = Windows.OPEN_IN_FOREGROUND;
672651

673-
} else {
674-
SessionStore.get().getActiveSession().loadUri(uri.toString());
652+
if (openInWindow) {
653+
location = Windows.OPEN_IN_NEW_WINDOW;
654+
} else if (openInBackground) {
655+
location = Windows.OPEN_IN_BACKGROUND;
675656
}
676-
657+
mWindows.openNewTabAfterRestore(uri.toString(), location);
677658
} else {
678659
mWindows.getFocusedWindow().loadHomeIfNotRestored();
679660
}

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java

+42
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Context;
44
import android.util.Log;
55

6+
import androidx.annotation.IntDef;
67
import androidx.annotation.NonNull;
78
import androidx.annotation.Nullable;
89

@@ -55,6 +56,13 @@ public class Windows implements TrayListener, TopBarWidget.Delegate, TitleBarWid
5556

5657
private static final String LOGTAG = SystemUtils.createLogtag(Windows.class);
5758

59+
@IntDef(value = { OPEN_IN_FOREGROUND, OPEN_IN_BACKGROUND, OPEN_IN_NEW_WINDOW})
60+
public @interface NewTabLocation {}
61+
public static final int OPEN_IN_FOREGROUND = 0;
62+
public static final int OPEN_IN_BACKGROUND = 1;
63+
public static final int OPEN_IN_NEW_WINDOW = 2;
64+
65+
5866
private static final String WINDOWS_SAVE_FILENAME = "windows_state.json";
5967

6068
private static final int TAB_ADDED_NOTIFICATION_ID = 0;
@@ -135,6 +143,9 @@ class WindowsState {
135143
private boolean mCompositorPaused = false;
136144
private WindowsState mWindowsState;
137145
private boolean mIsRestoreEnabled;
146+
private boolean mAfterRestore;
147+
private String mAddedTabUri;
148+
private @NewTabLocation int mAddedTabLocation = OPEN_IN_FOREGROUND;
138149

139150
public enum PanelType {
140151
NONE,
@@ -759,6 +770,13 @@ public void restoreSessions() {
759770
exitPrivateMode();
760771
}
761772
}
773+
774+
if (mAddedTabUri != null) {
775+
openNewTab(mAddedTabUri, mAddedTabLocation);
776+
mAddedTabUri = null;
777+
}
778+
779+
mAfterRestore = true;
762780
}
763781

764782
private void removeWindow(@NonNull WindowWidget aWindow) {
@@ -1243,6 +1261,30 @@ public void addTab(WindowWidget targetWindow) {
12431261
addTab(targetWindow, null);
12441262
}
12451263

1264+
public void openNewTabAfterRestore(@NonNull String aUri, @NewTabLocation int aLocation) {
1265+
if (mAfterRestore) {
1266+
openNewTab(aUri, aLocation);
1267+
} else {
1268+
mAddedTabUri = aUri;
1269+
mAddedTabLocation = aLocation;
1270+
}
1271+
}
1272+
1273+
private void openNewTab(@NonNull String aUri, @NewTabLocation int aLocation) {
1274+
if (aLocation == OPEN_IN_NEW_WINDOW) {
1275+
WindowWidget newWindow = addWindow();
1276+
if ((newWindow != null) && (newWindow.getSession() != null)) {
1277+
newWindow.getSession().loadUri(aUri);
1278+
}
1279+
} else if (mFocusedWindow != null) {
1280+
if (aLocation == OPEN_IN_FOREGROUND) {
1281+
addTab(mFocusedWindow, aUri);
1282+
} else if (aLocation == OPEN_IN_BACKGROUND) {
1283+
addBackgroundTab(mFocusedWindow, aUri);
1284+
}
1285+
}
1286+
}
1287+
12461288
public void addTab(@NonNull WindowWidget targetWindow, @Nullable String aUri) {
12471289
Session session = SessionStore.get().createSuspendedSession(aUri, targetWindow.getSession().isPrivateMode());
12481290
setFirstPaint(targetWindow, session);

0 commit comments

Comments
 (0)