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

Wait to load URI from intent until after session restore. #3443

Merged
merged 1 commit into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 9 additions & 28 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,9 @@
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;

Expand Down Expand Up @@ -549,12 +547,11 @@ protected void onNewIntent(final Intent intent) {
Log.d(LOGTAG,"VRBrowserActivity onNewIntent");
super.onNewIntent(intent);
setIntent(intent);
final String action = intent.getAction();
if (Intent.ACTION_VIEW.equals(action)) {
loadFromIntent(intent);

} else if (GeckoRuntime.ACTION_CRASHED.equals(intent.getAction())) {
if (GeckoRuntime.ACTION_CRASHED.equals(intent.getAction())) {
Log.e(LOGTAG, "Restarted after a crash");
} else {
loadFromIntent(intent);
}
}

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

boolean openInWindow = false;
boolean openInTab = false;
boolean openInBackground = false;

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

// Open the provided URL in a new tab, if there is no URL provided we just open the homepage
if (extras.containsKey("create_new_tab")) {
openInTab = extras.getBoolean("create_new_tab", false);
if (uri == null) {
uri = Uri.parse(SettingsStore.getInstance(this).getHomepage());
}
}

// Open the tab in background/foreground, if there is no URL provided we just open the homepage
if (extras.containsKey("background")) {
openInBackground = extras.getBoolean("background", false);
Expand Down Expand Up @@ -659,21 +647,14 @@ void loadFromIntent(final Intent intent) {
if (uri != null) {
Log.d(LOGTAG, "Loading URI from intent: " + uri.toString());

if (openInWindow) {
openNewWindow(uri.toString());

} else if (openInTab) {
if (openInBackground) {
openNewTab(uri.toString());

} else {
openNewTabForeground(uri.toString());
}
int location = Windows.OPEN_IN_FOREGROUND;

} else {
SessionStore.get().getActiveSession().loadUri(uri.toString());
if (openInWindow) {
location = Windows.OPEN_IN_NEW_WINDOW;
} else if (openInBackground) {
location = Windows.OPEN_IN_BACKGROUND;
}

mWindows.openNewTabAfterRestore(uri.toString(), location);
} else {
mWindows.getFocusedWindow().loadHomeIfNotRestored();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.util.Log;

import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

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

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

@IntDef(value = { OPEN_IN_FOREGROUND, OPEN_IN_BACKGROUND, OPEN_IN_NEW_WINDOW})
public @interface NewTabLocation {}
public static final int OPEN_IN_FOREGROUND = 0;
public static final int OPEN_IN_BACKGROUND = 1;
public static final int OPEN_IN_NEW_WINDOW = 2;


private static final String WINDOWS_SAVE_FILENAME = "windows_state.json";

private static final int TAB_ADDED_NOTIFICATION_ID = 0;
Expand Down Expand Up @@ -135,6 +143,9 @@ class WindowsState {
private boolean mCompositorPaused = false;
private WindowsState mWindowsState;
private boolean mIsRestoreEnabled;
private boolean mAfterRestore;
private String mAddedTabUri;
private @NewTabLocation int mAddedTabLocation = OPEN_IN_FOREGROUND;

public enum PanelType {
NONE,
Expand Down Expand Up @@ -759,6 +770,13 @@ public void restoreSessions() {
exitPrivateMode();
}
}

if (mAddedTabUri != null) {
openNewTab(mAddedTabUri, mAddedTabLocation);
mAddedTabUri = null;
}

mAfterRestore = true;
}

private void removeWindow(@NonNull WindowWidget aWindow) {
Expand Down Expand Up @@ -1243,6 +1261,30 @@ public void addTab(WindowWidget targetWindow) {
addTab(targetWindow, null);
}

public void openNewTabAfterRestore(@NonNull String aUri, @NewTabLocation int aLocation) {
if (mAfterRestore) {
openNewTab(aUri, aLocation);
} else {
mAddedTabUri = aUri;
mAddedTabLocation = aLocation;
}
}

private void openNewTab(@NonNull String aUri, @NewTabLocation int aLocation) {
if (aLocation == OPEN_IN_NEW_WINDOW) {
WindowWidget newWindow = addWindow();
if ((newWindow != null) && (newWindow.getSession() != null)) {
newWindow.getSession().loadUri(aUri);
}
} else if (mFocusedWindow != null) {
if (aLocation == OPEN_IN_FOREGROUND) {
addTab(mFocusedWindow, aUri);
} else if (aLocation == OPEN_IN_BACKGROUND) {
addBackgroundTab(mFocusedWindow, aUri);
}
}
}

public void addTab(@NonNull WindowWidget targetWindow, @Nullable String aUri) {
Session session = SessionStore.get().createSuspendedSession(aUri, targetWindow.getSession().isPrivateMode());
setFirstPaint(targetWindow, session);
Expand Down