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

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

Issue 2048823004: PaymentRequest.abort() should return a promise. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Include what you use Created 4 years, 6 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 03844ff40be627b934d2e1e87e3385971a484abd..9161384a7ef7ed5ce535d77fa9ff837316e60df6 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
@@ -11,6 +11,7 @@ import android.text.TextUtils;
import org.chromium.base.Callback;
import org.chromium.base.Log;
+import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
import org.chromium.chrome.browser.favicon.FaviconHelper;
@@ -58,12 +59,24 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
PaymentApp.InstrumentsCallback, PaymentInstrument.DetailsCallback {
/**
+ * A test-only observer for the PaymentRequest service implementation.
+ */
+ public interface PaymentRequestServiceObserverForTest {
+ /**
+ * Called when an abort request was denied.
+ */
+ void onPaymentRequestServiceUnableToAbort();
+ }
+
+ /**
* The size for the favicon in density-independent pixels.
*/
private static final int FAVICON_SIZE_DP = 24;
private static final String TAG = "cr_PaymentRequest";
+ private static PaymentRequestServiceObserverForTest sObserverForTest;
+
private final Handler mHandler = new Handler();
private Activity mContext;
@@ -113,9 +126,10 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
private Callback<PaymentInformation> mPaymentInformationCallback;
private Pattern mRegionCodePattern;
private boolean mMerchantNeedsShippingAddress;
+ private boolean mPaymentAppRunning;
/**
- * Builds the dialog.
+ * Builds the PaymentRequest service implementation.
*
* @param webContents The web contents that have invoked the PaymentRequest API.
*/
@@ -241,7 +255,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
mPaymentMethodsSection = new SectionInformation(PaymentRequestUI.TYPE_PAYMENT_METHODS);
}
- mUI = PaymentRequestUI.show(mContext, this, requestShipping, mMerchantName, mOrigin);
+ mUI = new PaymentRequestUI(mContext, this, requestShipping, mMerchantName, mOrigin);
if (mFavicon != null) mUI.setTitleBitmap(mFavicon);
mFavicon = null;
}
@@ -546,6 +560,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
PaymentOption selectedShippingOption, PaymentOption selectedPaymentMethod) {
assert selectedPaymentMethod instanceof PaymentInstrument;
PaymentInstrument instrument = (PaymentInstrument) selectedPaymentMethod;
+ mPaymentAppRunning = true;
instrument.getDetails(mMerchantName, mOrigin, mRawTotal, mRawLineItems,
mMethodData.get(instrument.getMethodName()), this);
}
@@ -566,8 +581,13 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
*/
@Override
public void abort() {
- closeClient();
- closeUI(false);
+ mClient.onAbort(!mPaymentAppRunning);
+ if (mPaymentAppRunning) {
+ if (sObserverForTest != null) sObserverForTest.onPaymentRequestServiceUnableToAbort();
+ } else {
+ closeClient();
+ closeUI(false);
+ }
}
/**
@@ -693,4 +713,9 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
if (mClient != null) mClient.close();
mClient = null;
}
+
+ @VisibleForTesting
+ public static void setObserverForTest(PaymentRequestServiceObserverForTest observerForTest) {
+ sObserverForTest = observerForTest;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698