Commit 72c29544 authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Commit Bot

[PRImpl] Assert mMerchantSupportsAutofillCards != null

After crrev.com/c/2372888, all cases of mMerchantSupportsAutofillCards
are accessed after defined, we can limit that it's used only after it's
not null.

Bug: 1107039

Change-Id: Iea978142c9a9e7d755cb294d9acf3eff80f13d5a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2388561
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarSahel Sharify <sahel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804069}
parent ede900bb
...@@ -1828,11 +1828,7 @@ public class PaymentRequestImpl ...@@ -1828,11 +1828,7 @@ public class PaymentRequestImpl
int missingFields = 0; int missingFields = 0;
if (mPendingApps.isEmpty()) { if (mPendingApps.isEmpty()) {
// TODO(crbug.com/1107039): This value could be null when this method is entered from if (mPaymentUIsManager.merchantSupportsAutofillCards()) {
// PaymentRequest#init. We should turn it into boolean after correcting this bug.
Boolean merchantSupportsAutofillCards =
mPaymentUIsManager.merchantSupportsAutofillCards();
if (merchantSupportsAutofillCards != null && merchantSupportsAutofillCards) {
// Record all fields if basic-card is supported but no card exists. // Record all fields if basic-card is supported but no card exists.
missingFields = AutofillPaymentInstrument.CompletionStatus.CREDIT_CARD_EXPIRED missingFields = AutofillPaymentInstrument.CompletionStatus.CREDIT_CARD_EXPIRED
| AutofillPaymentInstrument.CompletionStatus.CREDIT_CARD_NO_CARDHOLDER | AutofillPaymentInstrument.CompletionStatus.CREDIT_CARD_NO_CARDHOLDER
......
...@@ -111,14 +111,15 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob ...@@ -111,14 +111,15 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
private PaymentRequestUI mPaymentRequestUI; private PaymentRequestUI mPaymentRequestUI;
private ShoppingCart mUiShoppingCart; private ShoppingCart mUiShoppingCart;
private Boolean mMerchantSupportsAutofillCards; private boolean mMerchantSupportsAutofillCards;
private boolean mIsPaymentRequestParamsInitiated;
private SectionInformation mPaymentMethodsSection; private SectionInformation mPaymentMethodsSection;
private SectionInformation mShippingAddressesSection; private SectionInformation mShippingAddressesSection;
private ContactDetailsSection mContactSection; private ContactDetailsSection mContactSection;
private AutofillPaymentAppCreator mAutofillPaymentAppCreator; private AutofillPaymentAppCreator mAutofillPaymentAppCreator;
private boolean mHaveRequestedAutofillData = true; private boolean mHaveRequestedAutofillData = true;
private List<AutofillProfile> mAutofillProfiles; private List<AutofillProfile> mAutofillProfiles;
private Boolean mCanUserAddCreditCard; private boolean mCanUserAddCreditCard;
private final JourneyLogger mJourneyLogger; private final JourneyLogger mJourneyLogger;
private PaymentUIsObserver mObserver; private PaymentUIsObserver mObserver;
...@@ -255,11 +256,12 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob ...@@ -255,11 +256,12 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
return mCardEditor; return mCardEditor;
} }
/** @return Whether the merchant supports autofill cards. */ /**
@Nullable * @return Whether the merchant supports autofill cards. It can be used only after
public Boolean merchantSupportsAutofillCards() { * onPaymentRequestParamsInitiated() is invoked.
// TODO(crbug.com/1107039): this value should be asserted not null to avoid being used */
// before defined, after this bug is fixed. public boolean merchantSupportsAutofillCards() {
assert mIsPaymentRequestParamsInitiated;
return mMerchantSupportsAutofillCards; return mMerchantSupportsAutofillCards;
} }
...@@ -293,9 +295,12 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob ...@@ -293,9 +295,12 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
mAutofillPaymentAppCreator = autofillPaymentAppCreator; mAutofillPaymentAppCreator = autofillPaymentAppCreator;
} }
/** @return Whether user can add credit card. */ /**
* @return Whether user can add credit card. It can be used only after
* onPaymentRequestParamsInitiated() is invoked.
*/
public boolean canUserAddCreditCard() { public boolean canUserAddCreditCard() {
assert mCanUserAddCreditCard != null; assert mIsPaymentRequestParamsInitiated;
return mCanUserAddCreditCard; return mCanUserAddCreditCard;
} }
...@@ -379,7 +384,7 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob ...@@ -379,7 +384,7 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
// Implement SettingsAutofillAndPaymentsObserver.Observer: // Implement SettingsAutofillAndPaymentsObserver.Observer:
@Override @Override
public void onCreditCardUpdated(CreditCard card) { public void onCreditCardUpdated(CreditCard card) {
assert mMerchantSupportsAutofillCards != null; assert mIsPaymentRequestParamsInitiated;
if (!mMerchantSupportsAutofillCards || mPaymentMethodsSection == null if (!mMerchantSupportsAutofillCards || mPaymentMethodsSection == null
|| mAutofillPaymentAppCreator == null) { || mAutofillPaymentAppCreator == null) {
return; return;
...@@ -405,7 +410,7 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob ...@@ -405,7 +410,7 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
// Implement SettingsAutofillAndPaymentsObserver.Observer: // Implement SettingsAutofillAndPaymentsObserver.Observer:
@Override @Override
public void onCreditCardDeleted(String guid) { public void onCreditCardDeleted(String guid) {
assert mMerchantSupportsAutofillCards != null; assert mIsPaymentRequestParamsInitiated;
if (!mMerchantSupportsAutofillCards || mPaymentMethodsSection == null) return; if (!mMerchantSupportsAutofillCards || mPaymentMethodsSection == null) return;
mPaymentMethodsSection.removeAndUnselectItem(guid); mPaymentMethodsSection.removeAndUnselectItem(guid);
...@@ -469,6 +474,7 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob ...@@ -469,6 +474,7 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
} }
mHaveRequestedAutofillData &= haveCompleteContactInfo; mHaveRequestedAutofillData &= haveCompleteContactInfo;
} }
mIsPaymentRequestParamsInitiated = true;
} }
// Implement PaymentRequestLifecycleObserver: // Implement PaymentRequestLifecycleObserver:
...@@ -944,8 +950,9 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob ...@@ -944,8 +950,9 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
* @param activity The ChromeActivity for the payment request. * @param activity The ChromeActivity for the payment request.
*/ */
public void buildPaymentRequestUI(ChromeActivity activity) { public void buildPaymentRequestUI(ChromeActivity activity) {
assert mIsPaymentRequestParamsInitiated;
mPaymentRequestUI = new PaymentRequestUI(activity, mDelegate.getPaymentRequestUIClient(), mPaymentRequestUI = new PaymentRequestUI(activity, mDelegate.getPaymentRequestUIClient(),
merchantSupportsAutofillCards(), !PaymentPreferencesUtil.isPaymentCompleteOnce(), mMerchantSupportsAutofillCards, !PaymentPreferencesUtil.isPaymentCompleteOnce(),
mMerchantName, mTopLevelOriginFormattedForDisplay, mMerchantName, mTopLevelOriginFormattedForDisplay,
SecurityStateModel.getSecurityLevelForWebContents(mWebContents), SecurityStateModel.getSecurityLevelForWebContents(mWebContents),
new ShippingStrings( new ShippingStrings(
......
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