Skip to content

Commit

Permalink
[M118] Revert "Introduce Tab Modal dialog to CCT."
Browse files Browse the repository at this point in the history
This reverts commit 8c03adf.

Reason for revert: crbug.com/1486017

Original change's description:
> Introduce Tab Modal dialog to CCT.
>
> Before this CL, only App Modal dialog is supported on CCT. This CL
> adds Tab Modal dialog to CCT and tests whether they can be
> correctly dismissed by navigation and back press.
>
> Bug: 1446709
> Change-Id: Id113b2c0bcae7284deb55f970ff2b30fc96177ee
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4706547
> Reviewed-by: Theresa Sullivan <twellington@chromium.org>
> Commit-Queue: Lijin Shen <lazzzis@google.com>
> Code-Coverage: Findit <findit-for-me@appspot.gserviceaccount.com>
> Cr-Commit-Position: refs/heads/main@{#1175793}

Bug: 1446709, 1486017
Change-Id: I6bb31f485c26500b84ea731c307f24fc3720dcc2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4903131
Commit-Queue: Krishna Govind <govind@chromium.org>
Reviewed-by: Theresa Sullivan <twellington@chromium.org>
Cr-Commit-Position: refs/branch-heads/5993@{#1049}
Cr-Branched-From: 5113507-refs/heads/main@{#1192594}
  • Loading branch information
Theresa Sullivan authored and Chromium LUCI CQ committed Oct 2, 2023
1 parent 00fdc8c commit 4b4e069
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
import org.chromium.chrome.browser.metrics.LaunchMetrics;
import org.chromium.chrome.browser.metrics.MainIntentBehaviorMetrics;
import org.chromium.chrome.browser.modaldialog.ChromeTabModalPresenter;
import org.chromium.chrome.browser.modaldialog.TabModalLifetimeHandler;
import org.chromium.chrome.browser.multiwindow.MultiInstanceChromeTabbedActivity;
import org.chromium.chrome.browser.multiwindow.MultiInstanceManager;
import org.chromium.chrome.browser.multiwindow.MultiWindowUtils;
Expand Down Expand Up @@ -219,6 +220,7 @@
import org.chromium.content_public.common.ContentSwitches;
import org.chromium.ui.base.DeviceFormFactor;
import org.chromium.ui.base.PageTransition;
import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.ui.widget.Toast;

import java.lang.annotation.Retention;
Expand Down Expand Up @@ -298,6 +300,7 @@ public class ChromeTabbedActivity extends ChromeActivity<ChromeActivityComponent
private HistoricalTabModelObserver mHistoricalTabModelObserver;

private BrowserControlsVisibilityDelegate mVrBrowserControlsVisibilityDelegate;
private TabModalLifetimeHandler mTabModalHandler;

private boolean mUIWithNativeInitialized;

Expand Down Expand Up @@ -2266,7 +2269,7 @@ private boolean isTabRegularNtp(Tab tab) {
}

private void onOmniboxFocusChanged(boolean hasFocus) {
getTabModalLifetimeHandler().onOmniboxFocusChanged(hasFocus);
mTabModalHandler.onOmniboxFocusChanged(hasFocus);
}

private void recordLauncherShortcutAction(boolean isIncognito) {
Expand Down Expand Up @@ -2294,7 +2297,7 @@ && getToolbarManager().unfocusUrlBarOnBackPress()) {
return true;
}

if (getTabModalLifetimeHandler().onBackPressed()) {
if (mTabModalHandler.onBackPressed()) {
BackPressManager.record(BackPressHandler.Type.TAB_MODAL_HANDLER);
return true;
}
Expand Down Expand Up @@ -2898,7 +2901,21 @@ public TabSwitcher getTabSwitcherForTesting() {
}

private ComposedBrowserControlsVisibilityDelegate getAppBrowserControlsVisibilityDelegate() {
return mRootUiCoordinator.getAppBrowserControlsVisibilityDelegate();
// TODO(jinsukkim): Move this to RootUiCoordinator.
return ((TabbedRootUiCoordinator) mRootUiCoordinator)
.getAppBrowserControlsVisibilityDelegate();
}

@Override
protected ModalDialogManager createModalDialogManager() {
ModalDialogManager manager = super.createModalDialogManager();
// TODO(crbug.com/1157310): Transition this::method refs to dedicated suppliers.
mTabModalHandler = new TabModalLifetimeHandler(this, getLifecycleDispatcher(), manager,
this::getAppBrowserControlsVisibilityDelegate, this::getTabObscuringHandler,
this::getToolbarManager, getContextualSearchManagerSupplier(),
getTabModelSelectorSupplier(), this::getBrowserControlsManager,
this::getFullscreenManager, mBackPressManager);
return manager;
}

// App Menu related code -----------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@
import org.chromium.chrome.browser.metrics.ActivityTabStartupMetricsTracker;
import org.chromium.chrome.browser.metrics.LaunchMetrics;
import org.chromium.chrome.browser.metrics.UmaSessionStats;
import org.chromium.chrome.browser.modaldialog.TabModalLifetimeHandler;
import org.chromium.chrome.browser.multiwindow.MultiWindowUtils;
import org.chromium.chrome.browser.night_mode.SystemNightModeMonitor;
import org.chromium.chrome.browser.night_mode.WebContentsDarkModeController;
Expand Down Expand Up @@ -407,8 +406,6 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
private boolean mBlockingDrawForAppRestart;
private Runnable mShowContentRunnable;
private boolean mIsRecreatingForTabletModeChange;
// Handling the dismissal of tab modal dialog.
private TabModalLifetimeHandler mTabModalLifetimeHandler;

protected ChromeActivity() {
mIntentHandler = new IntentHandler(this, createIntentHandlerDelegate());
Expand Down Expand Up @@ -1651,21 +1648,8 @@ public SnackbarManager getSnackbarManager() {

@Override
protected ModalDialogManager createModalDialogManager() {
var dialogManager = new ModalDialogManager(
return new ModalDialogManager(
new AppModalPresenter(this), ModalDialogManager.ModalDialogType.APP);
// TODO(crbug.com/1157310): Transition this::method refs to dedicated suppliers.
mTabModalLifetimeHandler = new TabModalLifetimeHandler(this, getLifecycleDispatcher(),
dialogManager,
()
-> mRootUiCoordinator.getAppBrowserControlsVisibilityDelegate(),
this::getTabObscuringHandler, this::getToolbarManager,
getContextualSearchManagerSupplier(), getTabModelSelectorSupplier(),
this::getBrowserControlsManager, this::getFullscreenManager, mBackPressManager);
return dialogManager;
}

protected TabModalLifetimeHandler getTabModalLifetimeHandler() {
return mTabModalLifetimeHandler;
}

protected Drawable getBackgroundDrawable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,6 @@ public boolean shouldPostDeferredStartupForReparentedTab() {

@Override
protected boolean handleBackPressed() {
if (!BackPressManager.isEnabled() && getTabModalLifetimeHandler() != null
&& getTabModalLifetimeHandler().onBackPressed()) {
BackPressManager.record(BackPressHandler.Type.TAB_MODAL_HANDLER);
return true;
}
if (BackPressManager.correctTabNavigationOnFallback()) {
if (getToolbarManager() != null && getToolbarManager().back()) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
import org.chromium.chrome.features.start_surface.StartSurfaceUserData;
import org.chromium.components.browser_ui.accessibility.PageZoomCoordinator;
import org.chromium.components.browser_ui.bottomsheet.EmptyBottomSheetObserver;
import org.chromium.components.browser_ui.util.ComposedBrowserControlsVisibilityDelegate;
import org.chromium.components.browser_ui.widget.InsetObserverView;
import org.chromium.components.browser_ui.widget.MenuOrKeyboardActionController;
import org.chromium.components.browser_ui.widget.TouchEventObserver;
Expand Down Expand Up @@ -153,6 +154,7 @@ public class TabbedRootUiCoordinator extends RootUiCoordinator {
private NotificationPermissionController mNotificationPermissionController;
private HistoryNavigationCoordinator mHistoryNavigationCoordinator;
private NavigationSheet mNavigationSheet;
private ComposedBrowserControlsVisibilityDelegate mAppBrowserControlsVisibilityDelegate;
private LayoutManagerImpl mLayoutManager;
private CommerceSubscriptionsService mCommerceSubscriptionsService;
private UndoGroupSnackbarController mUndoGroupSnackbarController;
Expand Down Expand Up @@ -885,6 +887,16 @@ public void onUrlAnimationFinished(boolean hasFocus) {
}
}

/**
* @return {@link ComposedBrowserControlsVisibilityDelegate} object for tabbed activity.
*/
public ComposedBrowserControlsVisibilityDelegate getAppBrowserControlsVisibilityDelegate() {
if (mAppBrowserControlsVisibilityDelegate == null) {
mAppBrowserControlsVisibilityDelegate = new ComposedBrowserControlsVisibilityDelegate();
}
return mAppBrowserControlsVisibilityDelegate;
}

public StatusIndicatorCoordinator getStatusIndicatorCoordinatorForTesting() {
return mStatusIndicatorCoordinator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@
import org.chromium.components.browser_ui.bottomsheet.EmptyBottomSheetObserver;
import org.chromium.components.browser_ui.bottomsheet.ExpandedSheetHelper;
import org.chromium.components.browser_ui.bottomsheet.ManagedBottomSheetController;
import org.chromium.components.browser_ui.util.ComposedBrowserControlsVisibilityDelegate;
import org.chromium.components.browser_ui.widget.MenuOrKeyboardActionController;
import org.chromium.components.browser_ui.widget.gesture.BackPressHandler;
import org.chromium.components.browser_ui.widget.scrim.ScrimCoordinator;
Expand Down Expand Up @@ -330,7 +329,6 @@ public class RootUiCoordinator
new OneshotSupplierImpl<>();
private FoldTransitionController mFoldTransitionController;
private RestoreTabsFeatureHelper mRestoreTabsFeatureHelper;
private ComposedBrowserControlsVisibilityDelegate mAppBrowserControlsVisibilityDelegate;

/**
* Create a new {@link RootUiCoordinator} for the given activity.
Expand Down Expand Up @@ -1593,16 +1591,6 @@ public Supplier<EphemeralTabCoordinator> getEphemeralTabCoordinatorSupplier() {
return mFindToolbarManager;
}

/**
* @return {@link ComposedBrowserControlsVisibilityDelegate} object for tabbed activity.
*/
public ComposedBrowserControlsVisibilityDelegate getAppBrowserControlsVisibilityDelegate() {
if (mAppBrowserControlsVisibilityDelegate == null) {
mAppBrowserControlsVisibilityDelegate = new ComposedBrowserControlsVisibilityDelegate();
}
return mAppBrowserControlsVisibilityDelegate;
}

/**
* Gets the browser controls manager, creates it unless already created.
* @deprecated Instead, inject this directly to your constructor. If that's not possible, then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,6 @@
import org.chromium.content_public.common.ContentSwitches;
import org.chromium.net.test.EmbeddedTestServer;
import org.chromium.net.test.util.TestWebServer;
import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.ui.modaldialog.ModalDialogProperties;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.mojom.WindowOpenDisposition;
import org.chromium.ui.test.util.BlankUiTestActivity;
import org.chromium.ui.test.util.DeviceRestriction;
Expand Down Expand Up @@ -2449,50 +2446,6 @@ public void testAppMenuDoesNotShowReadAloud() {
mCustomTabActivityTestRule.getActivity().findViewById(R.id.readaloud_menu_id));
}

@Test
@SmallTest
public void testNavigationDismissTabModalDialog() {
Context context = getInstrumentation().getTargetContext().getApplicationContext();
Intent intent = CustomTabsIntentTestUtils.createMinimalCustomTabIntent(context, mTestPage);
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(intent);
final Tab tab = mCustomTabActivityTestRule.getActivity().getActivityTab();

ModalDialogManager dialogManager =
mCustomTabActivityTestRule.getActivity().getModalDialogManagerSupplier().get();
TestThreadUtils.runOnUiThreadBlocking(() -> {
PropertyModel dialog =
new PropertyModel.Builder(ModalDialogProperties.ALL_KEYS)
.with(ModalDialogProperties.TITLE, "test")
.with(ModalDialogProperties.POSITIVE_BUTTON_TEXT,
context.getString(R.string.delete))
.with(ModalDialogProperties.NEGATIVE_BUTTON_TEXT,
context.getString(R.string.cancel))
.with(ModalDialogProperties.CONTROLLER,
new ModalDialogProperties.Controller() {
@Override
public void onClick(PropertyModel model, int buttonType) {}

@Override
public void onDismiss(
PropertyModel model, int dismissalCause) {}
})
.build();

dialogManager.showDialog(dialog, ModalDialogManager.ModalDialogType.TAB);
});

CriteriaHelper.pollUiThread(() -> dialogManager.isShowing());

TestThreadUtils.runOnUiThreadBlocking(
(Runnable) () -> tab.loadUrl(new LoadUrlParams(mTestPage2)));
ChromeTabUtils.waitForTabPageLoaded(tab, mTestPage2);

Assert.assertTrue(tab.canGoBack());
Assert.assertFalse(tab.canGoForward());

CriteriaHelper.pollUiThread(() -> !dialogManager.isShowing());
}

@Test
@SmallTest
@EnableFeatures(ChromeFeatureList.BACK_GESTURE_REFACTOR)
Expand Down Expand Up @@ -2573,74 +2526,6 @@ public void testBackPressNavigationFailure_WithoutRecover() {
});
}

@Test
@SmallTest
@DisableFeatures(ChromeFeatureList.BACK_GESTURE_REFACTOR)
public void testBackPressDismissTabModalDialog() {
Context context = getInstrumentation().getTargetContext().getApplicationContext();
Intent intent = CustomTabsIntentTestUtils.createMinimalCustomTabIntent(context, mTestPage);
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(intent);
final Tab tab = mCustomTabActivityTestRule.getActivity().getActivityTab();

ModalDialogManager dialogManager =
mCustomTabActivityTestRule.getActivity().getModalDialogManagerSupplier().get();

TestThreadUtils.runOnUiThreadBlocking(
(Runnable) () -> tab.loadUrl(new LoadUrlParams(mTestPage2)));
ChromeTabUtils.waitForTabPageLoaded(tab, mTestPage2);

TestThreadUtils.runOnUiThreadBlocking(() -> {
PropertyModel dialog =
new PropertyModel.Builder(ModalDialogProperties.ALL_KEYS)
.with(ModalDialogProperties.TITLE, "test")
.with(ModalDialogProperties.POSITIVE_BUTTON_TEXT,
context.getString(R.string.delete))
.with(ModalDialogProperties.NEGATIVE_BUTTON_TEXT,
context.getString(R.string.cancel))
.with(ModalDialogProperties.CONTROLLER,
new ModalDialogProperties.Controller() {
@Override
public void onClick(PropertyModel model, int buttonType) {}

@Override
public void onDismiss(
PropertyModel model, int dismissalCause) {}
})
.build();

dialogManager.showDialog(dialog, ModalDialogManager.ModalDialogType.TAB);
});
CriteriaHelper.pollUiThread(() -> dialogManager.isShowing(), "Dialog should be displayed");

HistogramWatcher histogramWatcher =
HistogramWatcher.newSingleRecordWatcher("Android.BackPress.Intercept",
BackPressManager.getHistogramValueForTesting(
BackPressHandler.Type.TAB_MODAL_HANDLER));

TestThreadUtils.runOnUiThreadBlocking(() -> {
mCustomTabActivityTestRule.getActivity().getOnBackPressedDispatcher().onBackPressed();
});

Assert.assertTrue("Should be able to navigate back after navigation", tab.canGoBack());
Assert.assertFalse("Should be unable to navigate forward", tab.canGoForward());
CriteriaHelper.pollInstrumentationThread(() -> {
Criteria.checkThat("Tab should not be navigated when dialog is dismissed",
ChromeTabUtils.getUrlStringOnUiThread(getActivity().getActivityTab()),
is(mTestPage2));
});

histogramWatcher.assertExpected("Dialog should be dismissed by back press");
CriteriaHelper.pollUiThread(
() -> !dialogManager.isShowing(), "Dialog should be dismissed by back press");
}

@Test
@SmallTest
@EnableFeatures(ChromeFeatureList.BACK_GESTURE_REFACTOR)
public void testBackPressDismissTabModalDialog_BackGestureRefactor() {
testBackPressDismissTabModalDialog();
}

private void rotateCustomTabActivity(CustomTabActivity activity, int orientation) {
ActivityTestUtils.rotateActivityToOrientation(activity, orientation);
CriteriaHelper.pollUiThread(() -> {
Expand Down

0 comments on commit 4b4e069

Please sign in to comment.