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

Allow popup tabs to live long enough to initialize before suspending #2338

Merged
merged 1 commit into from
Nov 21, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class Session implements ContentBlocking.Delegate, GeckoSession.Navigatio

private static final String LOGTAG = SystemUtils.createLogtag(Session.class);
private static UserAgentOverride sUserAgentOverride;

private static final long KEEP_ALIVE_DURATION_MS = 1000; // 1 second.

private transient LinkedList<GeckoSession.NavigationDelegate> mNavigationListeners;
private transient LinkedList<GeckoSession.ProgressDelegate> mProgressListeners;
Expand All @@ -83,7 +83,7 @@ public class Session implements ContentBlocking.Delegate, GeckoSession.Navigatio
private transient GeckoRuntime mRuntime;
private transient byte[] mPrivatePage;
private transient boolean mFirstContentfulPaint;

private transient long mKeepAlive;

public interface BitmapChangedListener {
void onBitmapChanged(Session aSession, Bitmap aBitmap);
Expand Down Expand Up @@ -334,6 +334,11 @@ public void suspend() {
if (mState.mSession == null) {
return;
}
if (mKeepAlive > System.currentTimeMillis()) {
Log.e(LOGTAG, "Unable to suspend activity with active keep alive time.");
return;
}

Log.d(LOGTAG, "Suspending Session: " + mState.mId);
closeSession(mState);
mState.mSession = null;
Expand Down Expand Up @@ -688,6 +693,7 @@ public String getId() {
return mState.mId;
}


public boolean isPrivateMode() {
if (mState.mSession != null) {
return mState.mSession.getSettings().getUsePrivateMode();
Expand Down Expand Up @@ -916,10 +922,12 @@ public void onCanGoForward(@NonNull GeckoSession aSession, boolean aCanGoForward

@Override
public GeckoResult<GeckoSession> onNewSession(@NonNull GeckoSession aSession, @NonNull String aUri) {
Log.d(LOGTAG, "Session onStackSession: " + aUri);
mKeepAlive = System.currentTimeMillis() + KEEP_ALIVE_DURATION_MS;
Log.d(LOGTAG, "onNewSession: " + aUri);

Session session = SessionStore.get().createSession(mState.mSettings, SESSION_DO_NOT_OPEN);
session.mState.mParentId = mState.mId;
session.mKeepAlive = mKeepAlive;
for (SessionChangeListener listener: new LinkedList<>(mSessionChangeListeners)) {
listener.onStackSession(session);
}
Expand Down Expand Up @@ -1427,6 +1435,16 @@ public void onActiveStateChange(Session aSession, boolean aActive) {
}
}

@Override
public void onStackSession(Session aSession) {
if (aSession.equals(this)) {
return;
}
for (SessionChangeListener listener : mSessionChangeListeners) {
listener.onStackSession(aSession);
}
}

// Display functions
public void releaseDisplay() {
surfaceDestroyed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,12 @@ public Session getActiveSession() {
public ArrayList<Session> getSortedSessions(boolean aPrivateMode) {
ArrayList<Session> result = new ArrayList<>(mSessions);
result.removeIf(session -> session.isPrivateMode() != aPrivateMode);
result.sort((o1, o2) -> (int)(o2.getLastUse() - o1.getLastUse()));
result.sort((o1, o2) -> {
if (o2.getLastUse() < o1.getLastUse()) {
return -1;
}
return o2.getLastUse() == o1.getLastUse() ? 0 : 1;
});
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,17 @@ public void removeWindowListener(WindowListener aListener) {
mListeners.remove(aListener);
}

public void waitForFirstPaint() {
setFirstPaintReady(false);
setFirstDrawCallback(() -> {
if (!isFirstPaintReady()) {
setFirstPaintReady(true);
mWidgetManager.updateWidget(WindowWidget.this);
}
});
mWidgetManager.updateWidget(this);
}

@Override
public void handleResizeEvent(float aWorldWidth, float aWorldHeight) {
int width = getWindowWidth(aWorldWidth);
Expand Down Expand Up @@ -1087,6 +1098,8 @@ public void onCurrentSessionChange(GeckoSession aOldSession, GeckoSession aSessi
@Override
public void onStackSession(Session aSession) {
// e.g. tab opened via window.open()
aSession.updateLastUse();
waitForFirstPaint();
Session current = mSession;
setSession(aSession);
SessionStore.get().setActiveSession(aSession);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -982,14 +982,7 @@ public void onTabsClicked() {

private void setFirstPaint(@NonNull final WindowWidget aWindow, @NonNull final Session aSession) {
if (aSession.getGeckoSession() == null) {
aWindow.setFirstPaintReady(false);
aWindow.setFirstDrawCallback(() -> {
if (!aWindow.isFirstPaintReady()) {
aWindow.setFirstPaintReady(true);
mWidgetManager.updateWidget(aWindow);
}
});
mWidgetManager.updateWidget(aWindow);
aWindow.waitForFirstPaint();
} else {
// If the new session has a GeckoSession there won't be a first paint event.
// So trigger the first paint callback in case the window is grayed out
Expand Down