| 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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 } | 399 } |
| 400 } | 400 } |
| 401 | 401 |
| 402 /** | 402 /** |
| 403 * Called by the merchant website to initialize the payment request data. | 403 * Called by the merchant website to initialize the payment request data. |
| 404 */ | 404 */ |
| 405 @Override | 405 @Override |
| 406 public void init(PaymentRequestClient client, PaymentMethodData[] methodData
, | 406 public void init(PaymentRequestClient client, PaymentMethodData[] methodData
, |
| 407 PaymentDetails details, PaymentOptions options) { | 407 PaymentDetails details, PaymentOptions options) { |
| 408 if (mClient != null) { | 408 if (mClient != null) { |
| 409 mJourneyLogger.setAborted(JourneyLogger.ABORT_REASON_INVALID_DATA_FR
OM_RENDERER); | 409 mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER); |
| 410 disconnectFromClientWithDebugMessage("Renderer should never call ini
t() twice"); | 410 disconnectFromClientWithDebugMessage("Renderer should never call ini
t() twice"); |
| 411 return; | 411 return; |
| 412 } | 412 } |
| 413 | 413 |
| 414 if (client == null) { | 414 if (client == null) { |
| 415 mJourneyLogger.setAborted(JourneyLogger.ABORT_REASON_INVALID_DATA_FR
OM_RENDERER); | 415 mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER); |
| 416 disconnectFromClientWithDebugMessage("Invalid mojo client"); | 416 disconnectFromClientWithDebugMessage("Invalid mojo client"); |
| 417 return; | 417 return; |
| 418 } | 418 } |
| 419 | 419 |
| 420 mClient = client; | 420 mClient = client; |
| 421 mMethodData = new HashMap<>(); | 421 mMethodData = new HashMap<>(); |
| 422 | 422 |
| 423 if (!OriginSecurityChecker.isOriginSecure(mWebContents.getLastCommittedU
rl())) { | 423 if (!OriginSecurityChecker.isOriginSecure(mWebContents.getLastCommittedU
rl())) { |
| 424 mJourneyLogger.setAborted(JourneyLogger.ABORT_REASON_INVALID_DATA_FR
OM_RENDERER); | 424 mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER); |
| 425 disconnectFromClientWithDebugMessage("Not in a secure context"); | 425 disconnectFromClientWithDebugMessage("Not in a secure context"); |
| 426 return; | 426 return; |
| 427 } | 427 } |
| 428 | 428 |
| 429 mRequestShipping = options != null && options.requestShipping; | 429 mRequestShipping = options != null && options.requestShipping; |
| 430 mRequestPayerName = options != null && options.requestPayerName; | 430 mRequestPayerName = options != null && options.requestPayerName; |
| 431 mRequestPayerPhone = options != null && options.requestPayerPhone; | 431 mRequestPayerPhone = options != null && options.requestPayerPhone; |
| 432 mRequestPayerEmail = options != null && options.requestPayerEmail; | 432 mRequestPayerEmail = options != null && options.requestPayerEmail; |
| 433 mShippingType = options == null ? PaymentShippingType.SHIPPING : options
.shippingType; | 433 mShippingType = options == null ? PaymentShippingType.SHIPPING : options
.shippingType; |
| 434 | 434 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 449 && !SslValidityChecker.isSslCertificateValid(mWebContents)) { | 449 && !SslValidityChecker.isSslCertificateValid(mWebContents)) { |
| 450 Log.d(TAG, "SSL certificate is not valid"); | 450 Log.d(TAG, "SSL certificate is not valid"); |
| 451 // Don't show any UI. Resolve .canMakePayment() with "false". Reject
.show() with | 451 // Don't show any UI. Resolve .canMakePayment() with "false". Reject
.show() with |
| 452 // "NotSupportedError". | 452 // "NotSupportedError". |
| 453 onAllPaymentAppsCreated(); | 453 onAllPaymentAppsCreated(); |
| 454 return; | 454 return; |
| 455 } | 455 } |
| 456 | 456 |
| 457 mMethodData = getValidatedMethodData(methodData, mCardEditor); | 457 mMethodData = getValidatedMethodData(methodData, mCardEditor); |
| 458 if (mMethodData == null) { | 458 if (mMethodData == null) { |
| 459 mJourneyLogger.setAborted(JourneyLogger.ABORT_REASON_INVALID_DATA_FR
OM_RENDERER); | 459 mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER); |
| 460 disconnectFromClientWithDebugMessage("Invalid payment methods or dat
a"); | 460 disconnectFromClientWithDebugMessage("Invalid payment methods or dat
a"); |
| 461 return; | 461 return; |
| 462 } | 462 } |
| 463 | 463 |
| 464 if (!parseAndValidateDetailsOrDisconnectFromClient(details)) return; | 464 if (!parseAndValidateDetailsOrDisconnectFromClient(details)) return; |
| 465 | 465 |
| 466 if (mRawTotal == null) { | 466 if (mRawTotal == null) { |
| 467 mJourneyLogger.setAborted(JourneyLogger.ABORT_REASON_INVALID_DATA_FR
OM_RENDERER); | 467 mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER); |
| 468 disconnectFromClientWithDebugMessage("Missing total"); | 468 disconnectFromClientWithDebugMessage("Missing total"); |
| 469 return; | 469 return; |
| 470 } | 470 } |
| 471 mId = details.id; | 471 mId = details.id; |
| 472 | 472 |
| 473 PaymentAppFactory.getInstance().create(mWebContents, | 473 PaymentAppFactory.getInstance().create(mWebContents, |
| 474 Collections.unmodifiableSet(mMethodData.keySet()), this /* callb
ack */); | 474 Collections.unmodifiableSet(mMethodData.keySet()), this /* callb
ack */); |
| 475 | 475 |
| 476 // If there is a single payment method and the merchant has not requeste
d any other | 476 // If there is a single payment method and the merchant has not requeste
d any other |
| 477 // information, we can safely go directly to the payment app instead of
showing | 477 // information, we can safely go directly to the payment app instead of
showing |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 Set<String> uniqueCountryCodes = new HashSet<>(); | 560 Set<String> uniqueCountryCodes = new HashSet<>(); |
| 561 for (int i = 0; i < addresses.size(); ++i) { | 561 for (int i = 0; i < addresses.size(); ++i) { |
| 562 String countryCode = AutofillAddress.getCountryCode(addresses.get(i)
.getProfile()); | 562 String countryCode = AutofillAddress.getCountryCode(addresses.get(i)
.getProfile()); |
| 563 if (!uniqueCountryCodes.contains(countryCode)) { | 563 if (!uniqueCountryCodes.contains(countryCode)) { |
| 564 uniqueCountryCodes.add(countryCode); | 564 uniqueCountryCodes.add(countryCode); |
| 565 PersonalDataManager.getInstance().loadRulesForAddressNormalizati
on(countryCode); | 565 PersonalDataManager.getInstance().loadRulesForAddressNormalizati
on(countryCode); |
| 566 } | 566 } |
| 567 } | 567 } |
| 568 | 568 |
| 569 // Log the number of suggested shipping addresses. | 569 // Log the number of suggested shipping addresses. |
| 570 mJourneyLogger.setNumberOfSuggestionsShown( | 570 mJourneyLogger.setNumberOfSuggestionsShown(Section.SHIPPING_ADDRESS, add
resses.size()); |
| 571 JourneyLogger.SECTION_SHIPPING_ADDRESS, addresses.size()); | |
| 572 | 571 |
| 573 // Automatically select the first address if one is complete and if the
merchant does | 572 // Automatically select the first address if one is complete and if the
merchant does |
| 574 // not require a shipping address to calculate shipping costs. | 573 // not require a shipping address to calculate shipping costs. |
| 575 int firstCompleteAddressIndex = SectionInformation.NO_SELECTION; | 574 int firstCompleteAddressIndex = SectionInformation.NO_SELECTION; |
| 576 if (mUiShippingOptions.getSelectedItem() != null && !addresses.isEmpty() | 575 if (mUiShippingOptions.getSelectedItem() != null && !addresses.isEmpty() |
| 577 && addresses.get(0).isComplete()) { | 576 && addresses.get(0).isComplete()) { |
| 578 firstCompleteAddressIndex = 0; | 577 firstCompleteAddressIndex = 0; |
| 579 | 578 |
| 580 // The initial label for the selected shipping address should not in
clude the | 579 // The initial label for the selected shipping address should not in
clude the |
| 581 // country. | 580 // country. |
| 582 addresses.get(firstCompleteAddressIndex).setShippingAddressLabelWith
outCountry(); | 581 addresses.get(firstCompleteAddressIndex).setShippingAddressLabelWith
outCountry(); |
| 583 } | 582 } |
| 584 | 583 |
| 585 mShippingAddressesSection = new SectionInformation( | 584 mShippingAddressesSection = new SectionInformation( |
| 586 PaymentRequestUI.TYPE_SHIPPING_ADDRESSES, firstCompleteAddressIn
dex, addresses); | 585 PaymentRequestUI.TYPE_SHIPPING_ADDRESSES, firstCompleteAddressIn
dex, addresses); |
| 587 } | 586 } |
| 588 | 587 |
| 589 /** | 588 /** |
| 590 * Called by the merchant website to show the payment request to the user. | 589 * Called by the merchant website to show the payment request to the user. |
| 591 */ | 590 */ |
| 592 @Override | 591 @Override |
| 593 public void show() { | 592 public void show() { |
| 594 if (mClient == null) return; | 593 if (mClient == null) return; |
| 595 | 594 |
| 596 if (mUI != null) { | 595 if (mUI != null) { |
| 597 // Can be triggered only by a compromised renderer. In normal operat
ion, calling show() | 596 // Can be triggered only by a compromised renderer. In normal operat
ion, calling show() |
| 598 // twice on the same instance of PaymentRequest in JavaScript is rej
ected at the | 597 // twice on the same instance of PaymentRequest in JavaScript is rej
ected at the |
| 599 // renderer level. | 598 // renderer level. |
| 600 mJourneyLogger.setAborted(JourneyLogger.ABORT_REASON_INVALID_DATA_FR
OM_RENDERER); | 599 mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER); |
| 601 disconnectFromClientWithDebugMessage("Renderer should never invoke s
how() twice"); | 600 disconnectFromClientWithDebugMessage("Renderer should never invoke s
how() twice"); |
| 602 return; | 601 return; |
| 603 } | 602 } |
| 604 | 603 |
| 605 if (getIsAnyPaymentRequestShowing()) { | 604 if (getIsAnyPaymentRequestShowing()) { |
| 606 // The renderer can create multiple instances of PaymentRequest and
call show() on each | 605 // The renderer can create multiple instances of PaymentRequest and
call show() on each |
| 607 // one. Only the first one will be shown. This also prevents multipl
e tabs and windows | 606 // one. Only the first one will be shown. This also prevents multipl
e tabs and windows |
| 608 // from showing PaymentRequest UI at the same time. | 607 // from showing PaymentRequest UI at the same time. |
| 609 mJourneyLogger.setNotShown(JourneyLogger.NO_SHOW_CONCURRENT_REQUESTS
); | 608 mJourneyLogger.setNotShown(NotShownReason.CONCURRENT_REQUESTS); |
| 610 disconnectFromClientWithDebugMessage("A PaymentRequest UI is already
showing"); | 609 disconnectFromClientWithDebugMessage("A PaymentRequest UI is already
showing"); |
| 611 if (sObserverForTest != null) sObserverForTest.onPaymentRequestServi
ceShowFailed(); | 610 if (sObserverForTest != null) sObserverForTest.onPaymentRequestServi
ceShowFailed(); |
| 612 return; | 611 return; |
| 613 } | 612 } |
| 614 | 613 |
| 615 mIsCurrentPaymentRequestShowing = true; | 614 mIsCurrentPaymentRequestShowing = true; |
| 616 if (disconnectIfNoPaymentMethodsSupported()) return; | 615 if (disconnectIfNoPaymentMethodsSupported()) return; |
| 617 | 616 |
| 618 ChromeActivity chromeActivity = ChromeActivity.fromWebContents(mWebConte
nts); | 617 ChromeActivity chromeActivity = ChromeActivity.fromWebContents(mWebConte
nts); |
| 619 if (chromeActivity == null) { | 618 if (chromeActivity == null) { |
| 620 mJourneyLogger.setNotShown(JourneyLogger.NO_SHOW_REASON_OTHER); | 619 mJourneyLogger.setNotShown(NotShownReason.OTHER); |
| 621 disconnectFromClientWithDebugMessage("Unable to find Chrome activity
"); | 620 disconnectFromClientWithDebugMessage("Unable to find Chrome activity
"); |
| 622 if (sObserverForTest != null) sObserverForTest.onPaymentRequestServi
ceShowFailed(); | 621 if (sObserverForTest != null) sObserverForTest.onPaymentRequestServi
ceShowFailed(); |
| 623 return; | 622 return; |
| 624 } | 623 } |
| 625 | 624 |
| 626 // Catch any time the user switches tabs. Because the dialog is modal, a
user shouldn't be | 625 // Catch any time the user switches tabs. Because the dialog is modal, a
user shouldn't be |
| 627 // allowed to switch tabs, which can happen if the user receives an exte
rnal Intent. | 626 // allowed to switch tabs, which can happen if the user receives an exte
rnal Intent. |
| 628 mObservedTabModelSelector = chromeActivity.getTabModelSelector(); | 627 mObservedTabModelSelector = chromeActivity.getTabModelSelector(); |
| 629 mObservedTabModel = chromeActivity.getCurrentTabModel(); | 628 mObservedTabModel = chromeActivity.getCurrentTabModel(); |
| 630 mObservedTabModelSelector.addObserver(mSelectorObserver); | 629 mObservedTabModelSelector.addObserver(mSelectorObserver); |
| 631 mObservedTabModel.addObserver(mTabModelObserver); | 630 mObservedTabModel.addObserver(mTabModelObserver); |
| 632 | 631 |
| 633 buildUI(chromeActivity); | 632 buildUI(chromeActivity); |
| 634 if (!mShouldSkipShowingPaymentRequestUi) mUI.show(); | 633 if (!mShouldSkipShowingPaymentRequestUi) mUI.show(); |
| 635 | 634 |
| 636 triggerPaymentAppUiSkipIfApplicable(); | 635 triggerPaymentAppUiSkipIfApplicable(); |
| 637 } | 636 } |
| 638 | 637 |
| 639 private void triggerPaymentAppUiSkipIfApplicable() { | 638 private void triggerPaymentAppUiSkipIfApplicable() { |
| 640 // If we are skipping showing the Payment Request UI, we should call int
o the | 639 // If we are skipping showing the Payment Request UI, we should call int
o the |
| 641 // PaymentApp immediately after we determine the instruments are ready a
nd UI is shown. | 640 // PaymentApp immediately after we determine the instruments are ready a
nd UI is shown. |
| 642 if (mShouldSkipShowingPaymentRequestUi && isFinishedQueryingPaymentApps(
) | 641 if (mShouldSkipShowingPaymentRequestUi && isFinishedQueryingPaymentApps(
) |
| 643 && mIsCurrentPaymentRequestShowing) { | 642 && mIsCurrentPaymentRequestShowing) { |
| 644 assert !mPaymentMethodsSection.isEmpty(); | 643 assert !mPaymentMethodsSection.isEmpty(); |
| 645 | 644 |
| 646 mDidRecordShowEvent = true; | 645 mDidRecordShowEvent = true; |
| 647 mShouldRecordAbortReason = true; | 646 mShouldRecordAbortReason = true; |
| 648 mJourneyLogger.setEventOccurred(JourneyLogger.EVENT_SKIPPED_SHOW); | 647 mJourneyLogger.setEventOccurred(Event.SKIPPED_SHOW); |
| 649 mJourneyLogger.setShowCalled(); | 648 mJourneyLogger.setShowCalled(); |
| 650 | 649 |
| 651 onPayClicked(null /* selectedShippingAddress */, null /* selectedShi
ppingOption */, | 650 onPayClicked(null /* selectedShippingAddress */, null /* selectedShi
ppingOption */, |
| 652 mPaymentMethodsSection.getItem(0)); | 651 mPaymentMethodsSection.getItem(0)); |
| 653 } | 652 } |
| 654 } | 653 } |
| 655 | 654 |
| 656 private static Map<String, PaymentMethodData> getValidatedMethodData( | 655 private static Map<String, PaymentMethodData> getValidatedMethodData( |
| 657 PaymentMethodData[] methodData, CardEditor paymentMethodsCollector)
{ | 656 PaymentMethodData[] methodData, CardEditor paymentMethodsCollector)
{ |
| 658 // Payment methodData are required. | 657 // Payment methodData are required. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 | 737 |
| 739 /** | 738 /** |
| 740 * Called by merchant to update the shipping options and line items after th
e user has selected | 739 * Called by merchant to update the shipping options and line items after th
e user has selected |
| 741 * their shipping address or shipping option. | 740 * their shipping address or shipping option. |
| 742 */ | 741 */ |
| 743 @Override | 742 @Override |
| 744 public void updateWith(PaymentDetails details) { | 743 public void updateWith(PaymentDetails details) { |
| 745 if (mClient == null) return; | 744 if (mClient == null) return; |
| 746 | 745 |
| 747 if (mUI == null) { | 746 if (mUI == null) { |
| 748 mJourneyLogger.setAborted(JourneyLogger.ABORT_REASON_INVALID_DATA_FR
OM_RENDERER); | 747 mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER); |
| 749 disconnectFromClientWithDebugMessage( | 748 disconnectFromClientWithDebugMessage( |
| 750 "PaymentRequestUpdateEvent.updateWith() called without Payme
ntRequest.show()"); | 749 "PaymentRequestUpdateEvent.updateWith() called without Payme
ntRequest.show()"); |
| 751 return; | 750 return; |
| 752 } | 751 } |
| 753 | 752 |
| 754 if (!parseAndValidateDetailsOrDisconnectFromClient(details)) return; | 753 if (!parseAndValidateDetailsOrDisconnectFromClient(details)) return; |
| 755 | 754 |
| 756 if (mUiShippingOptions.isEmpty() && mShippingAddressesSection.getSelecte
dItem() != null) { | 755 if (mUiShippingOptions.isEmpty() && mShippingAddressesSection.getSelecte
dItem() != null) { |
| 757 mShippingAddressesSection.getSelectedItem().setInvalid(); | 756 mShippingAddressesSection.getSelectedItem().setInvalid(); |
| 758 mShippingAddressesSection.setSelectedItemIndex(SectionInformation.IN
VALID_SELECTION); | 757 mShippingAddressesSection.setSelectedItemIndex(SectionInformation.IN
VALID_SELECTION); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 771 * Sets the total, display line items, and shipping options based on input a
nd returns the | 770 * Sets the total, display line items, and shipping options based on input a
nd returns the |
| 772 * status boolean. That status is true for valid data, false for invalid dat
a. If the input is | 771 * status boolean. That status is true for valid data, false for invalid dat
a. If the input is |
| 773 * invalid, disconnects from the client. Both raw and UI versions of data ar
e updated. | 772 * invalid, disconnects from the client. Both raw and UI versions of data ar
e updated. |
| 774 * | 773 * |
| 775 * @param details The total, line items, and shipping options to parse, vali
date, and save in | 774 * @param details The total, line items, and shipping options to parse, vali
date, and save in |
| 776 * member variables. | 775 * member variables. |
| 777 * @return True if the data is valid. False if the data is invalid. | 776 * @return True if the data is valid. False if the data is invalid. |
| 778 */ | 777 */ |
| 779 private boolean parseAndValidateDetailsOrDisconnectFromClient(PaymentDetails
details) { | 778 private boolean parseAndValidateDetailsOrDisconnectFromClient(PaymentDetails
details) { |
| 780 if (!PaymentValidator.validatePaymentDetails(details)) { | 779 if (!PaymentValidator.validatePaymentDetails(details)) { |
| 781 mJourneyLogger.setAborted(JourneyLogger.ABORT_REASON_INVALID_DATA_FR
OM_RENDERER); | 780 mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER); |
| 782 disconnectFromClientWithDebugMessage("Invalid payment details"); | 781 disconnectFromClientWithDebugMessage("Invalid payment details"); |
| 783 return false; | 782 return false; |
| 784 } | 783 } |
| 785 | 784 |
| 786 if (details.total != null) { | 785 if (details.total != null) { |
| 787 mRawTotal = details.total; | 786 mRawTotal = details.total; |
| 788 } | 787 } |
| 789 | 788 |
| 790 loadCurrencyFormattersForPaymentDetails(details); | 789 loadCurrencyFormattersForPaymentDetails(details); |
| 791 | 790 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 | 985 |
| 987 private void providePaymentInformation() { | 986 private void providePaymentInformation() { |
| 988 mPaymentInformationCallback.onResult( | 987 mPaymentInformationCallback.onResult( |
| 989 new PaymentInformation(mUiShoppingCart, mShippingAddressesSectio
n, | 988 new PaymentInformation(mUiShoppingCart, mShippingAddressesSectio
n, |
| 990 mUiShippingOptions, mContactSection, mPaymentMethodsSect
ion)); | 989 mUiShippingOptions, mContactSection, mPaymentMethodsSect
ion)); |
| 991 mPaymentInformationCallback = null; | 990 mPaymentInformationCallback = null; |
| 992 | 991 |
| 993 if (!mDidRecordShowEvent) { | 992 if (!mDidRecordShowEvent) { |
| 994 mDidRecordShowEvent = true; | 993 mDidRecordShowEvent = true; |
| 995 mShouldRecordAbortReason = true; | 994 mShouldRecordAbortReason = true; |
| 996 mJourneyLogger.setEventOccurred(JourneyLogger.EVENT_SHOWN); | 995 mJourneyLogger.setEventOccurred(Event.SHOWN); |
| 997 mJourneyLogger.setShowCalled(); | 996 mJourneyLogger.setShowCalled(); |
| 998 } | 997 } |
| 999 } | 998 } |
| 1000 | 999 |
| 1001 @Override | 1000 @Override |
| 1002 public void getShoppingCart(final Callback<ShoppingCart> callback) { | 1001 public void getShoppingCart(final Callback<ShoppingCart> callback) { |
| 1003 mHandler.post(new Runnable() { | 1002 mHandler.post(new Runnable() { |
| 1004 @Override | 1003 @Override |
| 1005 public void run() { | 1004 public void run() { |
| 1006 callback.onResult(mUiShoppingCart); | 1005 callback.onResult(mUiShoppingCart); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1028 }); | 1027 }); |
| 1029 } | 1028 } |
| 1030 | 1029 |
| 1031 @Override | 1030 @Override |
| 1032 @PaymentRequestUI.SelectionResult | 1031 @PaymentRequestUI.SelectionResult |
| 1033 public int onSectionOptionSelected(@PaymentRequestUI.DataType int optionType
, | 1032 public int onSectionOptionSelected(@PaymentRequestUI.DataType int optionType
, |
| 1034 PaymentOption option, Callback<PaymentInformation> callback) { | 1033 PaymentOption option, Callback<PaymentInformation> callback) { |
| 1035 if (optionType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES) { | 1034 if (optionType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES) { |
| 1036 assert option instanceof AutofillAddress; | 1035 assert option instanceof AutofillAddress; |
| 1037 // Log the change of shipping address. | 1036 // Log the change of shipping address. |
| 1038 mJourneyLogger.incrementSelectionChanges(JourneyLogger.SECTION_SHIPP
ING_ADDRESS); | 1037 mJourneyLogger.incrementSelectionChanges(Section.SHIPPING_ADDRESS); |
| 1039 AutofillAddress address = (AutofillAddress) option; | 1038 AutofillAddress address = (AutofillAddress) option; |
| 1040 if (address.isComplete()) { | 1039 if (address.isComplete()) { |
| 1041 mShippingAddressesSection.setSelectedItem(option); | 1040 mShippingAddressesSection.setSelectedItem(option); |
| 1042 startShippingAddressChangeNormalization(address); | 1041 startShippingAddressChangeNormalization(address); |
| 1043 } else { | 1042 } else { |
| 1044 editAddress(address); | 1043 editAddress(address); |
| 1045 } | 1044 } |
| 1046 mPaymentInformationCallback = callback; | 1045 mPaymentInformationCallback = callback; |
| 1047 return PaymentRequestUI.SELECTION_RESULT_ASYNCHRONOUS_VALIDATION; | 1046 return PaymentRequestUI.SELECTION_RESULT_ASYNCHRONOUS_VALIDATION; |
| 1048 } else if (optionType == PaymentRequestUI.TYPE_SHIPPING_OPTIONS) { | 1047 } else if (optionType == PaymentRequestUI.TYPE_SHIPPING_OPTIONS) { |
| 1049 // This may update the line items. | 1048 // This may update the line items. |
| 1050 mUiShippingOptions.setSelectedItem(option); | 1049 mUiShippingOptions.setSelectedItem(option); |
| 1051 mClient.onShippingOptionChange(option.getIdentifier()); | 1050 mClient.onShippingOptionChange(option.getIdentifier()); |
| 1052 mPaymentInformationCallback = callback; | 1051 mPaymentInformationCallback = callback; |
| 1053 return PaymentRequestUI.SELECTION_RESULT_ASYNCHRONOUS_VALIDATION; | 1052 return PaymentRequestUI.SELECTION_RESULT_ASYNCHRONOUS_VALIDATION; |
| 1054 } else if (optionType == PaymentRequestUI.TYPE_CONTACT_DETAILS) { | 1053 } else if (optionType == PaymentRequestUI.TYPE_CONTACT_DETAILS) { |
| 1055 assert option instanceof AutofillContact; | 1054 assert option instanceof AutofillContact; |
| 1056 // Log the change of contact info. | 1055 // Log the change of contact info. |
| 1057 mJourneyLogger.incrementSelectionChanges(JourneyLogger.SECTION_CONTA
CT_INFO); | 1056 mJourneyLogger.incrementSelectionChanges(Section.CONTACT_INFO); |
| 1058 AutofillContact contact = (AutofillContact) option; | 1057 AutofillContact contact = (AutofillContact) option; |
| 1059 | 1058 |
| 1060 if (contact.isComplete()) { | 1059 if (contact.isComplete()) { |
| 1061 mContactSection.setSelectedItem(option); | 1060 mContactSection.setSelectedItem(option); |
| 1062 } else { | 1061 } else { |
| 1063 editContact(contact); | 1062 editContact(contact); |
| 1064 return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH; | 1063 return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH; |
| 1065 } | 1064 } |
| 1066 } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) { | 1065 } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) { |
| 1067 assert option instanceof PaymentInstrument; | 1066 assert option instanceof PaymentInstrument; |
| 1068 if (option instanceof AutofillPaymentInstrument) { | 1067 if (option instanceof AutofillPaymentInstrument) { |
| 1069 // Log the change of credit card. | 1068 // Log the change of credit card. |
| 1070 mJourneyLogger.incrementSelectionChanges(JourneyLogger.SECTION_C
REDIT_CARDS); | 1069 mJourneyLogger.incrementSelectionChanges(Section.CREDIT_CARDS); |
| 1071 AutofillPaymentInstrument card = (AutofillPaymentInstrument) opt
ion; | 1070 AutofillPaymentInstrument card = (AutofillPaymentInstrument) opt
ion; |
| 1072 | 1071 |
| 1073 if (!card.isComplete()) { | 1072 if (!card.isComplete()) { |
| 1074 editCard(card); | 1073 editCard(card); |
| 1075 return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH; | 1074 return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH; |
| 1076 } | 1075 } |
| 1077 } | 1076 } |
| 1078 | 1077 |
| 1079 updateOrderSummary((PaymentInstrument) option); | 1078 updateOrderSummary((PaymentInstrument) option); |
| 1080 mPaymentMethodsSection.setSelectedItem(option); | 1079 mPaymentMethodsSection.setSelectedItem(option); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1111 } | 1110 } |
| 1112 | 1111 |
| 1113 @Override | 1112 @Override |
| 1114 @PaymentRequestUI.SelectionResult | 1113 @PaymentRequestUI.SelectionResult |
| 1115 public int onSectionAddOption( | 1114 public int onSectionAddOption( |
| 1116 @PaymentRequestUI.DataType int optionType, Callback<PaymentInformati
on> callback) { | 1115 @PaymentRequestUI.DataType int optionType, Callback<PaymentInformati
on> callback) { |
| 1117 if (optionType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES) { | 1116 if (optionType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES) { |
| 1118 editAddress(null); | 1117 editAddress(null); |
| 1119 mPaymentInformationCallback = callback; | 1118 mPaymentInformationCallback = callback; |
| 1120 // Log the add of shipping address. | 1119 // Log the add of shipping address. |
| 1121 mJourneyLogger.incrementSelectionAdds(JourneyLogger.SECTION_SHIPPING
_ADDRESS); | 1120 mJourneyLogger.incrementSelectionAdds(Section.SHIPPING_ADDRESS); |
| 1122 return PaymentRequestUI.SELECTION_RESULT_ASYNCHRONOUS_VALIDATION; | 1121 return PaymentRequestUI.SELECTION_RESULT_ASYNCHRONOUS_VALIDATION; |
| 1123 } else if (optionType == PaymentRequestUI.TYPE_CONTACT_DETAILS) { | 1122 } else if (optionType == PaymentRequestUI.TYPE_CONTACT_DETAILS) { |
| 1124 editContact(null); | 1123 editContact(null); |
| 1125 // Log the add of contact info. | 1124 // Log the add of contact info. |
| 1126 mJourneyLogger.incrementSelectionAdds(JourneyLogger.SECTION_CONTACT_
INFO); | 1125 mJourneyLogger.incrementSelectionAdds(Section.CONTACT_INFO); |
| 1127 return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH; | 1126 return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH; |
| 1128 } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) { | 1127 } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) { |
| 1129 editCard(null); | 1128 editCard(null); |
| 1130 // Log the add of credit card. | 1129 // Log the add of credit card. |
| 1131 mJourneyLogger.incrementSelectionAdds(JourneyLogger.SECTION_CREDIT_C
ARDS); | 1130 mJourneyLogger.incrementSelectionAdds(Section.CREDIT_CARDS); |
| 1132 return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH; | 1131 return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH; |
| 1133 } | 1132 } |
| 1134 | 1133 |
| 1135 return PaymentRequestUI.SELECTION_RESULT_NONE; | 1134 return PaymentRequestUI.SELECTION_RESULT_NONE; |
| 1136 } | 1135 } |
| 1137 | 1136 |
| 1138 private void editAddress(final AutofillAddress toEdit) { | 1137 private void editAddress(final AutofillAddress toEdit) { |
| 1139 if (toEdit != null) { | 1138 if (toEdit != null) { |
| 1140 // Log the edit of a shipping address. | 1139 // Log the edit of a shipping address. |
| 1141 mJourneyLogger.incrementSelectionEdits(JourneyLogger.SECTION_SHIPPIN
G_ADDRESS); | 1140 mJourneyLogger.incrementSelectionEdits(Section.SHIPPING_ADDRESS); |
| 1142 } | 1141 } |
| 1143 mAddressEditor.edit(toEdit, new Callback<AutofillAddress>() { | 1142 mAddressEditor.edit(toEdit, new Callback<AutofillAddress>() { |
| 1144 @Override | 1143 @Override |
| 1145 public void onResult(AutofillAddress editedAddress) { | 1144 public void onResult(AutofillAddress editedAddress) { |
| 1146 if (mUI == null) return; | 1145 if (mUI == null) return; |
| 1147 | 1146 |
| 1148 if (editedAddress != null) { | 1147 if (editedAddress != null) { |
| 1149 // Sets or updates the shipping address label. | 1148 // Sets or updates the shipping address label. |
| 1150 editedAddress.setShippingAddressLabelWithCountry(); | 1149 editedAddress.setShippingAddressLabelWithCountry(); |
| 1151 | 1150 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1179 } else { | 1178 } else { |
| 1180 providePaymentInformation(); | 1179 providePaymentInformation(); |
| 1181 } | 1180 } |
| 1182 } | 1181 } |
| 1183 }); | 1182 }); |
| 1184 } | 1183 } |
| 1185 | 1184 |
| 1186 private void editContact(final AutofillContact toEdit) { | 1185 private void editContact(final AutofillContact toEdit) { |
| 1187 if (toEdit != null) { | 1186 if (toEdit != null) { |
| 1188 // Log the edit of a contact info. | 1187 // Log the edit of a contact info. |
| 1189 mJourneyLogger.incrementSelectionEdits(JourneyLogger.SECTION_CONTACT
_INFO); | 1188 mJourneyLogger.incrementSelectionEdits(Section.CONTACT_INFO); |
| 1190 } | 1189 } |
| 1191 mContactEditor.edit(toEdit, new Callback<AutofillContact>() { | 1190 mContactEditor.edit(toEdit, new Callback<AutofillContact>() { |
| 1192 @Override | 1191 @Override |
| 1193 public void onResult(AutofillContact editedContact) { | 1192 public void onResult(AutofillContact editedContact) { |
| 1194 if (mUI == null) return; | 1193 if (mUI == null) return; |
| 1195 | 1194 |
| 1196 if (editedContact != null) { | 1195 if (editedContact != null) { |
| 1197 // A partial or complete contact came back from the editor (
could have been from | 1196 // A partial or complete contact came back from the editor (
could have been from |
| 1198 // adding/editing or cancelling out of the edit flow). | 1197 // adding/editing or cancelling out of the edit flow). |
| 1199 if (!editedContact.isComplete()) { | 1198 if (!editedContact.isComplete()) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1212 // action to take (if a contact was selected in the UI, it will
stay selected). | 1211 // action to take (if a contact was selected in the UI, it will
stay selected). |
| 1213 | 1212 |
| 1214 mUI.updateSection(PaymentRequestUI.TYPE_CONTACT_DETAILS, mContac
tSection); | 1213 mUI.updateSection(PaymentRequestUI.TYPE_CONTACT_DETAILS, mContac
tSection); |
| 1215 } | 1214 } |
| 1216 }); | 1215 }); |
| 1217 } | 1216 } |
| 1218 | 1217 |
| 1219 private void editCard(final AutofillPaymentInstrument toEdit) { | 1218 private void editCard(final AutofillPaymentInstrument toEdit) { |
| 1220 if (toEdit != null) { | 1219 if (toEdit != null) { |
| 1221 // Log the edit of a credit card. | 1220 // Log the edit of a credit card. |
| 1222 mJourneyLogger.incrementSelectionEdits(JourneyLogger.SECTION_CREDIT_
CARDS); | 1221 mJourneyLogger.incrementSelectionEdits(Section.CREDIT_CARDS); |
| 1223 } | 1222 } |
| 1224 mCardEditor.edit(toEdit, new Callback<AutofillPaymentInstrument>() { | 1223 mCardEditor.edit(toEdit, new Callback<AutofillPaymentInstrument>() { |
| 1225 @Override | 1224 @Override |
| 1226 public void onResult(AutofillPaymentInstrument editedCard) { | 1225 public void onResult(AutofillPaymentInstrument editedCard) { |
| 1227 if (mUI == null) return; | 1226 if (mUI == null) return; |
| 1228 | 1227 |
| 1229 if (editedCard != null) { | 1228 if (editedCard != null) { |
| 1230 // A partial or complete card came back from the editor (cou
ld have been from | 1229 // A partial or complete card came back from the editor (cou
ld have been from |
| 1231 // adding/editing or cancelling out of the edit flow). | 1230 // adding/editing or cancelling out of the edit flow). |
| 1232 if (!editedCard.isComplete()) { | 1231 if (!editedCard.isComplete()) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 } | 1284 } |
| 1286 if (mModifiers != null && mModifiers.containsKey(instrumentMethodNam
e)) { | 1285 if (mModifiers != null && mModifiers.containsKey(instrumentMethodNam
e)) { |
| 1287 modifiers.put(instrumentMethodName, mModifiers.get(instrumentMet
hodName)); | 1286 modifiers.put(instrumentMethodName, mModifiers.get(instrumentMet
hodName)); |
| 1288 } | 1287 } |
| 1289 } | 1288 } |
| 1290 | 1289 |
| 1291 instrument.invokePaymentApp(mId, mMerchantName, mTopLevelOrigin, mPaymen
tRequestOrigin, | 1290 instrument.invokePaymentApp(mId, mMerchantName, mTopLevelOrigin, mPaymen
tRequestOrigin, |
| 1292 mCertificateChain, Collections.unmodifiableMap(methodData), mRaw
Total, | 1291 mCertificateChain, Collections.unmodifiableMap(methodData), mRaw
Total, |
| 1293 mRawLineItems, Collections.unmodifiableMap(modifiers), this); | 1292 mRawLineItems, Collections.unmodifiableMap(modifiers), this); |
| 1294 | 1293 |
| 1295 mJourneyLogger.setEventOccurred(JourneyLogger.EVENT_PAY_CLICKED); | 1294 mJourneyLogger.setEventOccurred(Event.PAY_CLICKED); |
| 1296 return !(instrument instanceof AutofillPaymentInstrument); | 1295 return !(instrument instanceof AutofillPaymentInstrument); |
| 1297 } | 1296 } |
| 1298 | 1297 |
| 1299 @Override | 1298 @Override |
| 1300 public void onDismiss() { | 1299 public void onDismiss() { |
| 1301 mJourneyLogger.setAborted(JourneyLogger.ABORT_REASON_ABORTED_BY_USER); | 1300 mJourneyLogger.setAborted(AbortReason.ABORTED_BY_USER); |
| 1302 disconnectFromClientWithDebugMessage("Dialog dismissed"); | 1301 disconnectFromClientWithDebugMessage("Dialog dismissed"); |
| 1303 } | 1302 } |
| 1304 | 1303 |
| 1305 private void disconnectFromClientWithDebugMessage(String debugMessage) { | 1304 private void disconnectFromClientWithDebugMessage(String debugMessage) { |
| 1306 disconnectFromClientWithDebugMessage(debugMessage, PaymentErrorReason.US
ER_CANCEL); | 1305 disconnectFromClientWithDebugMessage(debugMessage, PaymentErrorReason.US
ER_CANCEL); |
| 1307 } | 1306 } |
| 1308 | 1307 |
| 1309 private void disconnectFromClientWithDebugMessage(String debugMessage, int r
eason) { | 1308 private void disconnectFromClientWithDebugMessage(String debugMessage, int r
eason) { |
| 1310 Log.d(TAG, debugMessage); | 1309 Log.d(TAG, debugMessage); |
| 1311 if (mClient != null) mClient.onError(reason); | 1310 if (mClient != null) mClient.onError(reason); |
| 1312 closeClient(); | 1311 closeClient(); |
| 1313 closeUI(true); | 1312 closeUI(true); |
| 1314 } | 1313 } |
| 1315 | 1314 |
| 1316 /** | 1315 /** |
| 1317 * Called by the merchant website to abort the payment. | 1316 * Called by the merchant website to abort the payment. |
| 1318 */ | 1317 */ |
| 1319 @Override | 1318 @Override |
| 1320 public void abort() { | 1319 public void abort() { |
| 1321 if (mClient == null) return; | 1320 if (mClient == null) return; |
| 1322 mClient.onAbort(!mPaymentAppRunning); | 1321 mClient.onAbort(!mPaymentAppRunning); |
| 1323 if (mPaymentAppRunning) { | 1322 if (mPaymentAppRunning) { |
| 1324 if (sObserverForTest != null) sObserverForTest.onPaymentRequestServi
ceUnableToAbort(); | 1323 if (sObserverForTest != null) sObserverForTest.onPaymentRequestServi
ceUnableToAbort(); |
| 1325 } else { | 1324 } else { |
| 1326 closeClient(); | 1325 closeClient(); |
| 1327 closeUI(true); | 1326 closeUI(true); |
| 1328 mJourneyLogger.setAborted(JourneyLogger.ABORT_REASON_ABORTED_BY_MERC
HANT); | 1327 mJourneyLogger.setAborted(AbortReason.ABORTED_BY_MERCHANT); |
| 1329 } | 1328 } |
| 1330 } | 1329 } |
| 1331 | 1330 |
| 1332 /** | 1331 /** |
| 1333 * Called when the merchant website has processed the payment. | 1332 * Called when the merchant website has processed the payment. |
| 1334 */ | 1333 */ |
| 1335 @Override | 1334 @Override |
| 1336 public void complete(int result) { | 1335 public void complete(int result) { |
| 1337 if (mClient == null) return; | 1336 if (mClient == null) return; |
| 1338 mJourneyLogger.setCompleted(); | 1337 mJourneyLogger.setCompleted(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1350 PaymentPreferencesUtil.setPaymentInstrumentLastUseDate( | 1349 PaymentPreferencesUtil.setPaymentInstrumentLastUseDate( |
| 1351 selectedPaymentMethod.getIdentifier(), System.currentTimeMillis(
)); | 1350 selectedPaymentMethod.getIdentifier(), System.currentTimeMillis(
)); |
| 1352 | 1351 |
| 1353 closeUI(PaymentComplete.FAIL != result); | 1352 closeUI(PaymentComplete.FAIL != result); |
| 1354 } | 1353 } |
| 1355 | 1354 |
| 1356 @Override | 1355 @Override |
| 1357 public void onCardAndAddressSettingsClicked() { | 1356 public void onCardAndAddressSettingsClicked() { |
| 1358 Context context = ChromeActivity.fromWebContents(mWebContents); | 1357 Context context = ChromeActivity.fromWebContents(mWebContents); |
| 1359 if (context == null) { | 1358 if (context == null) { |
| 1360 mJourneyLogger.setAborted(JourneyLogger.ABORT_REASON_OTHER); | 1359 mJourneyLogger.setAborted(AbortReason.OTHER); |
| 1361 disconnectFromClientWithDebugMessage("Unable to find Chrome activity
"); | 1360 disconnectFromClientWithDebugMessage("Unable to find Chrome activity
"); |
| 1362 return; | 1361 return; |
| 1363 } | 1362 } |
| 1364 | 1363 |
| 1365 Intent intent = PreferencesLauncher.createIntentForSettingsPage( | 1364 Intent intent = PreferencesLauncher.createIntentForSettingsPage( |
| 1366 context, AutofillAndPaymentsPreferences.class.getName()); | 1365 context, AutofillAndPaymentsPreferences.class.getName()); |
| 1367 context.startActivity(intent); | 1366 context.startActivity(intent); |
| 1368 mJourneyLogger.setAborted(JourneyLogger.ABORT_REASON_ABORTED_BY_USER); | 1367 mJourneyLogger.setAborted(AbortReason.ABORTED_BY_USER); |
| 1369 disconnectFromClientWithDebugMessage("Card and address settings clicked"
); | 1368 disconnectFromClientWithDebugMessage("Card and address settings clicked"
); |
| 1370 } | 1369 } |
| 1371 | 1370 |
| 1372 /** | 1371 /** |
| 1373 * Called by the merchant website to check if the user has complete payment
instruments. | 1372 * Called by the merchant website to check if the user has complete payment
instruments. |
| 1374 */ | 1373 */ |
| 1375 @Override | 1374 @Override |
| 1376 public void canMakePayment() { | 1375 public void canMakePayment() { |
| 1377 if (mClient == null) return; | 1376 if (mClient == null) return; |
| 1378 | 1377 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1449 } | 1448 } |
| 1450 | 1449 |
| 1451 /** | 1450 /** |
| 1452 * Called when the renderer closes the Mojo connection. | 1451 * Called when the renderer closes the Mojo connection. |
| 1453 */ | 1452 */ |
| 1454 @Override | 1453 @Override |
| 1455 public void close() { | 1454 public void close() { |
| 1456 if (mClient == null) return; | 1455 if (mClient == null) return; |
| 1457 closeClient(); | 1456 closeClient(); |
| 1458 closeUI(true); | 1457 closeUI(true); |
| 1459 mJourneyLogger.setAborted(JourneyLogger.ABORT_REASON_MOJO_RENDERER_CLOSI
NG); | 1458 mJourneyLogger.setAborted(AbortReason.MOJO_RENDERER_CLOSING); |
| 1460 } | 1459 } |
| 1461 | 1460 |
| 1462 /** | 1461 /** |
| 1463 * Called when the Mojo connection encounters an error. | 1462 * Called when the Mojo connection encounters an error. |
| 1464 */ | 1463 */ |
| 1465 @Override | 1464 @Override |
| 1466 public void onConnectionError(MojoException e) { | 1465 public void onConnectionError(MojoException e) { |
| 1467 if (mClient == null) return; | 1466 if (mClient == null) return; |
| 1468 closeClient(); | 1467 closeClient(); |
| 1469 closeUI(true); | 1468 closeUI(true); |
| 1470 mJourneyLogger.setAborted(JourneyLogger.ABORT_REASON_MOJO_CONNECTION_ERR
OR); | 1469 mJourneyLogger.setAborted(AbortReason.MOJO_CONNECTION_ERROR); |
| 1471 } | 1470 } |
| 1472 | 1471 |
| 1473 /** | 1472 /** |
| 1474 * Called after retrieving the list of payment instruments in an app. | 1473 * Called after retrieving the list of payment instruments in an app. |
| 1475 */ | 1474 */ |
| 1476 @Override | 1475 @Override |
| 1477 public void onInstrumentsReady(PaymentApp app, List<PaymentInstrument> instr
uments) { | 1476 public void onInstrumentsReady(PaymentApp app, List<PaymentInstrument> instr
uments) { |
| 1478 if (mClient == null) return; | 1477 if (mClient == null) return; |
| 1479 mPendingApps.remove(app); | 1478 mPendingApps.remove(app); |
| 1480 | 1479 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1532 // > Complete autofill instruments. | 1531 // > Complete autofill instruments. |
| 1533 // > Incomplete autofill instruments. | 1532 // > Incomplete autofill instruments. |
| 1534 Collections.sort(mPendingAutofillInstruments, COMPLETENESS_COMPARATOR); | 1533 Collections.sort(mPendingAutofillInstruments, COMPLETENESS_COMPARATOR); |
| 1535 Collections.sort(mPendingInstruments, APP_FRECENCY_COMPARATOR); | 1534 Collections.sort(mPendingInstruments, APP_FRECENCY_COMPARATOR); |
| 1536 if (!mPendingAutofillInstruments.isEmpty()) { | 1535 if (!mPendingAutofillInstruments.isEmpty()) { |
| 1537 mPendingInstruments.add(mPendingAutofillInstruments); | 1536 mPendingInstruments.add(mPendingAutofillInstruments); |
| 1538 } | 1537 } |
| 1539 | 1538 |
| 1540 // Log the number of suggested credit cards. | 1539 // Log the number of suggested credit cards. |
| 1541 mJourneyLogger.setNumberOfSuggestionsShown( | 1540 mJourneyLogger.setNumberOfSuggestionsShown( |
| 1542 JourneyLogger.SECTION_CREDIT_CARDS, mPendingAutofillInstruments.
size()); | 1541 Section.CREDIT_CARDS, mPendingAutofillInstruments.size()); |
| 1543 | 1542 |
| 1544 // Possibly pre-select the first instrument on the list. | 1543 // Possibly pre-select the first instrument on the list. |
| 1545 int selection = SectionInformation.NO_SELECTION; | 1544 int selection = SectionInformation.NO_SELECTION; |
| 1546 if (!mPendingInstruments.isEmpty()) { | 1545 if (!mPendingInstruments.isEmpty()) { |
| 1547 PaymentInstrument first = mPendingInstruments.get(0).get(0); | 1546 PaymentInstrument first = mPendingInstruments.get(0).get(0); |
| 1548 if (first instanceof AutofillPaymentInstrument) { | 1547 if (first instanceof AutofillPaymentInstrument) { |
| 1549 AutofillPaymentInstrument creditCard = (AutofillPaymentInstrumen
t) first; | 1548 AutofillPaymentInstrument creditCard = (AutofillPaymentInstrumen
t) first; |
| 1550 if (creditCard.isComplete()) selection = 0; | 1549 if (creditCard.isComplete()) selection = 0; |
| 1551 } else { | 1550 } else { |
| 1552 // If a payment app is available, then PaymentRequest.canMakePay
ment() returns true. | 1551 // If a payment app is available, then PaymentRequest.canMakePay
ment() returns true. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1589 boolean foundPaymentMethods = mPaymentMethodsSection != null | 1588 boolean foundPaymentMethods = mPaymentMethodsSection != null |
| 1590 && !mPaymentMethodsSection.isEmpty(); | 1589 && !mPaymentMethodsSection.isEmpty(); |
| 1591 boolean userCanAddCreditCard = mMerchantSupportsAutofillPaymentInstrumen
ts | 1590 boolean userCanAddCreditCard = mMerchantSupportsAutofillPaymentInstrumen
ts |
| 1592 && !ChromeFeatureList.isEnabled(ChromeFeatureList.NO_CREDIT_CARD
_ABORT); | 1591 && !ChromeFeatureList.isEnabled(ChromeFeatureList.NO_CREDIT_CARD
_ABORT); |
| 1593 | 1592 |
| 1594 if (!mArePaymentMethodsSupported || (!foundPaymentMethods && !userCanAdd
CreditCard)) { | 1593 if (!mArePaymentMethodsSupported || (!foundPaymentMethods && !userCanAdd
CreditCard)) { |
| 1595 // All payment apps have responded, but none of them have instrument
s. It's possible to | 1594 // All payment apps have responded, but none of them have instrument
s. It's possible to |
| 1596 // add credit cards, but the merchant does not support them either.
The payment request | 1595 // add credit cards, but the merchant does not support them either.
The payment request |
| 1597 // must be rejected. | 1596 // must be rejected. |
| 1598 mJourneyLogger.setNotShown(mArePaymentMethodsSupported | 1597 mJourneyLogger.setNotShown(mArePaymentMethodsSupported |
| 1599 ? JourneyLogger.NO_SHOW_NO_MATCHING_PAYMENT_METHOD | 1598 ? NotShownReason.NO_MATCHING_PAYMENT_METHOD |
| 1600 : JourneyLogger.NO_SHOW_NO_SUPPORTED_PAYMENT_METHOD)
; | 1599 : NotShownReason.NO_SUPPORTED_PAYMENT_METHOD); |
| 1601 disconnectFromClientWithDebugMessage("Requested payment methods have
no instruments", | 1600 disconnectFromClientWithDebugMessage("Requested payment methods have
no instruments", |
| 1602 mIsIncognito ? PaymentErrorReason.USER_CANCEL | 1601 mIsIncognito ? PaymentErrorReason.USER_CANCEL |
| 1603 : PaymentErrorReason.NOT_SUPPORTED); | 1602 : PaymentErrorReason.NOT_SUPPORTED); |
| 1604 if (sObserverForTest != null) sObserverForTest.onPaymentRequestServi
ceShowFailed(); | 1603 if (sObserverForTest != null) sObserverForTest.onPaymentRequestServi
ceShowFailed(); |
| 1605 return true; | 1604 return true; |
| 1606 } | 1605 } |
| 1607 | 1606 |
| 1608 return false; | 1607 return false; |
| 1609 } | 1608 } |
| 1610 | 1609 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1622 | 1621 |
| 1623 // Record the payment method used to complete the transaction. If the pa
yment method was an | 1622 // Record the payment method used to complete the transaction. If the pa
yment method was an |
| 1624 // Autofill credit card with an identifier, record its use. | 1623 // Autofill credit card with an identifier, record its use. |
| 1625 PaymentOption selectedPaymentMethod = mPaymentMethodsSection.getSelected
Item(); | 1624 PaymentOption selectedPaymentMethod = mPaymentMethodsSection.getSelected
Item(); |
| 1626 if (selectedPaymentMethod instanceof AutofillPaymentInstrument) { | 1625 if (selectedPaymentMethod instanceof AutofillPaymentInstrument) { |
| 1627 if (!selectedPaymentMethod.getIdentifier().isEmpty()) { | 1626 if (!selectedPaymentMethod.getIdentifier().isEmpty()) { |
| 1628 PersonalDataManager.getInstance().recordAndLogCreditCardUse( | 1627 PersonalDataManager.getInstance().recordAndLogCreditCardUse( |
| 1629 selectedPaymentMethod.getIdentifier()); | 1628 selectedPaymentMethod.getIdentifier()); |
| 1630 } | 1629 } |
| 1631 PaymentRequestMetrics.recordSelectedPaymentMethodHistogram( | 1630 PaymentRequestMetrics.recordSelectedPaymentMethodHistogram( |
| 1632 PaymentRequestMetrics.SELECTED_METHOD_CREDIT_CARD); | 1631 SelectedPaymentMethod.CREDIT_CARD); |
| 1633 } else if (methodName.equals(ANDROID_PAY_METHOD_NAME) | 1632 } else if (methodName.equals(ANDROID_PAY_METHOD_NAME) |
| 1634 || methodName.equals(PAY_WITH_GOOGLE_METHOD_NAME)) { | 1633 || methodName.equals(PAY_WITH_GOOGLE_METHOD_NAME)) { |
| 1635 PaymentRequestMetrics.recordSelectedPaymentMethodHistogram( | 1634 PaymentRequestMetrics.recordSelectedPaymentMethodHistogram( |
| 1636 PaymentRequestMetrics.SELECTED_METHOD_ANDROID_PAY); | 1635 SelectedPaymentMethod.ANDROID_PAY); |
| 1637 } else { | 1636 } else { |
| 1638 PaymentRequestMetrics.recordSelectedPaymentMethodHistogram( | 1637 PaymentRequestMetrics.recordSelectedPaymentMethodHistogram( |
| 1639 PaymentRequestMetrics.SELECTED_METHOD_OTHER_PAYMENT_APP); | 1638 SelectedPaymentMethod.OTHER_PAYMENT_APP); |
| 1640 } | 1639 } |
| 1641 | 1640 |
| 1642 // Showing the payment request UI if we were previously skipping it so t
he loading | 1641 // Showing the payment request UI if we were previously skipping it so t
he loading |
| 1643 // spinner shows up until the merchant notifies that payment was complet
ed. | 1642 // spinner shows up until the merchant notifies that payment was complet
ed. |
| 1644 if (mShouldSkipShowingPaymentRequestUi) mUI.showProcessingMessageAfterUi
Skip(); | 1643 if (mShouldSkipShowingPaymentRequestUi) mUI.showProcessingMessageAfterUi
Skip(); |
| 1645 | 1644 |
| 1646 mJourneyLogger.setEventOccurred(JourneyLogger.EVENT_RECEIVED_INSTRUMENT_
DETAILS); | 1645 mJourneyLogger.setEventOccurred(Event.RECEIVED_INSTRUMENT_DETAILS); |
| 1647 | 1646 |
| 1648 mPaymentResponseHelper.onInstrumentDetailsReceived(methodName, stringifi
edDetails); | 1647 mPaymentResponseHelper.onInstrumentDetailsReceived(methodName, stringifi
edDetails); |
| 1649 } | 1648 } |
| 1650 | 1649 |
| 1651 @Override | 1650 @Override |
| 1652 public void onPaymentResponseReady(PaymentResponse response) { | 1651 public void onPaymentResponseReady(PaymentResponse response) { |
| 1653 mClient.onPaymentResponse(response); | 1652 mClient.onPaymentResponse(response); |
| 1654 mPaymentResponseHelper = null; | 1653 mPaymentResponseHelper = null; |
| 1655 } | 1654 } |
| 1656 | 1655 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1689 | 1688 |
| 1690 mUI.updateSection(PaymentRequestUI.TYPE_SHIPPING_ADDRESSES, mShippingAdd
ressesSection); | 1689 mUI.updateSection(PaymentRequestUI.TYPE_SHIPPING_ADDRESSES, mShippingAdd
ressesSection); |
| 1691 } | 1690 } |
| 1692 | 1691 |
| 1693 @Override | 1692 @Override |
| 1694 public void onAddressNormalized(AutofillProfile profile) { | 1693 public void onAddressNormalized(AutofillProfile profile) { |
| 1695 ChromeActivity chromeActivity = ChromeActivity.fromWebContents(mWebConte
nts); | 1694 ChromeActivity chromeActivity = ChromeActivity.fromWebContents(mWebConte
nts); |
| 1696 | 1695 |
| 1697 // Can happen if the tab is closed during the normalization process. | 1696 // Can happen if the tab is closed during the normalization process. |
| 1698 if (chromeActivity == null) { | 1697 if (chromeActivity == null) { |
| 1699 mJourneyLogger.setAborted(JourneyLogger.ABORT_REASON_OTHER); | 1698 mJourneyLogger.setAborted(AbortReason.OTHER); |
| 1700 disconnectFromClientWithDebugMessage("Unable to find Chrome activity
"); | 1699 disconnectFromClientWithDebugMessage("Unable to find Chrome activity
"); |
| 1701 if (sObserverForTest != null) sObserverForTest.onPaymentRequestServi
ceShowFailed(); | 1700 if (sObserverForTest != null) sObserverForTest.onPaymentRequestServi
ceShowFailed(); |
| 1702 return; | 1701 return; |
| 1703 } | 1702 } |
| 1704 | 1703 |
| 1705 // Don't reuse the selected address because it is formatted for display. | 1704 // Don't reuse the selected address because it is formatted for display. |
| 1706 AutofillAddress shippingAddress = new AutofillAddress(chromeActivity, pr
ofile); | 1705 AutofillAddress shippingAddress = new AutofillAddress(chromeActivity, pr
ofile); |
| 1707 | 1706 |
| 1708 // This updates the line items and the shipping options asynchronously. | 1707 // This updates the line items and the shipping options asynchronously. |
| 1709 mClient.onShippingAddressChange(shippingAddress.toPaymentAddress()); | 1708 mClient.onShippingAddressChange(shippingAddress.toPaymentAddress()); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1812 | 1811 |
| 1813 /** | 1812 /** |
| 1814 * The frecency score is calculated according to use count and last use date
. The formula is | 1813 * The frecency score is calculated according to use count and last use date
. The formula is |
| 1815 * the same as the one used in GetFrecencyScore in autofill_data_model.cc. | 1814 * the same as the one used in GetFrecencyScore in autofill_data_model.cc. |
| 1816 */ | 1815 */ |
| 1817 private static final double getFrecencyScore(int count, long date) { | 1816 private static final double getFrecencyScore(int count, long date) { |
| 1818 long currentTime = System.currentTimeMillis(); | 1817 long currentTime = System.currentTimeMillis(); |
| 1819 return -Math.log((currentTime - date) / (24 * 60 * 60 * 1000) + 2) / Mat
h.log(count + 2); | 1818 return -Math.log((currentTime - date) / (24 * 60 * 60 * 1000) + 2) / Mat
h.log(count + 2); |
| 1820 } | 1819 } |
| 1821 } | 1820 } |
| OLD | NEW |