| OLD | NEW |
| 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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 mMethodData = getValidatedMethodData(methodData, mCardEditor); | 413 mMethodData = getValidatedMethodData(methodData, mCardEditor); |
| 414 if (mMethodData == null) { | 414 if (mMethodData == null) { |
| 415 disconnectFromClientWithDebugMessage("Invalid payment methods or dat
a"); | 415 disconnectFromClientWithDebugMessage("Invalid payment methods or dat
a"); |
| 416 recordAbortReasonHistogram( | 416 recordAbortReasonHistogram( |
| 417 PaymentRequestMetrics.ABORT_REASON_INVALID_DATA_FROM_RENDERE
R); | 417 PaymentRequestMetrics.ABORT_REASON_INVALID_DATA_FROM_RENDERE
R); |
| 418 return; | 418 return; |
| 419 } | 419 } |
| 420 | 420 |
| 421 if (!parseAndValidateDetailsOrDisconnectFromClient(details)) return; | 421 if (!parseAndValidateDetailsOrDisconnectFromClient(details)) return; |
| 422 | 422 |
| 423 if (mRawTotal == null) { | |
| 424 disconnectFromClientWithDebugMessage("Missing total"); | |
| 425 recordAbortReasonHistogram( | |
| 426 PaymentRequestMetrics.ABORT_REASON_INVALID_DATA_FROM_RENDERE
R); | |
| 427 return; | |
| 428 } | |
| 429 | |
| 430 PaymentAppFactory.getInstance().create(mWebContents, | 423 PaymentAppFactory.getInstance().create(mWebContents, |
| 431 Collections.unmodifiableSet(mMethodData.keySet()), this /* callb
ack */); | 424 Collections.unmodifiableSet(mMethodData.keySet()), this /* callb
ack */); |
| 432 | 425 |
| 433 mRequestShipping = options != null && options.requestShipping; | 426 mRequestShipping = options != null && options.requestShipping; |
| 434 mRequestPayerName = options != null && options.requestPayerName; | 427 mRequestPayerName = options != null && options.requestPayerName; |
| 435 mRequestPayerPhone = options != null && options.requestPayerPhone; | 428 mRequestPayerPhone = options != null && options.requestPayerPhone; |
| 436 mRequestPayerEmail = options != null && options.requestPayerEmail; | 429 mRequestPayerEmail = options != null && options.requestPayerEmail; |
| 437 mShippingType = options == null ? PaymentShippingType.SHIPPING : options
.shippingType; | 430 mShippingType = options == null ? PaymentShippingType.SHIPPING : options
.shippingType; |
| 438 | 431 |
| 439 // If there is a single payment method and the merchant has not requeste
d any other | 432 // If there is a single payment method and the merchant has not requeste
d any other |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 recordAbortReasonHistogram( | 728 recordAbortReasonHistogram( |
| 736 PaymentRequestMetrics.ABORT_REASON_INVALID_DATA_FROM_RENDERE
R); | 729 PaymentRequestMetrics.ABORT_REASON_INVALID_DATA_FROM_RENDERE
R); |
| 737 return false; | 730 return false; |
| 738 } | 731 } |
| 739 | 732 |
| 740 if (mCurrencyFormatter == null) { | 733 if (mCurrencyFormatter == null) { |
| 741 mCurrencyFormatter = new CurrencyFormatter(details.total.amount.curr
ency, | 734 mCurrencyFormatter = new CurrencyFormatter(details.total.amount.curr
ency, |
| 742 details.total.amount.currencySystem, Locale.getDefault()); | 735 details.total.amount.currencySystem, Locale.getDefault()); |
| 743 } | 736 } |
| 744 | 737 |
| 745 if (details.total != null) { | 738 // Total is never pending. |
| 746 mRawTotal = details.total; | 739 LineItem uiTotal = new LineItem(details.total.label, |
| 747 } | 740 mCurrencyFormatter.getFormattedCurrencyCode(), |
| 741 mCurrencyFormatter.format(details.total.amount.value), /* isPend
ing */ false); |
| 748 | 742 |
| 749 if (mRawTotal != null) { | 743 List<LineItem> uiLineItems = getLineItems(details.displayItems, mCurrenc
yFormatter); |
| 750 // Total is never pending. | |
| 751 LineItem uiTotal = new LineItem(mRawTotal.label, | |
| 752 mCurrencyFormatter.getFormattedCurrencyCode(), | |
| 753 mCurrencyFormatter.format(mRawTotal.amount.value), /* isPend
ing */ false); | |
| 754 | 744 |
| 755 List<LineItem> uiLineItems = getLineItems(details.displayItems, mCur
rencyFormatter); | 745 mUiShoppingCart = new ShoppingCart(uiTotal, uiLineItems); |
| 756 | 746 mRawTotal = details.total; |
| 757 mUiShoppingCart = new ShoppingCart(uiTotal, uiLineItems); | |
| 758 } | |
| 759 mRawLineItems = Collections.unmodifiableList(Arrays.asList(details.displ
ayItems)); | 747 mRawLineItems = Collections.unmodifiableList(Arrays.asList(details.displ
ayItems)); |
| 760 | 748 |
| 761 mUiShippingOptions = getShippingOptions(details.shippingOptions, mCurren
cyFormatter); | 749 mUiShippingOptions = getShippingOptions(details.shippingOptions, mCurren
cyFormatter); |
| 762 | 750 |
| 763 for (int i = 0; i < details.modifiers.length; i++) { | 751 for (int i = 0; i < details.modifiers.length; i++) { |
| 764 PaymentDetailsModifier modifier = details.modifiers[i]; | 752 PaymentDetailsModifier modifier = details.modifiers[i]; |
| 765 String[] methods = modifier.methodData.supportedMethods; | 753 String[] methods = modifier.methodData.supportedMethods; |
| 766 for (int j = 0; j < methods.length; j++) { | 754 for (int j = 0; j < methods.length; j++) { |
| 767 if (mModifiers == null) mModifiers = new ArrayMap<>(); | 755 if (mModifiers == null) mModifiers = new ArrayMap<>(); |
| 768 mModifiers.put(methods[j], modifier); | 756 mModifiers.put(methods[j], modifier); |
| (...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1690 | 1678 |
| 1691 /** | 1679 /** |
| 1692 * The frecency score is calculated according to use count and last use date
. The formula is | 1680 * The frecency score is calculated according to use count and last use date
. The formula is |
| 1693 * the same as the one used in GetFrecencyScore in autofill_data_model.cc. | 1681 * the same as the one used in GetFrecencyScore in autofill_data_model.cc. |
| 1694 */ | 1682 */ |
| 1695 private static final double getFrecencyScore(int count, long date) { | 1683 private static final double getFrecencyScore(int count, long date) { |
| 1696 long currentTime = System.currentTimeMillis(); | 1684 long currentTime = System.currentTimeMillis(); |
| 1697 return -Math.log((currentTime - date) / (24 * 60 * 60 * 1000) + 2) / Mat
h.log(count + 2); | 1685 return -Math.log((currentTime - date) / (24 * 60 * 60 * 1000) + 2) / Mat
h.log(count + 2); |
| 1698 } | 1686 } |
| 1699 } | 1687 } |
| OLD | NEW |