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

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: Addressed comment 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
« no previous file with comments | « no previous file | chrome/android/java_sources.gni » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b232c7fd259b3ce2f597ee229dbf62199a0d392a 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,
+ PaymentApp.InstrumentsCallback,
+ PaymentInstrument.InstrumentDetailsCallback,
+ PaymentAppFactory.PaymentAppCreatedCallback,
+ PaymentResponseHelper.PaymentResponseRequesterDelegate,
+ FocusChangedObserver, NormalizedAddressRequestDelegate {
/**
* A test-only observer for the PaymentRequest service implementation.
*/
@@ -974,8 +976,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 +1111,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 +1592,38 @@ public class PaymentRequestImpl
mUI.updateSection(PaymentRequestUI.TYPE_SHIPPING_ADDRESSES, mShippingAddressesSection);
}
+ @Override
+ public void onAddressNormalized(AutofillProfile profile) {
+ ChromeActivity chromeActivity = ChromeActivity.fromWebContents(mWebContents);
+
+ // Can happen if the tab is closed during the normalization process.
+ if (chromeActivity == null) {
+ recordAbortReasonHistogram(PaymentRequestMetrics.ABORT_REASON_OTHER);
+ disconnectFromClientWithDebugMessage("Unable to find Chrome activity");
+ if (sObserverForTest != null) sObserverForTest.onPaymentRequestServiceShowFailed();
+ return;
+ }
+
+ // Don't reuse the selected address because it is formatted for display.
+ AutofillAddress shippingAddress = new AutofillAddress(chromeActivity, profile);
+
+ // This updates the line items and the shipping options asynchronously.
+ mClient.onShippingAddressChange(shippingAddress.toPaymentAddress());
+ }
+
+ @Override
+ public void onCouldNotNormalize(AutofillProfile profile) {
+ // Since the phone number is formatted in either case, this profile should be used.
+ 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) {
+ 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.
*
« no previous file with comments | « no previous file | chrome/android/java_sources.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698