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

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

Issue 2645813006: Download web payment manifests. (Closed)
Patch Set: Stricter DEPS Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.payments; 5 package org.chromium.chrome.browser.payments;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.graphics.Bitmap; 10 import android.graphics.Bitmap;
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 mMethodData = getValidatedMethodData(methodData, mCardEditor); 390 mMethodData = getValidatedMethodData(methodData, mCardEditor);
391 if (mMethodData == null) { 391 if (mMethodData == null) {
392 disconnectFromClientWithDebugMessage("Invalid payment methods or dat a"); 392 disconnectFromClientWithDebugMessage("Invalid payment methods or dat a");
393 recordAbortReasonHistogram( 393 recordAbortReasonHistogram(
394 PaymentRequestMetrics.ABORT_REASON_INVALID_DATA_FROM_RENDERE R); 394 PaymentRequestMetrics.ABORT_REASON_INVALID_DATA_FROM_RENDERE R);
395 return; 395 return;
396 } 396 }
397 397
398 if (!parseAndValidateDetailsOrDisconnectFromClient(details)) return; 398 if (!parseAndValidateDetailsOrDisconnectFromClient(details)) return;
399 399
400 PaymentAppFactory.getInstance().create( 400 PaymentAppFactory.getInstance().create(mWebContents,
401 mWebContents, Collections.unmodifiableSet(mMethodData.keySet()), this); 401 Collections.unmodifiableSet(mMethodData.keySet()), this /* callb ack */);
402 402
403 mRequestShipping = options != null && options.requestShipping; 403 mRequestShipping = options != null && options.requestShipping;
404 mRequestPayerName = options != null && options.requestPayerName; 404 mRequestPayerName = options != null && options.requestPayerName;
405 mRequestPayerPhone = options != null && options.requestPayerPhone; 405 mRequestPayerPhone = options != null && options.requestPayerPhone;
406 mRequestPayerEmail = options != null && options.requestPayerEmail; 406 mRequestPayerEmail = options != null && options.requestPayerEmail;
407 mShippingType = options == null ? PaymentShippingType.SHIPPING : options .shippingType; 407 mShippingType = options == null ? PaymentShippingType.SHIPPING : options .shippingType;
408 408
409 // If there is a single payment method and the merchant has not requeste d any other 409 // If there is a single payment method and the merchant has not requeste d any other
410 // information, we can safely go directly to the payment app instead of showing 410 // information, we can safely go directly to the payment app instead of showing
411 // Payment Request UI. 411 // Payment Request UI.
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 app.getAppMethodNames()); 618 app.getAppMethodNames());
619 if (appMethods == null || !app.supportsMethodsAndData(appMethods)) { 619 if (appMethods == null || !app.supportsMethodsAndData(appMethods)) {
620 mPendingApps.remove(app); 620 mPendingApps.remove(app);
621 } else { 621 } else {
622 mArePaymentMethodsSupported = true; 622 mArePaymentMethodsSupported = true;
623 mMerchantSupportsAutofillPaymentInstruments |= app instanceof Au tofillPaymentApp; 623 mMerchantSupportsAutofillPaymentInstruments |= app instanceof Au tofillPaymentApp;
624 queryApps.put(app, appMethods); 624 queryApps.put(app, appMethods);
625 } 625 }
626 } 626 }
627 627
628 if (queryApps.isEmpty()) {
629 CanMakePaymentQuery query = sCanMakePaymentQueries.get(mSchemelessOr iginForPaymentApp);
630 if (query != null && query.matchesPaymentMethods(mMethodData)) {
631 query.notifyObserversOfResponse(false);
gogerald1 2017/03/03 19:40:27 How about add this logic to disconnectFromClientWi
please use gerrit instead 2017/03/09 18:05:32 Closing the connection to the current instance of
632 }
633 }
634
635 if (disconnectIfNoPaymentMethodsSupported()) return;
636
628 // Query instruments after mMerchantSupportsAutofillPaymentInstruments h as been initialized, 637 // Query instruments after mMerchantSupportsAutofillPaymentInstruments h as been initialized,
629 // so a fast response from a non-autofill payment app at the front of th e app list does not 638 // so a fast response from a non-autofill payment app at the front of th e app list does not
630 // cause NOT_SUPPORTED payment rejection. 639 // cause NOT_SUPPORTED payment rejection.
631 for (Map.Entry<PaymentApp, Map<String, PaymentMethodData>> q : queryApps .entrySet()) { 640 for (Map.Entry<PaymentApp, Map<String, PaymentMethodData>> q : queryApps .entrySet()) {
632 q.getKey().getInstruments( 641 q.getKey().getInstruments(
633 q.getValue(), mSchemelessOriginForPaymentApp, mCertificateCh ain, this); 642 q.getValue(), mSchemelessOriginForPaymentApp, mCertificateCh ain, this);
634 } 643 }
635 } 644 }
636 645
637 /** Filter out merchant method data that's not relevant to a payment app. Ca n return null. */ 646 /** Filter out merchant method data that's not relevant to a payment app. Ca n return null. */
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 AutofillPaymentInstrument creditCard = (AutofillPaymentInstrumen t) first; 1378 AutofillPaymentInstrument creditCard = (AutofillPaymentInstrumen t) first;
1370 if (creditCard.isComplete()) selection = 0; 1379 if (creditCard.isComplete()) selection = 0;
1371 } else { 1380 } else {
1372 // If a payment app is available, then PaymentRequest.canMakePay ment() returns true. 1381 // If a payment app is available, then PaymentRequest.canMakePay ment() returns true.
1373 mCanMakePayment = true; 1382 mCanMakePayment = true;
1374 selection = 0; 1383 selection = 0;
1375 } 1384 }
1376 } 1385 }
1377 1386
1378 CanMakePaymentQuery query = sCanMakePaymentQueries.get(mSchemelessOrigin ForPaymentApp); 1387 CanMakePaymentQuery query = sCanMakePaymentQueries.get(mSchemelessOrigin ForPaymentApp);
1379 if (query != null) query.notifyObserversOfResponse(mCanMakePayment); 1388 if (query != null && query.matchesPaymentMethods(mMethodData)) {
gogerald1 2017/03/03 19:40:27 We should no need matchesPaymentMethods if notifyO
please use gerrit instead 2017/03/09 18:05:32 This is important for the merchant that has create
1389 query.notifyObserversOfResponse(mCanMakePayment);
1390 }
1380 1391
1381 // The list of payment instruments is ready to display. 1392 // The list of payment instruments is ready to display.
1382 List<PaymentInstrument> sortedInstruments = new ArrayList<>(); 1393 List<PaymentInstrument> sortedInstruments = new ArrayList<>();
1383 for (List<PaymentInstrument> a : mPendingInstruments) { 1394 for (List<PaymentInstrument> a : mPendingInstruments) {
1384 sortedInstruments.addAll(a); 1395 sortedInstruments.addAll(a);
1385 } 1396 }
1386 mPaymentMethodsSection = new SectionInformation( 1397 mPaymentMethodsSection = new SectionInformation(
1387 PaymentRequestUI.TYPE_PAYMENT_METHODS, selection, sortedInstrume nts); 1398 PaymentRequestUI.TYPE_PAYMENT_METHODS, selection, sortedInstrume nts);
1388 1399
1389 mPendingInstruments.clear(); 1400 mPendingInstruments.clear();
1390 1401
1391 updateInstrumentModifiedTotals(); 1402 updateInstrumentModifiedTotals();
1392 1403
1393 // UI has requested the full list of payment instruments. Provide it now . 1404 // UI has requested the full list of payment instruments. Provide it now .
1394 if (mPaymentInformationCallback != null) providePaymentInformation(); 1405 if (mPaymentInformationCallback != null) providePaymentInformation();
1395 1406
1396 triggerPaymentAppUiSkipIfApplicable(); 1407 triggerPaymentAppUiSkipIfApplicable();
1397 } 1408 }
1398 1409
1399 /** 1410 /**
1400 * If no payment methods are supported, disconnect from the client and retur n true. 1411 * If no payment methods are supported, disconnect from the client and retur n true.
1401 * 1412 *
1402 * @return True if no payment methods are supported 1413 * @return True if no payment methods are supported
1403 */ 1414 */
1404 private boolean disconnectIfNoPaymentMethodsSupported() { 1415 private boolean disconnectIfNoPaymentMethodsSupported() {
1405 if (!isFinishedQueryingPaymentApps()) return false; 1416 if (!isFinishedQueryingPaymentApps() || !mIsCurrentPaymentRequestShowing ) return false;
gogerald1 2017/03/03 19:40:27 This looks has been broken here https://cs.chromiu
please use gerrit instead 2017/03/09 18:05:32 I don't follow. Please explain more.
1406 1417
1407 boolean foundPaymentMethods = mPaymentMethodsSection != null 1418 boolean foundPaymentMethods = mPaymentMethodsSection != null
1408 && !mPaymentMethodsSection.isEmpty(); 1419 && !mPaymentMethodsSection.isEmpty();
1409 boolean userCanAddCreditCard = mMerchantSupportsAutofillPaymentInstrumen ts 1420 boolean userCanAddCreditCard = mMerchantSupportsAutofillPaymentInstrumen ts
1410 && !ChromeFeatureList.isEnabled(ChromeFeatureList.NO_CREDIT_CARD _ABORT); 1421 && !ChromeFeatureList.isEnabled(ChromeFeatureList.NO_CREDIT_CARD _ABORT);
1411 1422
1412 if (!mArePaymentMethodsSupported || (mIsCurrentPaymentRequestShowing && !foundPaymentMethods 1423 if (!mArePaymentMethodsSupported || (!foundPaymentMethods && !userCanAdd CreditCard)) {
1413 && !userCanAddCreditCard)) {
1414 // All payment apps have responded, but none of them have instrument s. It's possible to 1424 // All payment apps have responded, but none of them have instrument s. It's possible to
1415 // add credit cards, but the merchant does not support them either. The payment request 1425 // add credit cards, but the merchant does not support them either. The payment request
1416 // must be rejected. 1426 // must be rejected.
1417 disconnectFromClientWithDebugMessage("Requested payment methods have no instruments", 1427 disconnectFromClientWithDebugMessage("Requested payment methods have no instruments",
1418 PaymentErrorReason.NOT_SUPPORTED); 1428 PaymentErrorReason.NOT_SUPPORTED);
1419 recordNoShowReasonHistogram(mArePaymentMethodsSupported 1429 recordNoShowReasonHistogram(mArePaymentMethodsSupported
1420 ? PaymentRequestMetrics.NO_SHOW_NO_MATCHING_PAYMENT_ METHOD 1430 ? PaymentRequestMetrics.NO_SHOW_NO_MATCHING_PAYMENT_ METHOD
1421 : PaymentRequestMetrics.NO_SHOW_NO_SUPPORTED_PAYMENT _METHOD); 1431 : PaymentRequestMetrics.NO_SHOW_NO_SUPPORTED_PAYMENT _METHOD);
1422 if (sObserverForTest != null) sObserverForTest.onPaymentRequestServi ceShowFailed(); 1432 if (sObserverForTest != null) sObserverForTest.onPaymentRequestServi ceShowFailed();
1423 return true; 1433 return true;
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1635 1645
1636 /** 1646 /**
1637 * The frecency score is calculated according to use count and last use date . The formula is 1647 * The frecency score is calculated according to use count and last use date . The formula is
1638 * the same as the one used in GetFrecencyScore in autofill_data_model.cc. 1648 * the same as the one used in GetFrecencyScore in autofill_data_model.cc.
1639 */ 1649 */
1640 private static final double getFrecencyScore(int count, long date) { 1650 private static final double getFrecencyScore(int count, long date) {
1641 long currentTime = System.currentTimeMillis(); 1651 long currentTime = System.currentTimeMillis();
1642 return -Math.log((currentTime - date) / (24 * 60 * 60 * 1000) + 2) / Mat h.log(count + 2); 1652 return -Math.log((currentTime - date) / (24 * 60 * 60 * 1000) + 2) / Mat h.log(count + 2);
1643 } 1653 }
1644 } 1654 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698