Commit 084fb967 authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Commit Bot

[WebLayer] Remove PaymentUIsObserver

PaymentUIsObserver plays the same role as PaymentUiService#Delegate
and so should be merged into one. This CL moves the PaymentUIsObserver
methods into PaymentUiService#Delegate without any change.

Bug: 1025619

Change-Id: I6e951168c7ed9c0e3459e55671aec9cbb69742da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2536992
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827830}
parent 544aab82
...@@ -37,7 +37,6 @@ import org.chromium.components.payments.PaymentRequestService; ...@@ -37,7 +37,6 @@ import org.chromium.components.payments.PaymentRequestService;
import org.chromium.components.payments.PaymentRequestServiceUtil; import org.chromium.components.payments.PaymentRequestServiceUtil;
import org.chromium.components.payments.PaymentRequestSpec; import org.chromium.components.payments.PaymentRequestSpec;
import org.chromium.components.payments.PaymentResponseHelperInterface; import org.chromium.components.payments.PaymentResponseHelperInterface;
import org.chromium.components.payments.PaymentUIsObserver;
import org.chromium.components.payments.Section; import org.chromium.components.payments.Section;
import org.chromium.components.payments.SkipToGPayHelper; import org.chromium.components.payments.SkipToGPayHelper;
import org.chromium.content_public.browser.RenderFrameHost; import org.chromium.content_public.browser.RenderFrameHost;
...@@ -65,9 +64,8 @@ import java.util.Set; ...@@ -65,9 +64,8 @@ import java.util.Set;
* This is the Clank specific parts of {@link PaymentRequest}, with the parts shared with WebLayer * This is the Clank specific parts of {@link PaymentRequest}, with the parts shared with WebLayer
* living in {@link PaymentRequestService}. * living in {@link PaymentRequestService}.
*/ */
public class ChromePaymentRequestService implements BrowserPaymentRequest, public class ChromePaymentRequestService
PaymentUiService.Delegate, PaymentUIsObserver { implements BrowserPaymentRequest, PaymentUiService.Delegate {
// Null-check is necessary because retainers of ChromePaymentRequestService could still // Null-check is necessary because retainers of ChromePaymentRequestService could still
// reference ChromePaymentRequestService after mPaymentRequestService is set null, e.g., // reference ChromePaymentRequestService after mPaymentRequestService is set null, e.g.,
// crbug.com/1122148. // crbug.com/1122148.
...@@ -130,8 +128,7 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest, ...@@ -130,8 +128,7 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest,
mPaymentRequestService = paymentRequestService; mPaymentRequestService = paymentRequestService;
mPaymentUiService = new PaymentUiService(/*delegate=*/this, mPaymentUiService = new PaymentUiService(/*delegate=*/this,
/*params=*/mPaymentRequestService, mWebContents, /*params=*/mPaymentRequestService, mWebContents,
paymentRequestService.isOffTheRecord(), mJourneyLogger, topLevelOrigin, paymentRequestService.isOffTheRecord(), mJourneyLogger, topLevelOrigin);
/*observer=*/this);
if (PaymentRequestService.getNativeObserverForTest() != null) { if (PaymentRequestService.getNativeObserverForTest() != null) {
PaymentRequestService.getNativeObserverForTest().onPaymentUiServiceCreated( PaymentRequestService.getNativeObserverForTest().onPaymentUiServiceCreated(
mPaymentUiService); mPaymentUiService);
...@@ -812,21 +809,21 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest, ...@@ -812,21 +809,21 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest,
mPaymentRequestService.onPayerDetailChange(detail); mPaymentRequestService.onPayerDetailChange(detail);
} }
// Implement PaymentUIsObserver: // Implement PaymentUiService.Delegate:
@Override @Override
public void onPaymentRequestUIFaviconNotAvailable() { public void onPaymentRequestUIFaviconNotAvailable() {
if (mPaymentRequestService == null) return; if (mPaymentRequestService == null) return;
mPaymentRequestService.warnNoFavicon(); mPaymentRequestService.warnNoFavicon();
} }
// Implement PaymentUIsObserver: // Implement PaymentUiService.Delegate:
@Override @Override
public void onShippingOptionChange(String optionId) { public void onShippingOptionChange(String optionId) {
if (mPaymentRequestService == null) return; if (mPaymentRequestService == null) return;
mPaymentRequestService.onShippingOptionChange(optionId); mPaymentRequestService.onShippingOptionChange(optionId);
} }
// Implement PaymentUIsObserver.onLeavingCurrentTab: // Implement PaymentUiService.Delegate:
@Override @Override
public void onLeavingCurrentTab(String reason) { public void onLeavingCurrentTab(String reason) {
if (mPaymentRequestService == null) return; if (mPaymentRequestService == null) return;
...@@ -834,7 +831,7 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest, ...@@ -834,7 +831,7 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest,
disconnectFromClientWithDebugMessage(reason); disconnectFromClientWithDebugMessage(reason);
} }
// Implement PaymentUIsObserver: // Implement PaymentUiService.Delegate:
@Override @Override
public void onUiServiceError(String error) { public void onUiServiceError(String error) {
mJourneyLogger.setAborted(AbortReason.OTHER); mJourneyLogger.setAborted(AbortReason.OTHER);
...@@ -844,7 +841,7 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest, ...@@ -844,7 +841,7 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest,
} }
} }
// Implement PaymentUIsObserver: // Implement PaymentUiService.Delegate:
@Override @Override
public void onShippingAddressChange(PaymentAddress address) { public void onShippingAddressChange(PaymentAddress address) {
if (mPaymentRequestService == null) return; if (mPaymentRequestService == null) return;
......
...@@ -64,7 +64,6 @@ import org.chromium.components.payments.PaymentDetailsUpdateServiceHelper; ...@@ -64,7 +64,6 @@ import org.chromium.components.payments.PaymentDetailsUpdateServiceHelper;
import org.chromium.components.payments.PaymentFeatureList; import org.chromium.components.payments.PaymentFeatureList;
import org.chromium.components.payments.PaymentOptionsUtils; import org.chromium.components.payments.PaymentOptionsUtils;
import org.chromium.components.payments.PaymentRequestParams; import org.chromium.components.payments.PaymentRequestParams;
import org.chromium.components.payments.PaymentUIsObserver;
import org.chromium.components.payments.PaymentUiServiceTestInterface; import org.chromium.components.payments.PaymentUiServiceTestInterface;
import org.chromium.components.payments.Section; import org.chromium.components.payments.Section;
import org.chromium.components.security_state.SecurityStateModel; import org.chromium.components.security_state.SecurityStateModel;
...@@ -132,10 +131,8 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -132,10 +131,8 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
private final PaymentUisShowStateReconciler mPaymentUisShowStateReconciler; private final PaymentUisShowStateReconciler mPaymentUisShowStateReconciler;
private final PaymentRequestParams mParams; private final PaymentRequestParams mParams;
private final JourneyLogger mJourneyLogger; private final JourneyLogger mJourneyLogger;
private final PaymentUIsObserver mObserver;
private PaymentRequestUI mPaymentRequestUI; private PaymentRequestUI mPaymentRequestUI;
private ShoppingCart mUiShoppingCart; private ShoppingCart mUiShoppingCart;
private boolean mMerchantSupportsAutofillCards; private boolean mMerchantSupportsAutofillCards;
private boolean mHasInitialized; private boolean mHasInitialized;
...@@ -192,6 +189,36 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -192,6 +189,36 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
* @param debugMessage The debug message for the aborting. * @param debugMessage The debug message for the aborting.
*/ */
void onUiAborted(@AbortReason int reason, String debugMessage); void onUiAborted(@AbortReason int reason, String debugMessage);
/** Called when favicon not available for payment request UI. */
void onPaymentRequestUIFaviconNotAvailable();
/**
* Called when the user is leaving the current tab (e.g., tab switched or tab overview mode
* is shown), upon which the PaymentRequest service should be closed.
* @param reason The reason of leaving the current tab, to be used as debug message for the
* developers.
*/
void onLeavingCurrentTab(String reason);
/**
* Called when the user's selected shipping option has changed.
* @param optionId The option id of the selected shipping option.
*/
void onShippingOptionChange(String optionId);
/**
* Called when the shipping address has changed by the user.
* @param address The changed shipping address.
*/
void onShippingAddressChange(org.chromium.payments.mojom.PaymentAddress address);
/**
* Called when the Payment UI service quits with an error. The observer should stop
* referencing the Payment UI service.
* @param error The diagnostic message that's exposed to developers.
*/
void onUiServiceError(String error);
} }
/** /**
...@@ -247,7 +274,7 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -247,7 +274,7 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
boolean isSuccess = boolean isSuccess =
mPaymentRequestUI.setVisible(!mShowingBottomSheet && mShouldShowDialog); mPaymentRequestUI.setVisible(!mShowingBottomSheet && mShouldShowDialog);
if (!isSuccess) { if (!isSuccess) {
mObserver.onUiServiceError(ErrorStrings.FAIL_TO_SHOW_PAYMENT_REQUEST_UI); mDelegate.onUiServiceError(ErrorStrings.FAIL_TO_SHOW_PAYMENT_REQUEST_UI);
} }
} }
} }
...@@ -259,11 +286,9 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -259,11 +286,9 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
* @param isOffTheRecord Whether merchant page is in an isOffTheRecord tab. * @param isOffTheRecord Whether merchant page is in an isOffTheRecord tab.
* @param journeyLogger The logger of the user journey. * @param journeyLogger The logger of the user journey.
* @param topLevelOrigin The last committed url of webContents. * @param topLevelOrigin The last committed url of webContents.
* @param observer The payment UIs observer.
*/ */
public PaymentUiService(Delegate delegate, PaymentRequestParams params, WebContents webContents, public PaymentUiService(Delegate delegate, PaymentRequestParams params, WebContents webContents,
boolean isOffTheRecord, JourneyLogger journeyLogger, String topLevelOrigin, boolean isOffTheRecord, JourneyLogger journeyLogger, String topLevelOrigin) {
PaymentUIsObserver observer) {
assert !params.hasClosed(); assert !params.hasClosed();
mDelegate = delegate; mDelegate = delegate;
mParams = params; mParams = params;
...@@ -283,25 +308,24 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -283,25 +308,24 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
mCurrencyFormatterMap = new HashMap<>(); mCurrencyFormatterMap = new HashMap<>();
mIsOffTheRecord = isOffTheRecord; mIsOffTheRecord = isOffTheRecord;
mPaymentAppComparator = new PaymentAppComparator(/*params=*/mParams); mPaymentAppComparator = new PaymentAppComparator(/*params=*/mParams);
mObserver = observer;
mSelectorObserver = new EmptyTabModelSelectorObserver() { mSelectorObserver = new EmptyTabModelSelectorObserver() {
@Override @Override
public void onTabModelSelected(TabModel newModel, TabModel oldModel) { public void onTabModelSelected(TabModel newModel, TabModel oldModel) {
mObserver.onLeavingCurrentTab(ErrorStrings.TAB_SWITCH); mDelegate.onLeavingCurrentTab(ErrorStrings.TAB_SWITCH);
} }
}; };
mTabModelObserver = new TabModelObserver() { mTabModelObserver = new TabModelObserver() {
@Override @Override
public void didSelectTab(Tab tab, @TabSelectionType int type, int lastId) { public void didSelectTab(Tab tab, @TabSelectionType int type, int lastId) {
if (tab == null || tab.getId() != lastId) { if (tab == null || tab.getId() != lastId) {
mObserver.onLeavingCurrentTab(ErrorStrings.TAB_SWITCH); mDelegate.onLeavingCurrentTab(ErrorStrings.TAB_SWITCH);
} }
} }
}; };
mOverviewModeObserver = new EmptyOverviewModeObserver() { mOverviewModeObserver = new EmptyOverviewModeObserver() {
@Override @Override
public void onOverviewModeStartedShowing(boolean showToolbar) { public void onOverviewModeStartedShowing(boolean showToolbar) {
mObserver.onLeavingCurrentTab(ErrorStrings.TAB_OVERVIEW_MODE); mDelegate.onLeavingCurrentTab(ErrorStrings.TAB_OVERVIEW_MODE);
} }
}; };
} }
...@@ -1148,7 +1172,7 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -1148,7 +1172,7 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
activity.getResources().getDimensionPixelSize(R.dimen.payments_favicon_size), activity.getResources().getDimensionPixelSize(R.dimen.payments_favicon_size),
(bitmap, iconUrl) -> { (bitmap, iconUrl) -> {
if (bitmap == null) { if (bitmap == null) {
mObserver.onPaymentRequestUIFaviconNotAvailable(); mDelegate.onPaymentRequestUIFaviconNotAvailable();
} }
if (mPaymentRequestUI != null && bitmap != null) { if (mPaymentRequestUI != null && bitmap != null) {
mPaymentRequestUI.setTitleBitmap(bitmap); mPaymentRequestUI.setTitleBitmap(bitmap);
...@@ -1548,7 +1572,7 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -1548,7 +1572,7 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
} else if (optionType == PaymentRequestUI.DataType.SHIPPING_OPTIONS) { } else if (optionType == PaymentRequestUI.DataType.SHIPPING_OPTIONS) {
// This may update the line items. // This may update the line items.
mUiShippingOptions.setSelectedItem(option); mUiShippingOptions.setSelectedItem(option);
mObserver.onShippingOptionChange(option.getIdentifier()); mDelegate.onShippingOptionChange(option.getIdentifier());
mPaymentInformationCallback = callback; mPaymentInformationCallback = callback;
return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION; return PaymentRequestUI.SelectionResult.ASYNCHRONOUS_VALIDATION;
} else if (optionType == PaymentRequestUI.DataType.CONTACT_DETAILS) { } else if (optionType == PaymentRequestUI.DataType.CONTACT_DETAILS) {
...@@ -1619,13 +1643,13 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -1619,13 +1643,13 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
// Can happen if the tab is closed during the normalization process. // Can happen if the tab is closed during the normalization process.
if (chromeActivity == null) { if (chromeActivity == null) {
mObserver.onUiServiceError(ErrorStrings.ACTIVITY_NOT_FOUND); mDelegate.onUiServiceError(ErrorStrings.ACTIVITY_NOT_FOUND);
return; return;
} }
// Don't reuse the selected address because it is formatted for display. // Don't reuse the selected address because it is formatted for display.
AutofillAddress shippingAddress = new AutofillAddress(chromeActivity, profile); AutofillAddress shippingAddress = new AutofillAddress(chromeActivity, profile);
mObserver.onShippingAddressChange(shippingAddress.toPaymentAddress()); mDelegate.onShippingAddressChange(shippingAddress.toPaymentAddress());
} }
// Implements PersonalDataManager.NormalizedAddressRequestDelegate: // Implements PersonalDataManager.NormalizedAddressRequestDelegate:
......
...@@ -134,7 +134,6 @@ android_library("all_java") { ...@@ -134,7 +134,6 @@ android_library("all_java") {
"java/src/org/chromium/components/payments/PaymentRequestServiceUtil.java", "java/src/org/chromium/components/payments/PaymentRequestServiceUtil.java",
"java/src/org/chromium/components/payments/PaymentRequestSpec.java", "java/src/org/chromium/components/payments/PaymentRequestSpec.java",
"java/src/org/chromium/components/payments/PaymentResponseHelperInterface.java", "java/src/org/chromium/components/payments/PaymentResponseHelperInterface.java",
"java/src/org/chromium/components/payments/PaymentUIsObserver.java",
"java/src/org/chromium/components/payments/PaymentUiServiceTestInterface.java", "java/src/org/chromium/components/payments/PaymentUiServiceTestInterface.java",
"java/src/org/chromium/components/payments/PaymentValidator.java", "java/src/org/chromium/components/payments/PaymentValidator.java",
"java/src/org/chromium/components/payments/SkipToGPayHelper.java", "java/src/org/chromium/components/payments/SkipToGPayHelper.java",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.components.payments;
import org.chromium.payments.mojom.PaymentAddress;
/** Interface for observing payment UIs. */
public interface PaymentUIsObserver {
/** Called when favicon not available for payment request UI. */
void onPaymentRequestUIFaviconNotAvailable();
/**
* Called when the user is leaving the current tab (e.g., tab switched or tab overview mode is
* shown), upon which the PaymentRequest service should be closed.
* @param reason The reason of leaving the current tab, to be used as debug message for the
* developers.
*/
void onLeavingCurrentTab(String reason);
/**
* Called when the user's selected shipping option has changed.
* @param optionId The option id of the selected shipping option.
*/
void onShippingOptionChange(String optionId);
/**
* Called when the shipping address has changed by the user.
* @param address The changed shipping address.
*/
void onShippingAddressChange(PaymentAddress address);
/**
* Called when the Payment UI service quits with an error. The observer should stop referencing
* the Payment UI service.
* @param error The diagnostic message that's exposed to developers.
*/
void onUiServiceError(String error);
}
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