Commit e010c2c3 authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Chromium LUCI CQ

[Payments] Replace deprecated OverviewModeBehavior in PaymentUiService

Since OverviewModeBehavior has been deprecated in favor of
LayoutStateProvider, this CL replace PaymentUiService's
OverviewModeBehavior with LayoutStateProvider.

In order to do that, this CL also provides an accessor for
ChromeTabbedActivity's LayoutStateProvider.

Related:
* The CL that introduced OverviewModeBehavior to payment code:
  https://crrev.com/c/1506374

Bug: 1161560
Change-Id: Ied65a51953602bd3176449074297cd99ae54deb7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2622316Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846401}
parent cf81f284
...@@ -12,10 +12,8 @@ import androidx.annotation.Nullable; ...@@ -12,10 +12,8 @@ import androidx.annotation.Nullable;
import androidx.collection.ArrayMap; import androidx.collection.ArrayMap;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.app.ChromeActivity; import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.autofill.PersonalDataManager; import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher; import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.payments.ui.PaymentUiService; import org.chromium.chrome.browser.payments.ui.PaymentUiService;
import org.chromium.chrome.browser.tabmodel.TabModel; import org.chromium.chrome.browser.tabmodel.TabModel;
...@@ -216,18 +214,6 @@ public class ChromePaymentRequestService ...@@ -216,18 +214,6 @@ public class ChromePaymentRequestService
return activity == null ? null : activity.getCurrentTabModel(); return activity == null ? null : activity.getCurrentTabModel();
} }
/**
* @param webContents Any WebContents.
* @return The OverviewModeBehavior of the given WebContents.
*/
@Nullable
default OverviewModeBehavior getOverviewModeBehavior(WebContents webContents) {
ChromeActivity activity = ChromeActivity.fromWebContents(webContents);
if (activity == null) return null;
if (!(activity instanceof ChromeTabbedActivity)) return null;
return ((ChromeTabbedActivity) activity).getOverviewModeBehaviorSupplier().get();
}
/** /**
* @param webContents Any WebContents. * @param webContents Any WebContents.
* @return The ActivityLifecycleDispatcher of the ChromeActivity that contains the given * @return The ActivityLifecycleDispatcher of the ChromeActivity that contains the given
...@@ -375,7 +361,7 @@ public class ChromePaymentRequestService ...@@ -375,7 +361,7 @@ public class ChromePaymentRequestService
if (tabModel == null) return ErrorStrings.TAB_NOT_FOUND; if (tabModel == null) return ErrorStrings.TAB_NOT_FOUND;
String error = mPaymentUiService.buildPaymentRequestUI( String error = mPaymentUiService.buildPaymentRequestUI(
/*isWebContentsActive=*/mDelegate.isWebContentsActive(mRenderFrameHost), activity, /*isWebContentsActive=*/mDelegate.isWebContentsActive(mRenderFrameHost), activity,
tabModelSelector, tabModel, mDelegate.getOverviewModeBehavior(mWebContents)); tabModelSelector, tabModel);
if (error != null) return error; if (error != null) return error;
// Calculate skip ui and build ui only after all payment apps are ready and // Calculate skip ui and build ui only after all payment apps are ready and
// request.show() is called. // request.show() is called.
......
...@@ -19,9 +19,10 @@ import org.chromium.chrome.browser.autofill.PersonalDataManager; ...@@ -19,9 +19,10 @@ import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard;
import org.chromium.chrome.browser.autofill.PersonalDataManager.NormalizedAddressRequestDelegate; import org.chromium.chrome.browser.autofill.PersonalDataManager.NormalizedAddressRequestDelegate;
import org.chromium.chrome.browser.compositor.layouts.EmptyOverviewModeObserver; import org.chromium.chrome.browser.layouts.LayoutManagerProvider;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior; import org.chromium.chrome.browser.layouts.LayoutStateProvider;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior.OverviewModeObserver; import org.chromium.chrome.browser.layouts.LayoutStateProvider.LayoutStateObserver;
import org.chromium.chrome.browser.layouts.LayoutType;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher; import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.payments.AddressEditor; import org.chromium.chrome.browser.payments.AddressEditor;
import org.chromium.chrome.browser.payments.AutofillAddress; import org.chromium.chrome.browser.payments.AutofillAddress;
...@@ -103,10 +104,10 @@ import java.util.Set; ...@@ -103,10 +104,10 @@ import java.util.Set;
* This class manages all of the UIs related to payment. The UI logic of {@link * This class manages all of the UIs related to payment. The UI logic of {@link
* ChromePaymentRequestService} should be moved into this class. * ChromePaymentRequestService} should be moved into this class.
*/ */
public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Observer, public class PaymentUiService
PaymentHandlerUiObserver, FocusChangedObserver, implements SettingsAutofillAndPaymentsObserver.Observer, PaymentHandlerUiObserver,
PaymentUiServiceTestInterface, FocusChangedObserver, PaymentUiServiceTestInterface,
NormalizedAddressRequestDelegate, PaymentRequestUI.Client { NormalizedAddressRequestDelegate, PaymentRequestUI.Client, LayoutStateObserver {
/** Limit in the number of suggested items in a section. */ /** Limit in the number of suggested items in a section. */
/* package */ static final int SUGGESTIONS_LIMIT = 4; /* package */ static final int SUGGESTIONS_LIMIT = 4;
...@@ -118,7 +119,6 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -118,7 +119,6 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
private final boolean mIsOffTheRecord; private final boolean mIsOffTheRecord;
private final Handler mHandler = new Handler(); private final Handler mHandler = new Handler();
private final Queue<Runnable> mRetryQueue = new LinkedList<>(); private final Queue<Runnable> mRetryQueue = new LinkedList<>();
private final OverviewModeObserver mOverviewModeObserver;
private final TabModelSelectorObserver mSelectorObserver; private final TabModelSelectorObserver mSelectorObserver;
private final TabModelObserver mTabModelObserver; private final TabModelObserver mTabModelObserver;
private ContactEditor mContactEditor; private ContactEditor mContactEditor;
...@@ -150,7 +150,7 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -150,7 +150,7 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
private boolean mCanUserAddCreditCard; private boolean mCanUserAddCreditCard;
private TabModelSelector mObservedTabModelSelector; private TabModelSelector mObservedTabModelSelector;
private TabModel mObservedTabModel; private TabModel mObservedTabModel;
private OverviewModeBehavior mOverviewModeBehavior; private LayoutStateProvider mLayoutStateProvider;
private MinimalUICoordinator mMinimalUi; private MinimalUICoordinator mMinimalUi;
/** The delegate of this class. */ /** The delegate of this class. */
...@@ -328,13 +328,13 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -328,13 +328,13 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
} }
} }
}; };
mOverviewModeObserver = new EmptyOverviewModeObserver() { }
// Implements LayoutStateObserver:
@Override @Override
public void onOverviewModeStartedShowing(boolean showToolbar) { public void onStartedShowing(int layoutType, boolean showToolbar) {
mDelegate.onLeavingCurrentTab(ErrorStrings.TAB_OVERVIEW_MODE); mDelegate.onLeavingCurrentTab(ErrorStrings.TAB_OVERVIEW_MODE);
} }
};
}
/** /**
* Creates the shipping section for the app selector UI if needed. This method should be called * Creates the shipping section for the app selector UI if needed. This method should be called
...@@ -1204,13 +1204,11 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -1204,13 +1204,11 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
* @param activity The activity of the current tab. * @param activity The activity of the current tab.
* @param tabModelSelector The tab model selector of the current tab. * @param tabModelSelector The tab model selector of the current tab.
* @param tabModel The tab model of the current tab. * @param tabModel The tab model of the current tab.
* @param overviewModeBehavior The overview model behaviour of the current tab, can be null.
* @return The error message if built unsuccessfully; null otherwise. * @return The error message if built unsuccessfully; null otherwise.
*/ */
@Nullable @Nullable
public String buildPaymentRequestUI(boolean isWebContentsActive, Activity activity, public String buildPaymentRequestUI(boolean isWebContentsActive, Activity activity,
TabModelSelector tabModelSelector, TabModel tabModel, TabModelSelector tabModelSelector, TabModel tabModel) {
@Nullable OverviewModeBehavior overviewModeBehavior) {
// Payment methods section must be ready before building the rest of the UI. This is because // Payment methods section must be ready before building the rest of the UI. This is because
// shipping and contact sections (when requested by merchant) are populated depending on // shipping and contact sections (when requested by merchant) are populated depending on
// whether or not the selected payment app (if such exists) can provide the required // whether or not the selected payment app (if such exists) can provide the required
...@@ -1220,7 +1218,6 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -1220,7 +1218,6 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
assert activity != null; assert activity != null;
assert tabModelSelector != null; assert tabModelSelector != null;
assert tabModel != null; assert tabModel != null;
assert overviewModeBehavior != null;
// Only the currently selected tab is allowed to show the payment UI. // Only the currently selected tab is allowed to show the payment UI.
if (!isWebContentsActive) return ErrorStrings.CANNOT_SHOW_IN_BACKGROUND_TAB; if (!isWebContentsActive) return ErrorStrings.CANNOT_SHOW_IN_BACKGROUND_TAB;
...@@ -1241,15 +1238,17 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -1241,15 +1238,17 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
mObservedTabModel.addObserver(mTabModelObserver); mObservedTabModel.addObserver(mTabModelObserver);
// Catch any time the user enters the overview mode and dismiss the payment UI. // Catch any time the user enters the overview mode and dismiss the payment UI.
if (overviewModeBehavior != null) { LayoutStateProvider layoutStateProvider =
if (mOverviewModeBehavior != null) { LayoutManagerProvider.from(mWebContents.getTopLevelNativeWindow());
mOverviewModeBehavior.removeOverviewModeObserver(mOverviewModeObserver); if (layoutStateProvider != null) {
if (mLayoutStateProvider != null) {
mLayoutStateProvider.removeObserver(this);
} }
mOverviewModeBehavior = overviewModeBehavior; if (layoutStateProvider.isLayoutVisible(LayoutType.TAB_SWITCHER)) {
return ErrorStrings.TAB_OVERVIEW_MODE;
assert mOverviewModeBehavior != null; }
if (mOverviewModeBehavior.overviewVisible()) return ErrorStrings.TAB_OVERVIEW_MODE; mLayoutStateProvider = layoutStateProvider;
mOverviewModeBehavior.addOverviewModeObserver(mOverviewModeObserver); mLayoutStateProvider.addObserver(this);
} }
if (shouldShowContactSection()) { if (shouldShowContactSection()) {
...@@ -1537,9 +1536,9 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -1537,9 +1536,9 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
mObservedTabModel = null; mObservedTabModel = null;
} }
if (mOverviewModeBehavior != null) { if (mLayoutStateProvider != null) {
mOverviewModeBehavior.removeOverviewModeObserver(mOverviewModeObserver); mLayoutStateProvider.removeObserver(this);
mOverviewModeBehavior = null; mLayoutStateProvider = null;
} }
} }
......
...@@ -24,8 +24,8 @@ public class MockPaymentUiServiceBuilder { ...@@ -24,8 +24,8 @@ public class MockPaymentUiServiceBuilder {
mPaymentUiService = Mockito.mock(PaymentUiService.class); mPaymentUiService = Mockito.mock(PaymentUiService.class);
Mockito.doReturn(null) Mockito.doReturn(null)
.when(mPaymentUiService) .when(mPaymentUiService)
.buildPaymentRequestUI(Mockito.anyBoolean(), Mockito.any(), Mockito.any(), .buildPaymentRequestUI(
Mockito.any(), Mockito.any()); Mockito.anyBoolean(), Mockito.any(), Mockito.any(), Mockito.any());
Mockito.doReturn(true).when(mPaymentUiService).hasAvailableApps(); Mockito.doReturn(true).when(mPaymentUiService).hasAvailableApps();
List<PaymentApp> apps = new ArrayList<>(); List<PaymentApp> apps = new ArrayList<>();
apps.add(app); apps.add(app);
...@@ -36,8 +36,8 @@ public class MockPaymentUiServiceBuilder { ...@@ -36,8 +36,8 @@ public class MockPaymentUiServiceBuilder {
/* package */ MockPaymentUiServiceBuilder setBuildPaymentRequestUIResult(String result) { /* package */ MockPaymentUiServiceBuilder setBuildPaymentRequestUIResult(String result) {
Mockito.doReturn(result) Mockito.doReturn(result)
.when(mPaymentUiService) .when(mPaymentUiService)
.buildPaymentRequestUI(Mockito.anyBoolean(), Mockito.any(), Mockito.any(), .buildPaymentRequestUI(
Mockito.any(), Mockito.any()); Mockito.anyBoolean(), Mockito.any(), Mockito.any(), Mockito.any());
return this; return this;
} }
......
...@@ -12,7 +12,6 @@ import androidx.annotation.Nullable; ...@@ -12,7 +12,6 @@ import androidx.annotation.Nullable;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher; import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.payments.ui.PaymentUiService; import org.chromium.chrome.browser.payments.ui.PaymentUiService;
import org.chromium.chrome.browser.tabmodel.TabModel; import org.chromium.chrome.browser.tabmodel.TabModel;
...@@ -210,12 +209,6 @@ public class PaymentRequestParamsBuilder implements ChromePaymentRequestService. ...@@ -210,12 +209,6 @@ public class PaymentRequestParamsBuilder implements ChromePaymentRequestService.
return Mockito.mock(TabModel.class); return Mockito.mock(TabModel.class);
} }
@Nullable
@Override
public OverviewModeBehavior getOverviewModeBehavior(WebContents webContents) {
return Mockito.mock(OverviewModeBehavior.class);
}
@Nullable @Nullable
@Override @Override
public ActivityLifecycleDispatcher getActivityLifecycleDispatcher(WebContents webContents) { public ActivityLifecycleDispatcher getActivityLifecycleDispatcher(WebContents webContents) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment