Commit 59b9c7b1 authored by Sahel Sharify's avatar Sahel Sharify Committed by Commit Bot

[Payments][Android] PR's spec should not get used after PR closure.

Bug: 1130343
Change-Id: I07031ec0347d86abcc2c0cd7cc10ba09627bd8ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2422783Reviewed-by: default avatarLiquan (Max) Gu <maxlg@chromium.org>
Commit-Queue: Sahel Sharify <sahel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810614}
parent d087cfbd
......@@ -191,11 +191,11 @@ public class AndroidPaymentAppFinder implements ManifestVerifyCallback {
}
private void findAppStoreBillingApp(List<ResolveInfo> allInstalledPaymentApps) {
assert !mFactoryDelegate.getParams().hasClosed();
String twaPackageName = mFactoryDelegate.getParams().getTwaPackageName();
if (TextUtils.isEmpty(twaPackageName)) return;
ResolveInfo twaApp = findAppWithPackageName(allInstalledPaymentApps, twaPackageName);
if (twaApp == null) return;
List<String> agreedAppStoreMethods = new ArrayList<>();
for (GURL appStoreUriMethod : mAppStores.values()) {
assert appStoreUriMethod != null;
......@@ -256,6 +256,7 @@ public class AndroidPaymentAppFinder implements ManifestVerifyCallback {
* that the merchant is using.
*/
/* package */ void findAndroidPaymentApps() {
if (mFactoryDelegate.getParams().hasClosed()) return;
// For non-URL payment method names, only names published by W3C should be supported. Keep
// this in sync with manifest_verifier.cc.
Set<String> supportedNonUriPaymentMethods = new HashSet<>();
......@@ -580,7 +581,7 @@ public class AndroidPaymentAppFinder implements ManifestVerifyCallback {
assert mPendingVerifiersCount == 0;
mFactoryDelegate.onCanMakePaymentCalculated(mValidApps.size() > 0);
if (mValidApps.isEmpty()) {
if (mValidApps.isEmpty() || mFactoryDelegate.getParams().hasClosed()) {
mFactoryDelegate.onDoneCreatingPaymentApps(mFactory);
return;
}
......@@ -642,6 +643,7 @@ public class AndroidPaymentAppFinder implements ManifestVerifyCallback {
* @param methodName The method name that can be used by the app.
*/
private void onValidPaymentAppForPaymentMethodName(ResolveInfo resolveInfo, String methodName) {
if (mFactoryDelegate.getParams().hasClosed()) return;
String packageName = resolveInfo.activityInfo.packageName;
SupportedDelegations appSupportedDelegations =
......
......@@ -56,7 +56,9 @@ public class AutofillPaymentAppFactory implements PaymentAppFactoryInterface {
/** @return Whether can make payments with basic card. */
private boolean createPaymentApps() {
if (!mDelegate.getParams().getMethodData().containsKey(MethodStrings.BASIC_CARD)) {
if (mDelegate.getParams().hasClosed()
|| !mDelegate.getParams().getMethodData().containsKey(
MethodStrings.BASIC_CARD)) {
return false;
}
......@@ -85,7 +87,7 @@ public class AutofillPaymentAppFactory implements PaymentAppFactoryInterface {
@Override
@Nullable
public PaymentApp createPaymentAppForCard(CreditCard card) {
if (!mCanMakePayment) return null;
if (!mCanMakePayment || mDelegate.getParams().hasClosed()) return null;
if (!mNetworks.contains(card.getBasicCardIssuerNetwork())) return null;
......@@ -127,6 +129,11 @@ public class AutofillPaymentAppFactory implements PaymentAppFactoryInterface {
return methodData;
}
@Override
public boolean hasClosed() {
return false;
}
@Override
public RenderFrameHost getRenderFrameHost() {
// AutofillPaymentAppFactory.Creator doesn't need RenderFrameHost.
......
......@@ -35,6 +35,7 @@ public class PaymentAppServiceBridge implements PaymentAppFactoryInterface {
// PaymentAppFactoryInterface implementation.
@Override
public void create(PaymentAppFactoryDelegate delegate) {
if (delegate.getParams().hasClosed()) return;
assert delegate.getParams().getPaymentRequestOrigin().equals(
UrlFormatter.formatUrlForSecurityDisplay(
delegate.getParams().getRenderFrameHost().getLastCommittedURL()));
......
......@@ -1304,19 +1304,26 @@ public class PaymentRequestImpl
return mRenderFrameHost;
}
// PaymentAppFactoryParams implementation.
@Override
public boolean hasClosed() {
return mHasClosed;
}
// PaymentAppFactoryParams implementation.
@Override
public Map<String, PaymentMethodData> getMethodData() {
// TODO(crbug.com/1130343): This should only get called while mSpec is not destroyed.
// uncomment the following assertion after fixing the issue.
// assert !mSpec.isDestroyed();
return mSpec.isDestroyed() ? new ArrayMap<String, PaymentMethodData>()
: mSpec.getMethodData();
// GetMethodData should not get called after PR is closed.
assert !mHasClosed;
assert !mSpec.isDestroyed();
return mSpec.getMethodData();
}
// PaymentAppFactoryParams implementation.
@Override
public String getId() {
assert !mHasClosed;
assert !mSpec.isDestroyed();
return mSpec.getId();
}
......@@ -1348,12 +1355,16 @@ public class PaymentRequestImpl
// PaymentAppFactoryParams implementation.
@Override
public Map<String, PaymentDetailsModifier> getUnmodifiableModifiers() {
assert !mHasClosed;
assert !mSpec.isDestroyed();
return Collections.unmodifiableMap(mSpec.getModifiers());
}
// PaymentAppFactoryParams implementation.
@Override
public PaymentItem getRawTotal() {
assert !mHasClosed;
assert !mSpec.isDestroyed();
return mSpec.getRawTotal();
}
......
......@@ -233,6 +233,7 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
public PaymentUIsManager(Delegate delegate, PaymentRequestParams params,
WebContents webContents, boolean isOffTheRecord, JourneyLogger journeyLogger,
String topLevelOrigin, PaymentUIsObserver observer) {
assert !params.hasClosed();
mDelegate = delegate;
mParams = params;
......@@ -560,6 +561,7 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
// Implement PaymentRequestLifecycleObserver:
@Override
public void onPaymentRequestParamsInitiated(PaymentRequestParams params) {
assert !params.hasClosed();
for (PaymentMethodData method : params.getMethodData().values()) {
mCardEditor.addAcceptedPaymentMethodIfRecognized(method);
}
......@@ -685,7 +687,7 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
/** Sets the modifier for the order summary based on the given app, if any. */
public void updateOrderSummary(@Nullable PaymentApp app) {
if (!PaymentFeatureList.isEnabled(PaymentFeatureList.WEB_PAYMENTS_MODIFIERS)) return;
if (mParams.hasClosed()) return;
PaymentDetailsModifier modifier = getModifier(app);
PaymentItem total = modifier == null ? null : modifier.total;
if (total == null) total = mParams.getRawTotal();
......@@ -704,6 +706,7 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
/** @return The first modifier that matches the given app, or null. */
@Nullable
private PaymentDetailsModifier getModifier(@Nullable PaymentApp app) {
if (mParams.hasClosed()) return null;
Map<String, PaymentDetailsModifier> modifiers = mParams.getUnmodifiableModifiers();
if (modifiers.isEmpty() || app == null) return null;
// Makes a copy to ensure it is modifiable.
......@@ -724,7 +727,7 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
/** Updates the modifiers for payment apps and order summary. */
public void updateAppModifiedTotals() {
if (!PaymentFeatureList.isEnabled(PaymentFeatureList.WEB_PAYMENTS_MODIFIERS)) return;
if (mParams.getMethodData().isEmpty()) return;
if (mParams.hasClosed() || mParams.getMethodData().isEmpty()) return;
if (mPaymentMethodsSection == null) return;
for (int i = 0; i < mPaymentMethodsSection.getSize(); i++) {
......@@ -888,7 +891,7 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
/** Implements {@link PaymentRequestUI.Client.shouldShowShippingSection}. */
public boolean shouldShowShippingSection() {
if (!mParams.getPaymentOptions().requestShipping) return false;
if (mParams.hasClosed() || !mParams.getPaymentOptions().requestShipping) return false;
if (mPaymentMethodsSection == null) return true;
......@@ -901,6 +904,7 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
PaymentApp selectedApp = (mPaymentMethodsSection == null)
? null
: (PaymentApp) mPaymentMethodsSection.getSelectedItem();
if (mParams.hasClosed()) return false;
PaymentOptions options = mParams.getPaymentOptions();
if (options.requestPayerName && (selectedApp == null || !selectedApp.handlesPayerName())) {
return true;
......@@ -1102,6 +1106,8 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
// Only the currently selected tab is allowed to show the payment UI.
if (!isWebContentsActive) return ErrorStrings.CANNOT_SHOW_IN_BACKGROUND_TAB;
if (mParams.hasClosed()) return ErrorStrings.PAYMENT_REQUEST_IS_ABORTING;
// Catch any time the user switches tabs. Because the dialog is modal, a user shouldn't be
// allowed to switch tabs, which can happen if the user receives an external Intent.
if (mObservedTabModelSelector != null) {
......@@ -1394,6 +1400,7 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
public boolean onlySingleAppCanProvideAllRequiredInformation() {
assert mPaymentMethodsSection != null;
if (mParams.hasClosed()) return false;
if (!PaymentOptionsUtils.requestAnyInformation(mParams.getPaymentOptions())) {
return mPaymentMethodsSection.getSize() == 1
&& !((PaymentApp) mPaymentMethodsSection.getItem(0)).isAutofillInstrument();
......
......@@ -118,6 +118,12 @@ public class AndroidPaymentAppFinderTest
return this;
}
// PaymentAppFactoryDelegate implementation.
@Override
public boolean hasClosed() {
return false;
}
// PaymentAppFactoryDelegate implementation.
@Override
public void onPaymentAppCreated(PaymentApp paymentApp) {
......
......@@ -15,6 +15,12 @@ import java.util.Map;
* The parameters of PaymentRequest specified by the merchant.
*/
public interface PaymentRequestParams {
/**
* @return Whether or not the payment request is being aborted. Other methods should not get
* called when the payment request is being aborted.
*/
boolean hasClosed();
/** @return The PaymentOptions set by the merchant. */
PaymentOptions getPaymentOptions();
......
......@@ -39,6 +39,8 @@ public abstract class ErrorStrings {{
public static final String PAYMENT_APP_PRIVATE_ACTIVITY =
"Payment app does not have android:exported=\"true\" on the PAY activity.";
public static final String PAYMENT_REQUEST_IS_ABORTING = "Payment request is aborting.";
public static final String MISSING_INTENT_DATA =
"Payment app returned an invalid result. Missing intent data.";
......
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