Bug 1699046 - Allow GVE to have zero tabs. r=droeh

Marionette uses GVE and sometimes closes the last tab and calls |Quit| at the
same time. When the last tab is closed, GVE will try to open a new tab with the
same content in it, to avoid leaving the browser in the "zero tabs" state. This
causes a race condition where the browser is shutting down and a new tab is
being created, which trips an assertion in our widget code.

During real life usage of the browser, calling Quit only happens during errors.
Because of that, and the fact that we're not seing this crash in the wild,
it should be safe to just fix the problem in GVE instead of supporting this
edge case in GeckoView.

To support the Marionette case, we allow GVE to stay at zero tabs. Some menu
elements need to be disabled (like reload tab and the url bar).

This has the added benefit of being able to test the "no windows" case in GVE
which wasn't possible until now.

Differential Revision: https://phabricator.services.mozilla.com/D113202
This commit is contained in:
Agi Sferro 2021-04-26 20:49:00 +00:00
Родитель 6f231d697c
Коммит 0bacfb352b
2 изменённых файлов: 31 добавлений и 12 удалений

Просмотреть файл

@ -43,6 +43,7 @@ import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.os.Build;
@ -1103,6 +1104,15 @@ public class GeckoViewActivity
menu.findItem(R.id.desktop_mode).setChecked(mDesktopMode);
menu.findItem(R.id.action_tpe).setChecked(mTrackingProtectionException);
menu.findItem(R.id.action_forward).setEnabled(mCanGoForward);
final boolean hasSession = mTabSessionManager.getCurrentSession() != null;
menu.findItem(R.id.action_reload).setEnabled(hasSession);
menu.findItem(R.id.action_forward).setEnabled(hasSession);
menu.findItem(R.id.action_close_tab).setEnabled(hasSession);
menu.findItem(R.id.action_tpe).setEnabled(hasSession);
menu.findItem(R.id.action_pb).setEnabled(hasSession);
menu.findItem(R.id.desktop_mode).setEnabled(hasSession);
return true;
}
@ -1223,15 +1233,13 @@ public class GeckoViewActivity
@Override
public void closeTab(TabSession session) {
if (mTabSessionManager.sessionCount() > 1) {
mTabSessionManager.closeSession(session);
TabSession tabSession = mTabSessionManager.getCurrentSession();
setGeckoViewSession(tabSession);
mTabSessionManager.closeSession(session);
TabSession tabSession = mTabSessionManager.getCurrentSession();
setGeckoViewSession(tabSession);
if (tabSession != null) {
tabSession.reload();
mToolbarView.updateTabCount();
} else {
recreateSession(session);
}
mToolbarView.updateTabCount();
}
@Override
@ -1274,11 +1282,22 @@ public class GeckoViewActivity
if (previousSession != null) {
controller.setTabActive(previousSession, false);
}
mGeckoView.setSession(session);
if (activateTab) {
controller.setTabActive(session, true);
final boolean hasSession = session != null;
final LocationView view = mToolbarView.getLocationView();
// No point having the URL bar enabled if there's no session to navigate to
view.setEnabled(hasSession);
if (hasSession) {
mGeckoView.setSession(session);
if (activateTab) {
controller.setTabActive(session, true);
}
mTabSessionManager.setCurrentSession(session);
} else {
mGeckoView.coverUntilFirstPaint(Color.WHITE);
view.setText("");
}
mTabSessionManager.setCurrentSession(session);
}
@Override

Просмотреть файл

@ -58,7 +58,7 @@ public class TabSessionManager {
}
public TabSession getSession(int index) {
if (index >= mTabSessions.size()) {
if (index >= mTabSessions.size() || index < 0) {
return null;
}
return mTabSessions.get(index);