| 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 27 matching lines...) Expand all Loading... |
| 38 import org.chromium.chrome.browser.profiles.Profile; | 38 import org.chromium.chrome.browser.profiles.Profile; |
| 39 import org.chromium.chrome.browser.tab.Tab; | 39 import org.chromium.chrome.browser.tab.Tab; |
| 40 import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver; | 40 import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver; |
| 41 import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver; | 41 import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver; |
| 42 import org.chromium.chrome.browser.tabmodel.TabModel; | 42 import org.chromium.chrome.browser.tabmodel.TabModel; |
| 43 import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType; | 43 import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType; |
| 44 import org.chromium.chrome.browser.tabmodel.TabModelObserver; | 44 import org.chromium.chrome.browser.tabmodel.TabModelObserver; |
| 45 import org.chromium.chrome.browser.tabmodel.TabModelSelector; | 45 import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
| 46 import org.chromium.chrome.browser.tabmodel.TabModelSelectorObserver; | 46 import org.chromium.chrome.browser.tabmodel.TabModelSelectorObserver; |
| 47 import org.chromium.components.payments.CurrencyFormatter; | 47 import org.chromium.components.payments.CurrencyFormatter; |
| 48 import org.chromium.components.payments.JourneyLogger; | |
| 49 import org.chromium.components.payments.PaymentValidator; | 48 import org.chromium.components.payments.PaymentValidator; |
| 50 import org.chromium.components.url_formatter.UrlFormatter; | 49 import org.chromium.components.url_formatter.UrlFormatter; |
| 51 import org.chromium.content_public.browser.RenderFrameHost; | 50 import org.chromium.content_public.browser.RenderFrameHost; |
| 52 import org.chromium.content_public.browser.WebContents; | 51 import org.chromium.content_public.browser.WebContents; |
| 53 import org.chromium.content_public.browser.WebContentsStatics; | 52 import org.chromium.content_public.browser.WebContentsStatics; |
| 54 import org.chromium.mojo.system.MojoException; | 53 import org.chromium.mojo.system.MojoException; |
| 55 import org.chromium.payments.mojom.CanMakePaymentQueryResult; | 54 import org.chromium.payments.mojom.CanMakePaymentQueryResult; |
| 56 import org.chromium.payments.mojom.PaymentComplete; | 55 import org.chromium.payments.mojom.PaymentComplete; |
| 57 import org.chromium.payments.mojom.PaymentDetails; | 56 import org.chromium.payments.mojom.PaymentDetails; |
| 58 import org.chromium.payments.mojom.PaymentDetailsModifier; | 57 import org.chromium.payments.mojom.PaymentDetailsModifier; |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 | 373 |
| 375 mApps = new ArrayList<>(); | 374 mApps = new ArrayList<>(); |
| 376 | 375 |
| 377 mAddressEditor = new AddressEditor(); | 376 mAddressEditor = new AddressEditor(); |
| 378 mCardEditor = new CardEditor(mWebContents, mAddressEditor, sObserverForT
est); | 377 mCardEditor = new CardEditor(mWebContents, mAddressEditor, sObserverForT
est); |
| 379 | 378 |
| 380 ChromeActivity activity = ChromeActivity.fromWebContents(mWebContents); | 379 ChromeActivity activity = ChromeActivity.fromWebContents(mWebContents); |
| 381 mIsIncognito = activity != null && activity.getCurrentTabModel() != null | 380 mIsIncognito = activity != null && activity.getCurrentTabModel() != null |
| 382 && activity.getCurrentTabModel().isIncognito(); | 381 && activity.getCurrentTabModel().isIncognito(); |
| 383 | 382 |
| 384 mJourneyLogger = new JourneyLogger(mIsIncognito); | 383 mJourneyLogger = new JourneyLogger(mIsIncognito, mWebContents.getLastCom
mittedUrl()); |
| 385 | 384 |
| 386 if (sCanMakePaymentQueries == null) sCanMakePaymentQueries = new ArrayMa
p<>(); | 385 if (sCanMakePaymentQueries == null) sCanMakePaymentQueries = new ArrayMa
p<>(); |
| 387 | 386 |
| 388 recordSuccessFunnelHistograms("Initiated"); | 387 recordSuccessFunnelHistograms("Initiated"); |
| 389 } | 388 } |
| 390 | 389 |
| 391 @Override | 390 @Override |
| 392 protected void finalize() throws Throwable { | 391 protected void finalize() throws Throwable { |
| 393 super.finalize(); | 392 super.finalize(); |
| 394 if (mCurrencyFormatter != null) { | 393 if (mCurrencyFormatter != null) { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 private void triggerPaymentAppUiSkipIfApplicable() { | 592 private void triggerPaymentAppUiSkipIfApplicable() { |
| 594 // If we are skipping showing the Payment Request UI, we should call int
o the | 593 // If we are skipping showing the Payment Request UI, we should call int
o the |
| 595 // PaymentApp immediately after we determine the instruments are ready a
nd UI is shown. | 594 // PaymentApp immediately after we determine the instruments are ready a
nd UI is shown. |
| 596 if (mShouldSkipShowingPaymentRequestUi && isFinishedQueryingPaymentApps(
) | 595 if (mShouldSkipShowingPaymentRequestUi && isFinishedQueryingPaymentApps(
) |
| 597 && mIsCurrentPaymentRequestShowing) { | 596 && mIsCurrentPaymentRequestShowing) { |
| 598 assert !mPaymentMethodsSection.isEmpty(); | 597 assert !mPaymentMethodsSection.isEmpty(); |
| 599 | 598 |
| 600 mDidRecordShowEvent = true; | 599 mDidRecordShowEvent = true; |
| 601 mShouldRecordAbortReason = true; | 600 mShouldRecordAbortReason = true; |
| 602 recordSuccessFunnelHistograms("Shown"); | 601 recordSuccessFunnelHistograms("Shown"); |
| 602 mJourneyLogger.setEventOccurred(JourneyLogger.EVENT_SHOWN); |
| 603 mJourneyLogger.setShowCalled(); | 603 mJourneyLogger.setShowCalled(); |
| 604 | 604 |
| 605 onPayClicked(null /* selectedShippingAddress */, null /* selectedShi
ppingOption */, | 605 onPayClicked(null /* selectedShippingAddress */, null /* selectedShi
ppingOption */, |
| 606 mPaymentMethodsSection.getItem(0)); | 606 mPaymentMethodsSection.getItem(0)); |
| 607 } | 607 } |
| 608 } | 608 } |
| 609 | 609 |
| 610 private static Map<String, PaymentMethodData> getValidatedMethodData( | 610 private static Map<String, PaymentMethodData> getValidatedMethodData( |
| 611 PaymentMethodData[] methodData, CardEditor paymentMethodsCollector)
{ | 611 PaymentMethodData[] methodData, CardEditor paymentMethodsCollector)
{ |
| 612 // Payment methodData are required. | 612 // Payment methodData are required. |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 modifiers.put(instrumentMethodName, mModifiers.get(instrumentMet
hodName)); | 1192 modifiers.put(instrumentMethodName, mModifiers.get(instrumentMet
hodName)); |
| 1193 } | 1193 } |
| 1194 } | 1194 } |
| 1195 | 1195 |
| 1196 instrument.invokePaymentApp(mMerchantName, mSchemelessOriginForPaymentAp
p, | 1196 instrument.invokePaymentApp(mMerchantName, mSchemelessOriginForPaymentAp
p, |
| 1197 mSchemelessIFrameOriginForPaymentApp, mCertificateChain, | 1197 mSchemelessIFrameOriginForPaymentApp, mCertificateChain, |
| 1198 Collections.unmodifiableMap(methodData), mRawTotal, mRawLineItem
s, | 1198 Collections.unmodifiableMap(methodData), mRawTotal, mRawLineItem
s, |
| 1199 Collections.unmodifiableMap(modifiers), this); | 1199 Collections.unmodifiableMap(modifiers), this); |
| 1200 | 1200 |
| 1201 recordSuccessFunnelHistograms("PayClicked"); | 1201 recordSuccessFunnelHistograms("PayClicked"); |
| 1202 mJourneyLogger.setEventOccurred(JourneyLogger.EVENT_PAY_CLICKED); |
| 1202 return !(instrument instanceof AutofillPaymentInstrument); | 1203 return !(instrument instanceof AutofillPaymentInstrument); |
| 1203 } | 1204 } |
| 1204 | 1205 |
| 1205 @Override | 1206 @Override |
| 1206 public void onDismiss() { | 1207 public void onDismiss() { |
| 1207 disconnectFromClientWithDebugMessage("Dialog dismissed"); | 1208 disconnectFromClientWithDebugMessage("Dialog dismissed"); |
| 1208 recordAbortReasonHistogram(PaymentRequestMetrics.ABORT_REASON_ABORTED_BY
_USER); | 1209 recordAbortReasonHistogram(PaymentRequestMetrics.ABORT_REASON_ABORTED_BY
_USER); |
| 1209 } | 1210 } |
| 1210 | 1211 |
| 1211 private void disconnectFromClientWithDebugMessage(String debugMessage) { | 1212 private void disconnectFromClientWithDebugMessage(String debugMessage) { |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1505 } else { | 1506 } else { |
| 1506 PaymentRequestMetrics.recordSelectedPaymentMethodHistogram( | 1507 PaymentRequestMetrics.recordSelectedPaymentMethodHistogram( |
| 1507 PaymentRequestMetrics.SELECTED_METHOD_OTHER_PAYMENT_APP); | 1508 PaymentRequestMetrics.SELECTED_METHOD_OTHER_PAYMENT_APP); |
| 1508 } | 1509 } |
| 1509 | 1510 |
| 1510 // Showing the payment request UI if we were previously skipping it so t
he loading | 1511 // Showing the payment request UI if we were previously skipping it so t
he loading |
| 1511 // spinner shows up until the merchant notifies that payment was complet
ed. | 1512 // spinner shows up until the merchant notifies that payment was complet
ed. |
| 1512 if (mShouldSkipShowingPaymentRequestUi) mUI.showProcessingMessageAfterUi
Skip(); | 1513 if (mShouldSkipShowingPaymentRequestUi) mUI.showProcessingMessageAfterUi
Skip(); |
| 1513 | 1514 |
| 1514 recordSuccessFunnelHistograms("ReceivedInstrumentDetails"); | 1515 recordSuccessFunnelHistograms("ReceivedInstrumentDetails"); |
| 1516 mJourneyLogger.setEventOccurred(JourneyLogger.EVENT_RECEIVED_INSTRUMENT_
DETAILS); |
| 1515 | 1517 |
| 1516 mPaymentResponseHelper.onInstrumentDetailsReceived(methodName, stringifi
edDetails); | 1518 mPaymentResponseHelper.onInstrumentDetailsReceived(methodName, stringifi
edDetails); |
| 1517 } | 1519 } |
| 1518 | 1520 |
| 1519 @Override | 1521 @Override |
| 1520 public void onPaymentResponseReady(PaymentResponse response) { | 1522 public void onPaymentResponseReady(PaymentResponse response) { |
| 1521 mClient.onPaymentResponse(response); | 1523 mClient.onPaymentResponse(response); |
| 1522 mPaymentResponseHelper = null; | 1524 mPaymentResponseHelper = null; |
| 1523 } | 1525 } |
| 1524 | 1526 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1687 | 1689 |
| 1688 /** | 1690 /** |
| 1689 * The frecency score is calculated according to use count and last use date
. The formula is | 1691 * The frecency score is calculated according to use count and last use date
. The formula is |
| 1690 * the same as the one used in GetFrecencyScore in autofill_data_model.cc. | 1692 * the same as the one used in GetFrecencyScore in autofill_data_model.cc. |
| 1691 */ | 1693 */ |
| 1692 private static final double getFrecencyScore(int count, long date) { | 1694 private static final double getFrecencyScore(int count, long date) { |
| 1693 long currentTime = System.currentTimeMillis(); | 1695 long currentTime = System.currentTimeMillis(); |
| 1694 return -Math.log((currentTime - date) / (24 * 60 * 60 * 1000) + 2) / Mat
h.log(count + 2); | 1696 return -Math.log((currentTime - date) / (24 * 60 * 60 * 1000) + 2) / Mat
h.log(count + 2); |
| 1695 } | 1697 } |
| 1696 } | 1698 } |
| OLD | NEW |