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

[WebLayer] Encapsulates getContactSection in PaymentUiService

Before the CL, CPRService did
PaymentUiService.getContactSection().getSelectedItem(). This is not
convenient for unit tests because the tests have to mock the contact
section and the selected item.

This CL changes it so CPRService accesses the selected contact by proxy
of PaymentUiService.

Bug: 1155582
Change-Id: I393f27594024cfb609ba99f212ac034c92a19b26
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2575341
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833950}
parent 3b04f4d6
...@@ -490,9 +490,6 @@ public class ChromePaymentRequestService ...@@ -490,9 +490,6 @@ public class ChromePaymentRequestService
public boolean invokePaymentApp(EditableOption selectedShippingAddress, public boolean invokePaymentApp(EditableOption selectedShippingAddress,
EditableOption selectedShippingOption, PaymentApp selectedPaymentApp) { EditableOption selectedShippingOption, PaymentApp selectedPaymentApp) {
if (mPaymentRequestService == null || mSpec == null || mSpec.isDestroyed()) return false; if (mPaymentRequestService == null || mSpec == null || mSpec.isDestroyed()) return false;
EditableOption selectedContact = mPaymentUiService.getContactSection() != null
? mPaymentUiService.getContactSection().getSelectedItem()
: null;
selectedPaymentApp.setPaymentHandlerHost(getPaymentHandlerHost()); selectedPaymentApp.setPaymentHandlerHost(getPaymentHandlerHost());
// Only native apps can use PaymentDetailsUpdateService. // Only native apps can use PaymentDetailsUpdateService.
if (selectedPaymentApp.getPaymentAppType() == PaymentAppType.NATIVE_MOBILE_APP) { if (selectedPaymentApp.getPaymentAppType() == PaymentAppType.NATIVE_MOBILE_APP) {
...@@ -500,9 +497,10 @@ public class ChromePaymentRequestService ...@@ -500,9 +497,10 @@ public class ChromePaymentRequestService
((AndroidPaymentApp) selectedPaymentApp).packageName(), ((AndroidPaymentApp) selectedPaymentApp).packageName(),
mPaymentRequestService /* PaymentApp.PaymentRequestUpdateEventListener */); mPaymentRequestService /* PaymentApp.PaymentRequestUpdateEventListener */);
} }
PaymentResponseHelperInterface paymentResponseHelper = new ChromePaymentResponseHelper( PaymentResponseHelperInterface paymentResponseHelper =
selectedShippingAddress, selectedShippingOption, selectedContact, new ChromePaymentResponseHelper(selectedShippingAddress, selectedShippingOption,
selectedPaymentApp, mSpec.getPaymentOptions(), mSkipToGPayHelper != null); mPaymentUiService.getSelectedContact(), selectedPaymentApp,
mSpec.getPaymentOptions(), mSkipToGPayHelper != null);
mPaymentRequestService.invokePaymentApp(selectedPaymentApp, paymentResponseHelper); mPaymentRequestService.invokePaymentApp(selectedPaymentApp, paymentResponseHelper);
return !selectedPaymentApp.isAutofillInstrument(); return !selectedPaymentApp.isAutofillInstrument();
} }
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.payments; package org.chromium.chrome.browser.payments;
import androidx.annotation.Nullable;
import org.chromium.chrome.browser.autofill.PersonalDataManager; 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.NormalizedAddressRequestDelegate; import org.chromium.chrome.browser.autofill.PersonalDataManager.NormalizedAddressRequestDelegate;
...@@ -22,6 +24,7 @@ import org.chromium.payments.mojom.PaymentResponse; ...@@ -22,6 +24,7 @@ import org.chromium.payments.mojom.PaymentResponse;
*/ */
public class ChromePaymentResponseHelper public class ChromePaymentResponseHelper
implements NormalizedAddressRequestDelegate, PaymentResponseHelperInterface { implements NormalizedAddressRequestDelegate, PaymentResponseHelperInterface {
@Nullable
private final AutofillContact mSelectedContact; private final AutofillContact mSelectedContact;
private final PaymentApp mSelectedPaymentApp; private final PaymentApp mSelectedPaymentApp;
private final PaymentOptions mPaymentOptions; private final PaymentOptions mPaymentOptions;
...@@ -37,13 +40,13 @@ public class ChromePaymentResponseHelper ...@@ -37,13 +40,13 @@ public class ChromePaymentResponseHelper
* Builds a helper to contruct and fill a PaymentResponse. * Builds a helper to contruct and fill a PaymentResponse.
* @param selectedShippingAddress The shipping address picked by the user. * @param selectedShippingAddress The shipping address picked by the user.
* @param selectedShippingOption The shipping option picked by the user. * @param selectedShippingOption The shipping option picked by the user.
* @param selectedContact The contact info picked by the user. * @param selectedContact The contact info picked by the user, can be null.
* @param selectedPaymentApp The payment app picked by the user. * @param selectedPaymentApp The payment app picked by the user.
* @param paymentOptions The paymentOptions of the corresponding payment request. * @param paymentOptions The paymentOptions of the corresponding payment request.
* @param skipToGpay Whether or not Gpay bridge is activated for skip to Gpay. * @param skipToGpay Whether or not Gpay bridge is activated for skip to Gpay.
*/ */
public ChromePaymentResponseHelper(EditableOption selectedShippingAddress, public ChromePaymentResponseHelper(EditableOption selectedShippingAddress,
EditableOption selectedShippingOption, EditableOption selectedContact, EditableOption selectedShippingOption, @Nullable AutofillContact selectedContact,
PaymentApp selectedPaymentApp, PaymentOptions paymentOptions, boolean skipToGpay) { PaymentApp selectedPaymentApp, PaymentOptions paymentOptions, boolean skipToGpay) {
mPaymentResponse = new PaymentResponse(); mPaymentResponse = new PaymentResponse();
mPaymentResponse.payer = new PayerDetail(); mPaymentResponse.payer = new PayerDetail();
...@@ -52,9 +55,7 @@ public class ChromePaymentResponseHelper ...@@ -52,9 +55,7 @@ public class ChromePaymentResponseHelper
mPaymentOptions = paymentOptions; mPaymentOptions = paymentOptions;
mSkipToGpay = skipToGpay; mSkipToGpay = skipToGpay;
// Contacts are created in ChromePaymentRequestService.init(). These should all be instances mSelectedContact = selectedContact;
// of AutofillContact.
mSelectedContact = (AutofillContact) selectedContact;
// Set up the shipping option section of the response when it comes from payment sheet // Set up the shipping option section of the response when it comes from payment sheet
// (Shipping option comes from payment app when the app can handle shipping, or from Gpay // (Shipping option comes from payment app when the app can handle shipping, or from Gpay
......
...@@ -422,6 +422,12 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -422,6 +422,12 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
return mUiShippingOptions; return mUiShippingOptions;
} }
/** @return The selected contact, can be null. */
@Nullable
public AutofillContact getSelectedContact() {
return mContactSection != null ? (AutofillContact) mContactSection.getSelectedItem() : null;
}
/** Get the contact editor on PaymentRequest UI. */ /** Get the contact editor on PaymentRequest UI. */
public ContactEditor getContactEditor() { public ContactEditor getContactEditor() {
return mContactEditor; return mContactEditor;
......
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