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

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: Remove DummyPageHolder and TrackExceptionState for haraken@ comment. 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 b81fa8857ed5b9c6ad74d4d0cf78716336ad739b..f42bb67785377e20cafaca6984e7a90ed59e3baf 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;
}
@@ -557,6 +571,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);
}
@@ -577,8 +592,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);
+ }
}
/**
@@ -705,4 +725,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