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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 public void didSelectTab(Tab tab, TabSelectionType type, int lastId) { | 245 public void didSelectTab(Tab tab, TabSelectionType type, int lastId) { |
246 if (tab == null || tab.getId() != lastId) onDismiss(); | 246 if (tab == null || tab.getId() != lastId) onDismiss(); |
247 } | 247 } |
248 }; | 248 }; |
249 | 249 |
250 private final Handler mHandler = new Handler(); | 250 private final Handler mHandler = new Handler(); |
251 private final RenderFrameHost mRenderFrameHost; | 251 private final RenderFrameHost mRenderFrameHost; |
252 private final WebContents mWebContents; | 252 private final WebContents mWebContents; |
253 private final String mSchemelessOriginForPaymentApp; | 253 private final String mSchemelessOriginForPaymentApp; |
254 private final String mOriginForDisplay; | 254 private final String mOriginForDisplay; |
| 255 private final String mSchemelessIFrameOriginForPaymentApp; |
255 private final String mMerchantName; | 256 private final String mMerchantName; |
256 private final byte[][] mCertificateChain; | 257 private final byte[][] mCertificateChain; |
257 private final AddressEditor mAddressEditor; | 258 private final AddressEditor mAddressEditor; |
258 private final CardEditor mCardEditor; | 259 private final CardEditor mCardEditor; |
259 private final PaymentRequestJourneyLogger mJourneyLogger = new PaymentReques
tJourneyLogger(); | 260 private final PaymentRequestJourneyLogger mJourneyLogger = new PaymentReques
tJourneyLogger(); |
260 private final boolean mIsIncognito; | 261 private final boolean mIsIncognito; |
261 | 262 |
262 private PaymentRequestClient mClient; | 263 private PaymentRequestClient mClient; |
263 private boolean mIsCurrentPaymentRequestShowing; | 264 private boolean mIsCurrentPaymentRequestShowing; |
264 | 265 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 | 349 |
349 /** | 350 /** |
350 * Builds the PaymentRequest service implementation. | 351 * Builds the PaymentRequest service implementation. |
351 * | 352 * |
352 * @param webContents The web contents that have invoked the PaymentRequest
API. | 353 * @param webContents The web contents that have invoked the PaymentRequest
API. |
353 */ | 354 */ |
354 public PaymentRequestImpl(RenderFrameHost renderFrameHost) { | 355 public PaymentRequestImpl(RenderFrameHost renderFrameHost) { |
355 assert renderFrameHost != null; | 356 assert renderFrameHost != null; |
356 | 357 |
357 mRenderFrameHost = renderFrameHost; | 358 mRenderFrameHost = renderFrameHost; |
| 359 mSchemelessIFrameOriginForPaymentApp = UrlFormatter.formatUrlForSecurity
Display( |
| 360 mRenderFrameHost.getLastCommittedURL(), false /* omit scheme for
payment apps. */); |
358 mWebContents = WebContentsStatics.fromRenderFrameHost(renderFrameHost); | 361 mWebContents = WebContentsStatics.fromRenderFrameHost(renderFrameHost); |
359 | 362 |
360 mSchemelessOriginForPaymentApp = UrlFormatter.formatUrlForSecurityDispla
y( | 363 mSchemelessOriginForPaymentApp = UrlFormatter.formatUrlForSecurityDispla
y( |
361 mWebContents.getLastCommittedUrl(), false /* omit scheme for pay
ment apps. */); | 364 mWebContents.getLastCommittedUrl(), false /* omit scheme for pay
ment apps. */); |
362 | 365 |
363 mOriginForDisplay = UrlFormatter.formatUrlForSecurityDisplay( | 366 mOriginForDisplay = UrlFormatter.formatUrlForSecurityDisplay( |
364 mWebContents.getLastCommittedUrl(), true /* include scheme in di
splay */); | 367 mWebContents.getLastCommittedUrl(), true /* include scheme in di
splay */); |
365 | 368 |
366 mMerchantName = mWebContents.getTitle(); | 369 mMerchantName = mWebContents.getTitle(); |
367 | 370 |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 query.notifyObserversOfResponse(mCanMakePayment); | 654 query.notifyObserversOfResponse(mCanMakePayment); |
652 } | 655 } |
653 } | 656 } |
654 | 657 |
655 if (disconnectIfNoPaymentMethodsSupported()) return; | 658 if (disconnectIfNoPaymentMethodsSupported()) return; |
656 | 659 |
657 // Query instruments after mMerchantSupportsAutofillPaymentInstruments h
as been initialized, | 660 // Query instruments after mMerchantSupportsAutofillPaymentInstruments h
as been initialized, |
658 // so a fast response from a non-autofill payment app at the front of th
e app list does not | 661 // so a fast response from a non-autofill payment app at the front of th
e app list does not |
659 // cause NOT_SUPPORTED payment rejection. | 662 // cause NOT_SUPPORTED payment rejection. |
660 for (Map.Entry<PaymentApp, Map<String, PaymentMethodData>> q : queryApps
.entrySet()) { | 663 for (Map.Entry<PaymentApp, Map<String, PaymentMethodData>> q : queryApps
.entrySet()) { |
661 q.getKey().getInstruments( | 664 q.getKey().getInstruments(q.getValue(), mSchemelessOriginForPaymentA
pp, |
662 q.getValue(), mSchemelessOriginForPaymentApp, mCertificateCh
ain, this); | 665 mSchemelessIFrameOriginForPaymentApp, mCertificateChain, thi
s); |
663 } | 666 } |
664 } | 667 } |
665 | 668 |
666 /** Filter out merchant method data that's not relevant to a payment app. Ca
n return null. */ | 669 /** Filter out merchant method data that's not relevant to a payment app. Ca
n return null. */ |
667 private static Map<String, PaymentMethodData> filterMerchantMethodData( | 670 private static Map<String, PaymentMethodData> filterMerchantMethodData( |
668 Map<String, PaymentMethodData> merchantMethodData, Set<String> appMe
thods) { | 671 Map<String, PaymentMethodData> merchantMethodData, Set<String> appMe
thods) { |
669 Map<String, PaymentMethodData> result = null; | 672 Map<String, PaymentMethodData> result = null; |
670 for (String method : appMethods) { | 673 for (String method : appMethods) { |
671 if (merchantMethodData.containsKey(method)) { | 674 if (merchantMethodData.containsKey(method)) { |
672 if (result == null) result = new ArrayMap<>(); | 675 if (result == null) result = new ArrayMap<>(); |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 for (String instrumentMethodName : instrument.getInstrumentMethodNames()
) { | 1177 for (String instrumentMethodName : instrument.getInstrumentMethodNames()
) { |
1175 if (mMethodData.containsKey(instrumentMethodName)) { | 1178 if (mMethodData.containsKey(instrumentMethodName)) { |
1176 methodData.put(instrumentMethodName, mMethodData.get(instrumentM
ethodName)); | 1179 methodData.put(instrumentMethodName, mMethodData.get(instrumentM
ethodName)); |
1177 } | 1180 } |
1178 if (mModifiers != null && mModifiers.containsKey(instrumentMethodNam
e)) { | 1181 if (mModifiers != null && mModifiers.containsKey(instrumentMethodNam
e)) { |
1179 modifiers.put(instrumentMethodName, mModifiers.get(instrumentMet
hodName)); | 1182 modifiers.put(instrumentMethodName, mModifiers.get(instrumentMet
hodName)); |
1180 } | 1183 } |
1181 } | 1184 } |
1182 | 1185 |
1183 instrument.invokePaymentApp(mMerchantName, mSchemelessOriginForPaymentAp
p, | 1186 instrument.invokePaymentApp(mMerchantName, mSchemelessOriginForPaymentAp
p, |
1184 mCertificateChain, Collections.unmodifiableMap(methodData), mRaw
Total, | 1187 mSchemelessIFrameOriginForPaymentApp, mCertificateChain, |
1185 mRawLineItems, Collections.unmodifiableMap(modifiers), this); | 1188 Collections.unmodifiableMap(methodData), mRawTotal, mRawLineItem
s, |
| 1189 Collections.unmodifiableMap(modifiers), this); |
1186 | 1190 |
1187 recordSuccessFunnelHistograms("PayClicked"); | 1191 recordSuccessFunnelHistograms("PayClicked"); |
1188 return !(instrument instanceof AutofillPaymentInstrument); | 1192 return !(instrument instanceof AutofillPaymentInstrument); |
1189 } | 1193 } |
1190 | 1194 |
1191 @Override | 1195 @Override |
1192 public void onDismiss() { | 1196 public void onDismiss() { |
1193 disconnectFromClientWithDebugMessage("Dialog dismissed"); | 1197 disconnectFromClientWithDebugMessage("Dialog dismissed"); |
1194 recordAbortReasonHistogram(PaymentRequestMetrics.ABORT_REASON_ABORTED_BY
_USER); | 1198 recordAbortReasonHistogram(PaymentRequestMetrics.ABORT_REASON_ABORTED_BY
_USER); |
1195 } | 1199 } |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1670 | 1674 |
1671 /** | 1675 /** |
1672 * The frecency score is calculated according to use count and last use date
. The formula is | 1676 * The frecency score is calculated according to use count and last use date
. The formula is |
1673 * the same as the one used in GetFrecencyScore in autofill_data_model.cc. | 1677 * the same as the one used in GetFrecencyScore in autofill_data_model.cc. |
1674 */ | 1678 */ |
1675 private static final double getFrecencyScore(int count, long date) { | 1679 private static final double getFrecencyScore(int count, long date) { |
1676 long currentTime = System.currentTimeMillis(); | 1680 long currentTime = System.currentTimeMillis(); |
1677 return -Math.log((currentTime - date) / (24 * 60 * 60 * 1000) + 2) / Mat
h.log(count + 2); | 1681 return -Math.log((currentTime - date) / (24 * 60 * 60 * 1000) + 2) / Mat
h.log(count + 2); |
1678 } | 1682 } |
1679 } | 1683 } |
OLD | NEW |