Skip to content

Commit

Permalink
[Android] [IncognitoReauth] Integrate TabSwitcherCustomViewManager.
Browse files Browse the repository at this point in the history
This CL defines ownership for the TabSwitcherCustomViewManager and
connects it with the IncognitoReauthCoordinator client.

Bug: 1227656
Change-Id: I663aefe9dae18494b18ae824fa1c85216699b1fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3629324
Reviewed-by: Mei Liang <meiliang@chromium.org>
Reviewed-by: Matthew Jones <mdjones@chromium.org>
Reviewed-by: Xi Han <hanxi@chromium.org>
Commit-Queue: Rohit Agarwal <roagarwal@chromium.org>
Reviewed-by: Theresa Sullivan <twellington@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1002218}
  • Loading branch information
Rohit Agarwal authored and Chromium LUCI CQ committed May 11, 2022
1 parent 6f792cc commit 5deebe9
Show file tree
Hide file tree
Showing 13 changed files with 211 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
import android.os.SystemClock;
import android.view.ViewGroup;

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

import com.google.android.material.appbar.AppBarLayout;

import org.chromium.base.supplier.OneshotSupplier;
import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.browser.ntp.NewTabPageLaunchOrigin;
import org.chromium.chrome.browser.tasks.tab_management.TabSwitcher;
import org.chromium.chrome.browser.tasks.tab_management.TabSwitcherCustomViewManager;
import org.chromium.chrome.features.tasks.TasksSurface;

