Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1248)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java

Issue 2828913002: [Payments] Normalize Shipping Address Change on Android. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
index 6c01ec408f9d2cac283e9ae2506b8e171e06ebdc..1d120f424999597e7ec265de60f4c8aaa0fd52b7 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
@@ -22,6 +22,7 @@ import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.UrlConstants;
import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
+import org.chromium.chrome.browser.autofill.PersonalDataManager.NormalizedAddressRequestDelegate;
import org.chromium.chrome.browser.favicon.FaviconHelper;
import org.chromium.chrome.browser.page_info.CertificateChainHelper;
import org.chromium.chrome.browser.payments.ui.Completable;
@@ -84,11 +85,12 @@ import javax.annotation.Nullable;
* Android implementation of the PaymentRequest service defined in
* components/payments/content/payment_request.mojom.
*/
-public class PaymentRequestImpl
- implements PaymentRequest, PaymentRequestUI.Client, PaymentApp.InstrumentsCallback,
- PaymentInstrument.InstrumentDetailsCallback,
- PaymentAppFactory.PaymentAppCreatedCallback,
- PaymentResponseHelper.PaymentResponseRequesterDelegate, FocusChangedObserver {
+public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Client,
please use gerrit instead 2017/04/20 15:41:43 Question: Which formatter does this?
sebsg 2017/04/20 21:16:39 git cl format. but it seems to change what it does
+ PaymentApp.InstrumentsCallback,
+ PaymentInstrument.InstrumentDetailsCallback,
+ PaymentAppFactory.PaymentAppCreatedCallback,
+ PaymentResponseHelper.PaymentResponseRequesterDelegate,
+ FocusChangedObserver, NormalizedAddressRequestDelegate {
/**
* A test-only observer for the PaymentRequest service implementation.
*/
@@ -347,6 +349,9 @@ public class PaymentRequestImpl
*/
private boolean mShouldSkipShowingPaymentRequestUi;
+ /** Whether there is a shipping address change normalization pending. */
+ private boolean mIsWaitingForShippingAddressChangeNormalization;
+
/** The helper to create and fill the response to send to the merchant. */
private PaymentResponseHelper mPaymentResponseHelper;
@@ -974,8 +979,7 @@ public class PaymentRequestImpl
AutofillAddress address = (AutofillAddress) option;
if (address.isComplete()) {
mShippingAddressesSection.setSelectedItem(option);
- // This updates the line items and the shipping options asynchronously.
- mClient.onShippingAddressChange(address.toPaymentAddress());
+ startShippingAddressChangeNormalization(address);
} else {
editAddress(address);
}
@@ -1110,9 +1114,7 @@ public class PaymentRequestImpl
PaymentRequestUI.TYPE_CONTACT_DETAILS, mContactSection);
}
- // This updates the line items and the shipping options asynchronously by
- // sending the new address to the merchant website.
- mClient.onShippingAddressChange(editedAddress.toPaymentAddress());
+ startShippingAddressChangeNormalization(editedAddress);
}
} else {
providePaymentInformation();
@@ -1593,6 +1595,33 @@ public class PaymentRequestImpl
mUI.updateSection(PaymentRequestUI.TYPE_SHIPPING_ADDRESSES, mShippingAddressesSection);
}
+ @Override
+ public void onAddressNormalized(AutofillProfile profile) {
+ if (mIsWaitingForShippingAddressChangeNormalization) {
please use gerrit instead 2017/04/20 15:41:43 Question: Why would onAddressNormalized() be calle
sebsg 2017/04/20 21:16:39 Right! I made this be handled in the normalizer it
+ mIsWaitingForShippingAddressChangeNormalization = false;
+
+ // Don't reuse the selected address because it is formatted for display.
+ AutofillAddress shippingAddress =
+ new AutofillAddress(ChromeActivity.fromWebContents(mWebContents), profile);
please use gerrit instead 2017/04/20 15:41:43 Please check the return value of ChromeActivity.fr
sebsg 2017/04/20 21:16:39 Done.
+
+ // This updates the line items and the shipping options asynchronously.
+ mClient.onShippingAddressChange(shippingAddress.toPaymentAddress());
+ }
+ }
+
+ @Override
+ public void onCouldNotNormalize(AutofillProfile profile) {
+ onAddressNormalized(profile);
+ }
+
+ /** Starts the normalization of the new shipping address. Will call back into either
+ * onAddressNormalized or onCouldNotNormalize which will send the result to the merchant. */
+ private void startShippingAddressChangeNormalization(AutofillAddress address) {
+ mIsWaitingForShippingAddressChangeNormalization = true;
+ PersonalDataManager.getInstance().normalizeAddress(
+ address.getProfile(), AutofillAddress.getCountryCode(address.getProfile()), this);
+ }
+
/**
* Closes the UI. If the client is still connected, then it's notified of UI hiding.
*

Powered by Google App Engine
This is Rietveld 408576698