/** Interface to communicate with the start surface. */
Expand Down Expand Up @@ -253,4 +256,12 @@ void onOverviewShownAtLaunch(
*/
@Nullable
TasksSurface getPrimaryTasksSurface();

/**
* TODO(crbug.com/1315676): Remove this API after the bug is resolved.
*
* @return A {@link OneShotSupplier <TabSwitcherCustomViewManager>}.
*/
@NonNull
OneshotSupplier<TabSwitcherCustomViewManager> getTabSwitcherCustomViewManagerSupplier();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.chromium.base.ObserverList;
import org.chromium.base.jank_tracker.JankTracker;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.supplier.OneshotSupplier;
import org.chromium.base.supplier.OneshotSupplierImpl;
import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.R;
Expand All @@ -47,6 +48,7 @@
import org.chromium.chrome.browser.tasks.tab_management.TabManagementDelegate.TabSwitcherType;
import org.chromium.chrome.browser.tasks.tab_management.TabManagementModuleProvider;
import org.chromium.chrome.browser.tasks.tab_management.TabSwitcher;
import org.chromium.chrome.browser.tasks.tab_management.TabSwitcherCustomViewManager;
import org.chromium.chrome.browser.toolbar.top.Toolbar;
import org.chromium.chrome.browser.ui.messages.snackbar.SnackbarManager;
import org.chromium.chrome.features.tasks.TasksSurface;
Expand Down Expand Up @@ -95,6 +97,9 @@ public class StartSurfaceCoordinator implements StartSurface {
private final MenuOrKeyboardActionController mMenuOrKeyboardActionController;
private final MultiWindowModeStateDispatcher mMultiWindowModeStateDispatcher;
private final Supplier<Toolbar> mToolbarSupplier;
// TODO(crbug.com/1315676): Directly return the supplier from {@link TabSwitcherCoordinator}.
private final OneshotSupplierImpl<TabSwitcherCustomViewManager>
mTabSwitcherCustomViewManagerSupplier;

@VisibleForTesting
static final String START_SHOWN_AT_STARTUP_UMA = "Startup.Android.StartSurfaceShownAtStartup";
Expand Down Expand Up @@ -258,6 +263,7 @@ public StartSurfaceCoordinator(@NonNull Activity activity,
mMultiWindowModeStateDispatcher = multiWindowModeStateDispatcher;
mToolbarSupplier = toolbarSupplier;

mTabSwitcherCustomViewManagerSupplier = new OneshotSupplierImpl<>();
boolean excludeMVTiles = StartSurfaceConfiguration.START_SURFACE_EXCLUDE_MV_TILES.getValue()
|| !mIsStartSurfaceEnabled;
boolean excludeQueryTiles =
Expand All @@ -270,6 +276,8 @@ public StartSurfaceCoordinator(@NonNull Activity activity,
browserControlsManager, tabCreatorManager, menuOrKeyboardActionController,
containerView, shareDelegateSupplier, multiWindowModeStateDispatcher,
scrimCoordinator, /* rootView= */ containerView);
mTabSwitcherCustomViewManagerSupplier.set(
mTabSwitcher.getTabSwitcherCustomViewManager());
} else {
// createSwipeRefreshLayout has to be called before creating any surface.
createSwipeRefreshLayout();
Expand Down Expand Up @@ -498,6 +506,11 @@ public TasksSurface getPrimaryTasksSurface() {
return mTasksSurface;
}

@Override
public OneshotSupplier<TabSwitcherCustomViewManager> getTabSwitcherCustomViewManagerSupplier() {
return mTabSwitcherCustomViewManagerSupplier;
}

/**
* Create the {@link TasksSurface}
* @param activity The {@link Activity} that creates this surface.
Expand Down Expand Up @@ -634,6 +647,11 @@ private TabSwitcher.Controller initializeSecondaryTasksSurface() {
mSecondaryTasksSurface.setOnTabSelectingListener(mOnTabSelectingListener);
mOnTabSelectingListener = null;
}

if (!mTabSwitcherCustomViewManagerSupplier.hasValue()) {
mTabSwitcherCustomViewManagerSupplier.set(
mSecondaryTasksSurface.getTabSwitcherCustomViewManager());
}
return mSecondaryTasksSurface.getController();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import org.chromium.base.Callback;
Expand All @@ -25,6 +26,7 @@
import org.chromium.chrome.browser.tasks.pseudotab.TabAttributeCache;
import org.chromium.chrome.browser.tasks.tab_management.TabListFaviconProvider;
import org.chromium.chrome.browser.tasks.tab_management.TabSwitcher;
import org.chromium.chrome.browser.tasks.tab_management.TabSwitcherCustomViewManager;
import org.chromium.chrome.browser.ui.messages.snackbar.SnackbarManager;
import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.ui.modelutil.PropertyModel;
Expand Down Expand Up @@ -151,4 +153,9 @@ public Supplier<Boolean> getTabGridDialogVisibilitySupplier() {
assert false : "should not reach here";
return null;
}

@Override
public @Nullable TabSwitcherCustomViewManager getTabSwitcherCustomViewManager() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.chromium.chrome.browser.compositor.layouts.Layout;
import org.chromium.chrome.browser.omnibox.OmniboxStub;
import org.chromium.chrome.browser.tasks.tab_management.TabSwitcher;
import org.chromium.chrome.browser.tasks.tab_management.TabSwitcherCustomViewManager;

/**
* Interface for the Tasks-related Start Surface. The tasks surface displays information related to
Expand Down Expand Up @@ -119,4 +120,13 @@ void updateFakeSearchBox(int height, int topMargin, int endPadding, float textSi
@VisibleForTesting
/** Returns whether the MV tiles has been initialized. */
boolean isMVTilesInitialized();

/**
* TODO(crbug.com/1315676): Remove this API after the bug is resolved.
*
* @return {@link TabSwitcherCustomViewManager} that allows to pass custom views to {@link
* TabSwitcherCoordinator}.
*/
@Nullable
TabSwitcherCustomViewManager getTabSwitcherCustomViewManager();
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.chromium.chrome.browser.tasks.tab_management.TabManagementDelegate.TabSwitcherType;
import org.chromium.chrome.browser.tasks.tab_management.TabManagementModuleProvider;
import org.chromium.chrome.browser.tasks.tab_management.TabSwitcher;
import org.chromium.chrome.browser.tasks.tab_management.TabSwitcherCustomViewManager;
import org.chromium.chrome.browser.tasks.tab_management.TabUiFeatureUtilities;
import org.chromium.chrome.browser.ui.messages.snackbar.SnackbarManager;
import org.chromium.components.browser_ui.widget.MenuOrKeyboardActionController;
Expand Down Expand Up @@ -293,6 +294,11 @@ public boolean isMVTilesInitialized() {
return mIsMVTilesInitialized;
}

@Override
public @Nullable TabSwitcherCustomViewManager getTabSwitcherCustomViewManager() {
return (mTabSwitcher != null) ? mTabSwitcher.getTabSwitcherCustomViewManager() : null;
}

/** Suggestions UI Delegate for constructing the TileGroup. */
private class MostVisitedSuggestionsUiDelegate extends SuggestionsUiDelegateImpl {
public MostVisitedSuggestionsUiDelegate(SuggestionsNavigationDelegate navigationDelegate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.os.SystemClock;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import org.chromium.base.Callback;
Expand Down Expand Up @@ -247,4 +248,11 @@ interface TabListDelegate {
* @return {@link Supplier} that provides dialog visibility.
*/
Supplier<Boolean> getTabGridDialogVisibilitySupplier();

/**
* @return {@link TabSwitcherCustomViewManager} that allows to pass custom views to {@link
* TabSwitcherCoordinator}.
*/
@Nullable
TabSwitcherCustomViewManager getTabSwitcherCustomViewManager();
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public boolean handleMenuOrKeyboardAction(int id, boolean fromMenu) {
};
private TabGridIphDialogCoordinator mTabGridIphDialogCoordinator;
private PriceTrackingDialogCoordinator mPriceTrackingDialogCoordinator;
private TabSwitcherCustomViewManager mTabSwitcherCustomViewManager;

/** {@see TabManagementDelegate#createCarouselTabSwitcher} */
public TabSwitcherCoordinator(@NonNull Activity activity,
Expand All @@ -183,6 +184,20 @@ public TabSwitcherCoordinator(@NonNull Activity activity,
mMultiWindowModeStateDispatcher = multiWindowModeStateDispatcher;
mRootView = rootView;

mTabSwitcherCustomViewManager =
new TabSwitcherCustomViewManager(new TabSwitcherCustomViewManager.Delegate() {
@Override
public void addCustomView(@NonNull View customView) {
// TODO(crbug.com/1227656): Show this custom view in the tab switcher
// content area.
}

@Override
public void removeCustomView(@NonNull View customView) {
// TODO(crbug.com/1227656): Release this custom view from the tab switcher
// content area and show the previously showed contents.
}
});
PropertyModel containerViewModel = new PropertyModel(TabListContainerProperties.ALL_KEYS);

mMediator = new TabSwitcherMediator(activity, this, containerViewModel, tabModelSelector,
Expand Down Expand Up @@ -435,6 +450,11 @@ public Supplier<Boolean> getTabGridDialogVisibilitySupplier() {
return mTabGridDialogCoordinator::isVisible;
}

@Override
public TabSwitcherCustomViewManager getTabSwitcherCustomViewManager() {
return mTabSwitcherCustomViewManager;
}

@Override
public int getTabListTopOffset() {
return mTabListCoordinator.getTabListTopOffset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.chromium.chrome.browser.incognito.reauth.IncognitoReauthController;
import org.chromium.chrome.browser.incognito.reauth.IncognitoReauthCoordinatorFactory;
import org.chromium.chrome.browser.incognito.reauth.IncognitoReauthManager;
import org.chromium.chrome.browser.incognito.reauth.IncognitoReauthTabSwitcherDelegate;
import org.chromium.chrome.browser.layouts.LayoutManager;
import org.chromium.chrome.browser.layouts.LayoutStateProvider;
import org.chromium.chrome.browser.layouts.LayoutType;
Expand Down Expand Up @@ -101,6 +102,7 @@
import org.chromium.chrome.browser.tab.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.TabCreatorManager;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tasks.tab_management.TabSwitcherCustomViewManager;
import org.chromium.chrome.browser.theme.TopUiThemeColorProvider;
import org.chromium.chrome.browser.toolbar.ButtonDataProvider;
import org.chromium.chrome.browser.toolbar.ToolbarIntentMetadata;
Expand Down Expand Up @@ -193,6 +195,11 @@ public class RootUiCoordinator
* available.
*/
private @Nullable IncognitoReauthController mIncognitoReauthController;
/**
* A Callback controller that is fired when the {@link TabSwitcherCustomViewManager} is made
* available.
*/
private @Nullable CallbackController mTabSwitcherCustomViewController;

/** A means of providing the theme color to different features. */
private TopUiThemeColorProvider mTopUiThemeColorProvider;
Expand Down Expand Up @@ -571,6 +578,10 @@ public void onDestroy() {
mIncognitoReauthController.destroy();
}

if (mTabSwitcherCustomViewController != null) {
mTabSwitcherCustomViewController.destroy();
}

mActivity = null;
}

Expand Down Expand Up @@ -704,9 +715,33 @@ public void onFinishNativeInitialization() {

if (IncognitoReauthManager.isIncognitoReauthFeatureAvailable()) {
TabModelSelector tabModelSelector = mTabModelSelectorSupplier.get();
// TODO(crbug.com/1324211, crbug.com/1227656) : Refactor below to remove
// IncognitoReauthTabSwitcherDelegate altogether and directly pass
// OneshotSupplierImpl<TabSwitcherCustomViewManager> instance.
OneshotSupplierImpl<IncognitoReauthTabSwitcherDelegate>
incognitoReauthTabSwitcherSupplier = new OneshotSupplierImpl<>();
mTabSwitcherCustomViewController = new CallbackController();
mStartSurfaceSupplier.get().getTabSwitcherCustomViewManagerSupplier().onAvailable(
mTabSwitcherCustomViewController.makeCancelable(tabSwitcherCustomViewManager
-> incognitoReauthTabSwitcherSupplier.set(
new IncognitoReauthTabSwitcherDelegate() {
@Override
public boolean addReauthScreenInTabSwitcher(
@NonNull View customView) {
return tabSwitcherCustomViewManager.requestView(
customView);
}

@Override
public boolean removeReauthScreenFromTabSwitcher() {
return tabSwitcherCustomViewManager.releaseView();
}
})));

IncognitoReauthCoordinatorFactory incognitoReauthCoordinatorFactory =
new IncognitoReauthCoordinatorFactory(mActivity, tabModelSelector,
mModalDialogManagerSupplier.get(), new SettingsLauncherImpl());
mModalDialogManagerSupplier.get(), new SettingsLauncherImpl(),
incognitoReauthTabSwitcherSupplier);
mIncognitoReauthController = new IncognitoReauthController(tabModelSelector,
mActivityLifecycleDispatcher, mLayoutStateProviderOneShotSupplier,
mProfileSupplier, incognitoReauthCoordinatorFactory);
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/incognito/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ android_library("java") {
"android/java/src/org/chromium/chrome/browser/incognito/reauth/IncognitoReauthProperties.java",
"android/java/src/org/chromium/chrome/browser/incognito/reauth/IncognitoReauthSettingSwitchPreference.java",
"android/java/src/org/chromium/chrome/browser/incognito/reauth/IncognitoReauthSettingUtils.java",
"android/java/src/org/chromium/chrome/browser/incognito/reauth/IncognitoReauthTabSwitcherDelegate.java",
"android/java/src/org/chromium/chrome/browser/incognito/reauth/IncognitoReauthViewBinder.java",
]
deps = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public void destroy() {
mTabModelSelector.removeObserver(mTabModelSelectorObserver);
mProfileObservableSupplier.removeObserver(mProfileSupplierCallback);
mLayoutStateProviderCallbackController.destroy();
mIncognitoReauthCoordinatorFactory.destroy();
hideDialogIfShowing(DialogDismissalCause.ACTIVITY_DESTROYED);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@
/**
* The coordinator which is responsible for showing the Incognito re-authentication page.
*
* This is created and removed each time the incognito re-auth screen is shown/hidden
* respectively.
*
* TODO(crbug.com/1227656): Add support to disable/enable certain UI elements in the Toolbar when
* the re-auth dialog is shown/hidden in the Incognito tab switcher.
*/
class IncognitoReauthCoordinator {
private final @NonNull Context mContext;
private final @NonNull ModalDialogManager mModalDialogManager;
// This can be null if the {link TabSwitcherCustomViewManager} is not yet created.
private final @Nullable IncognitoReauthTabSwitcherDelegate mIncognitoReauthTabSwitcherDelegate;
private final boolean mShowFullScreen;
private final @Nullable IncognitoReauthMenuDelegate mIncognitoReauthMenuDelegate;

// Non-null for full screen re-auth dialog.
private final @Nullable IncognitoReauthMenuDelegate mIncognitoReauthMenuDelegate;
private final IncognitoReauthMediator mIncognitoReauthMediator;

private View mIncognitoReauthView;
Expand All @@ -53,16 +59,21 @@ class IncognitoReauthCoordinator {
* to initiate re-authentication.
* @param settingsLauncher A {@link SettingsLauncher} that allows to fire {@link
* SettingsActivity}.
* @param incognitoReauthTabSwitcherDelegate A {@link IncognitoReauthTabSwitcherDelegate} that
* allows to communicate with tab switcher to show the re-auth screen.
* @param showFullScreen Whether to show a fullscreen / tab based re-auth dialog.
*/
public IncognitoReauthCoordinator(@NonNull Context context,
@NonNull TabModelSelector tabModelSelector,
@NonNull ModalDialogManager modalDialogManager,
@NonNull IncognitoReauthManager.IncognitoReauthCallback incognitoReauthCallback,
@NonNull IncognitoReauthManager incognitoReauthManager,
@NonNull SettingsLauncher settingsLauncher, boolean showFullScreen) {
@NonNull SettingsLauncher settingsLauncher,
@Nullable IncognitoReauthTabSwitcherDelegate incognitoReauthTabSwitcherDelegate,
boolean showFullScreen) {
mContext = context;
mModalDialogManager = modalDialogManager;
mIncognitoReauthTabSwitcherDelegate = incognitoReauthTabSwitcherDelegate;
mShowFullScreen = showFullScreen;
mIncognitoReauthMediator = new IncognitoReauthMediator(
tabModelSelector, incognitoReauthCallback, incognitoReauthManager);
Expand All @@ -86,14 +97,31 @@ void showDialog() {
mIncognitoReauthMediator::onSeeOtherTabsButtonClicked, mShowFullScreen, delegate);
mModelChangeProcessor = PropertyModelChangeProcessor.create(
mPropertyModel, mIncognitoReauthView, IncognitoReauthViewBinder::bind);
mIncognitoReauthDialog =
new IncognitoReauthDialog(mModalDialogManager, mIncognitoReauthView);
mIncognitoReauthDialog.showIncognitoReauthDialog(mShowFullScreen);

if (mShowFullScreen) {
mIncognitoReauthDialog =
new IncognitoReauthDialog(mModalDialogManager, mIncognitoReauthView);
mIncognitoReauthDialog.showIncognitoReauthDialog(mShowFullScreen);
} else {
assert mIncognitoReauthTabSwitcherDelegate
!= null : "delegate to TabSwitcher can't be null.";
boolean success = mIncognitoReauthTabSwitcherDelegate.addReauthScreenInTabSwitcher(
mIncognitoReauthView);
assert success : "Unable to signal showing the re-auth screen to tab switcher.";
}
}

void hideDialogAndDestroy(@DialogDismissalCause int dismissalCause) {
assert mIncognitoReauthDialog != null : "Incognito re-auth dialog doesn't exists.";
mIncognitoReauthDialog.dismissIncognitoReauthDialog(dismissalCause);
if (mShowFullScreen) {
assert mIncognitoReauthDialog != null : "Incognito re-auth dialog doesn't exists.";
mIncognitoReauthDialog.dismissIncognitoReauthDialog(dismissalCause);
} else {
assert mIncognitoReauthTabSwitcherDelegate
!= null : "delegate to TabSwitcher can't be null.";
boolean success =
mIncognitoReauthTabSwitcherDelegate.removeReauthScreenFromTabSwitcher();
assert success : "Unable to signal removing the re-auth screen from tab switcher.";
}
destroy();
}
}

0 comments on commit 5deebe9

Please sign in to comment.