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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 private final TabModelObserver mTabModelObserver = new EmptyTabModelObserver () { | 250 private final TabModelObserver mTabModelObserver = new EmptyTabModelObserver () { |
251 @Override | 251 @Override |
252 public void didSelectTab(Tab tab, TabSelectionType type, int lastId) { | 252 public void didSelectTab(Tab tab, TabSelectionType type, int lastId) { |
253 if (tab == null || tab.getId() != lastId) onDismiss(); | 253 if (tab == null || tab.getId() != lastId) onDismiss(); |
254 } | 254 } |
255 }; | 255 }; |
256 | 256 |
257 private final Handler mHandler = new Handler(); | 257 private final Handler mHandler = new Handler(); |
258 private final RenderFrameHost mRenderFrameHost; | 258 private final RenderFrameHost mRenderFrameHost; |
259 private final WebContents mWebContents; | 259 private final WebContents mWebContents; |
260 private final String mTopLevelUrl; | |
260 private final String mTopLevelOrigin; | 261 private final String mTopLevelOrigin; |
261 private final String mPaymentRequestOrigin; | 262 private final String mPaymentRequestUrl; |
262 private final String mMerchantName; | 263 private final String mMerchantName; |
263 @Nullable | 264 @Nullable |
264 private final byte[][] mCertificateChain; | 265 private final byte[][] mCertificateChain; |
265 private final AddressEditor mAddressEditor; | 266 private final AddressEditor mAddressEditor; |
266 private final CardEditor mCardEditor; | 267 private final CardEditor mCardEditor; |
267 private final JourneyLogger mJourneyLogger; | 268 private final JourneyLogger mJourneyLogger; |
268 private final boolean mIsIncognito; | 269 private final boolean mIsIncognito; |
269 | 270 |
270 private PaymentRequestClient mClient; | 271 private PaymentRequestClient mClient; |
271 private boolean mIsCurrentPaymentRequestShowing; | 272 private boolean mIsCurrentPaymentRequestShowing; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 * Builds the PaymentRequest service implementation. | 359 * Builds the PaymentRequest service implementation. |
359 * | 360 * |
360 * @param renderFrameHost The host of the frame that has invoked the Payment Request API. | 361 * @param renderFrameHost The host of the frame that has invoked the Payment Request API. |
361 */ | 362 */ |
362 public PaymentRequestImpl(RenderFrameHost renderFrameHost) { | 363 public PaymentRequestImpl(RenderFrameHost renderFrameHost) { |
363 assert renderFrameHost != null; | 364 assert renderFrameHost != null; |
364 | 365 |
365 mRenderFrameHost = renderFrameHost; | 366 mRenderFrameHost = renderFrameHost; |
366 mWebContents = WebContentsStatics.fromRenderFrameHost(renderFrameHost); | 367 mWebContents = WebContentsStatics.fromRenderFrameHost(renderFrameHost); |
367 | 368 |
368 mPaymentRequestOrigin = UrlFormatter.formatUrlForSecurityDisplay( | 369 mPaymentRequestUrl = mRenderFrameHost.getLastCommittedURL(); |
369 mRenderFrameHost.getLastCommittedURL(), true); | 370 mTopLevelUrl = mWebContents.getLastCommittedUrl(); |
370 mTopLevelOrigin = | 371 mTopLevelOrigin = UrlFormatter.formatUrlForSecurityDisplay(mTopLevelUrl, true); |
371 UrlFormatter.formatUrlForSecurityDisplay(mWebContents.getLastCom mittedUrl(), true); | |
372 | 372 |
373 mMerchantName = mWebContents.getTitle(); | 373 mMerchantName = mWebContents.getTitle(); |
374 | 374 |
375 mCertificateChain = CertificateChainHelper.getCertificateChain(mWebConte nts); | 375 mCertificateChain = CertificateChainHelper.getCertificateChain(mWebConte nts); |
376 | 376 |
377 mApps = new ArrayList<>(); | 377 mApps = new ArrayList<>(); |
378 | 378 |
379 mAddressEditor = new AddressEditor(); | 379 mAddressEditor = new AddressEditor(); |
380 mCardEditor = new CardEditor(mWebContents, mAddressEditor, sObserverForT est); | 380 mCardEditor = new CardEditor(mWebContents, mAddressEditor, sObserverForT est); |
381 | 381 |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
706 if (appMethods == null || !app.supportsMethodsAndData(appMethods)) { | 706 if (appMethods == null || !app.supportsMethodsAndData(appMethods)) { |
707 mPendingApps.remove(app); | 707 mPendingApps.remove(app); |
708 } else { | 708 } else { |
709 mArePaymentMethodsSupported = true; | 709 mArePaymentMethodsSupported = true; |
710 mMerchantSupportsAutofillPaymentInstruments |= app instanceof Au tofillPaymentApp; | 710 mMerchantSupportsAutofillPaymentInstruments |= app instanceof Au tofillPaymentApp; |
711 queryApps.put(app, appMethods); | 711 queryApps.put(app, appMethods); |
712 } | 712 } |
713 } | 713 } |
714 | 714 |
715 if (queryApps.isEmpty()) { | 715 if (queryApps.isEmpty()) { |
716 CanMakePaymentQuery query = sCanMakePaymentQueries.get(mPaymentReque stOrigin); | 716 CanMakePaymentQuery query = sCanMakePaymentQueries.get(mPaymentReque stUrl); |
please use gerrit instead
2017/05/25 17:56:13
canMakePayment() queries should be throttled based
gogerald1
2017/05/29 22:13:16
my bad, payment request handler do require origin
| |
717 if (query != null && query.matchesPaymentMethods(mMethodData)) { | 717 if (query != null && query.matchesPaymentMethods(mMethodData)) { |
718 query.notifyObserversOfResponse(mCanMakePayment); | 718 query.notifyObserversOfResponse(mCanMakePayment); |
719 } | 719 } |
720 } | 720 } |
721 | 721 |
722 if (disconnectIfNoPaymentMethodsSupported()) return; | 722 if (disconnectIfNoPaymentMethodsSupported()) return; |
723 | 723 |
724 // Query instruments after mMerchantSupportsAutofillPaymentInstruments h as been initialized, | 724 // Query instruments after mMerchantSupportsAutofillPaymentInstruments h as been initialized, |
725 // so a fast response from a non-autofill payment app at the front of th e app list does not | 725 // so a fast response from a non-autofill payment app at the front of th e app list does not |
726 // cause NOT_SUPPORTED payment rejection. | 726 // cause NOT_SUPPORTED payment rejection. |
727 for (Map.Entry<PaymentApp, Map<String, PaymentMethodData>> q : queryApps .entrySet()) { | 727 for (Map.Entry<PaymentApp, Map<String, PaymentMethodData>> q : queryApps .entrySet()) { |
728 q.getKey().getInstruments(q.getValue(), mTopLevelOrigin, mPaymentReq uestOrigin, | 728 q.getKey().getInstruments(q.getValue(), mTopLevelUrl, mPaymentReques tUrl, |
please use gerrit instead
2017/05/25 17:56:13
Please rename these parameters in PaymentApp.java
gogerald1
2017/05/29 22:13:16
Done.
| |
729 mCertificateChain, mRawTotal, this); | 729 mCertificateChain, mRawTotal, this); |
730 } | 730 } |
731 } | 731 } |
732 | 732 |
733 /** Filter out merchant method data that's not relevant to a payment app. Ca n return null. */ | 733 /** Filter out merchant method data that's not relevant to a payment app. Ca n return null. */ |
734 private static Map<String, PaymentMethodData> filterMerchantMethodData( | 734 private static Map<String, PaymentMethodData> filterMerchantMethodData( |
735 Map<String, PaymentMethodData> merchantMethodData, Set<String> appMe thods) { | 735 Map<String, PaymentMethodData> merchantMethodData, Set<String> appMe thods) { |
736 Map<String, PaymentMethodData> result = null; | 736 Map<String, PaymentMethodData> result = null; |
737 for (String method : appMethods) { | 737 for (String method : appMethods) { |
738 if (merchantMethodData.containsKey(method)) { | 738 if (merchantMethodData.containsKey(method)) { |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1290 Map<String, PaymentDetailsModifier> modifiers = new HashMap<>(); | 1290 Map<String, PaymentDetailsModifier> modifiers = new HashMap<>(); |
1291 for (String instrumentMethodName : instrument.getInstrumentMethodNames() ) { | 1291 for (String instrumentMethodName : instrument.getInstrumentMethodNames() ) { |
1292 if (mMethodData.containsKey(instrumentMethodName)) { | 1292 if (mMethodData.containsKey(instrumentMethodName)) { |
1293 methodData.put(instrumentMethodName, mMethodData.get(instrumentM ethodName)); | 1293 methodData.put(instrumentMethodName, mMethodData.get(instrumentM ethodName)); |
1294 } | 1294 } |
1295 if (mModifiers != null && mModifiers.containsKey(instrumentMethodNam e)) { | 1295 if (mModifiers != null && mModifiers.containsKey(instrumentMethodNam e)) { |
1296 modifiers.put(instrumentMethodName, mModifiers.get(instrumentMet hodName)); | 1296 modifiers.put(instrumentMethodName, mModifiers.get(instrumentMet hodName)); |
1297 } | 1297 } |
1298 } | 1298 } |
1299 | 1299 |
1300 instrument.invokePaymentApp(mId, mMerchantName, mTopLevelOrigin, mPaymen tRequestOrigin, | 1300 instrument.invokePaymentApp(mId, mMerchantName, mTopLevelUrl, mPaymentRe questUrl, |
please use gerrit instead
2017/05/25 17:56:13
Please update the names and comments of these para
gogerald1
2017/05/29 22:13:16
Done.
| |
1301 mCertificateChain, Collections.unmodifiableMap(methodData), mRaw Total, | 1301 mCertificateChain, Collections.unmodifiableMap(methodData), mRaw Total, |
1302 mRawLineItems, Collections.unmodifiableMap(modifiers), this); | 1302 mRawLineItems, Collections.unmodifiableMap(modifiers), this); |
1303 | 1303 |
1304 mJourneyLogger.setEventOccurred(JourneyLogger.EVENT_PAY_CLICKED); | 1304 mJourneyLogger.setEventOccurred(JourneyLogger.EVENT_PAY_CLICKED); |
1305 return !(instrument instanceof AutofillPaymentInstrument); | 1305 return !(instrument instanceof AutofillPaymentInstrument); |
1306 } | 1306 } |
1307 | 1307 |
1308 @Override | 1308 @Override |
1309 public void onDismiss() { | 1309 public void onDismiss() { |
1310 recordAbortReasonHistogram(PaymentRequestMetrics.ABORT_REASON_ABORTED_BY _USER); | 1310 recordAbortReasonHistogram(PaymentRequestMetrics.ABORT_REASON_ABORTED_BY _USER); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1378 disconnectFromClientWithDebugMessage("Card and address settings clicked" ); | 1378 disconnectFromClientWithDebugMessage("Card and address settings clicked" ); |
1379 } | 1379 } |
1380 | 1380 |
1381 /** | 1381 /** |
1382 * Called by the merchant website to check if the user has complete payment instruments. | 1382 * Called by the merchant website to check if the user has complete payment instruments. |
1383 */ | 1383 */ |
1384 @Override | 1384 @Override |
1385 public void canMakePayment() { | 1385 public void canMakePayment() { |
1386 if (mClient == null) return; | 1386 if (mClient == null) return; |
1387 | 1387 |
1388 CanMakePaymentQuery query = sCanMakePaymentQueries.get(mPaymentRequestOr igin); | 1388 CanMakePaymentQuery query = sCanMakePaymentQueries.get(mPaymentRequestUr l); |
1389 if (query == null) { | 1389 if (query == null) { |
1390 // If there has not been a canMakePayment() query in the last 30 min utes, take a note | 1390 // If there has not been a canMakePayment() query in the last 30 min utes, take a note |
1391 // that one has happened just now. Remember the payment method names and the | 1391 // that one has happened just now. Remember the payment method names and the |
1392 // corresponding data for the next 30 minutes. Forget about it after the 30 minute | 1392 // corresponding data for the next 30 minutes. Forget about it after the 30 minute |
1393 // period expires. | 1393 // period expires. |
1394 query = new CanMakePaymentQuery(Collections.unmodifiableMap(mMethodD ata)); | 1394 query = new CanMakePaymentQuery(Collections.unmodifiableMap(mMethodD ata)); |
1395 sCanMakePaymentQueries.put(mPaymentRequestOrigin, query); | 1395 sCanMakePaymentQueries.put(mPaymentRequestUrl, query); |
1396 mHandler.postDelayed(new Runnable() { | 1396 mHandler.postDelayed(new Runnable() { |
1397 @Override | 1397 @Override |
1398 public void run() { | 1398 public void run() { |
1399 sCanMakePaymentQueries.remove(mPaymentRequestOrigin); | 1399 sCanMakePaymentQueries.remove(mPaymentRequestUrl); |
1400 } | 1400 } |
1401 }, CAN_MAKE_PAYMENT_QUERY_PERIOD_MS); | 1401 }, CAN_MAKE_PAYMENT_QUERY_PERIOD_MS); |
1402 } else if (shouldEnforceCanMakePaymentQueryQuota() | 1402 } else if (shouldEnforceCanMakePaymentQueryQuota() |
1403 && !query.matchesPaymentMethods(Collections.unmodifiableMap(mMet hodData))) { | 1403 && !query.matchesPaymentMethods(Collections.unmodifiableMap(mMet hodData))) { |
1404 // If there has been a canMakePayment() query in the last 30 minutes , but the previous | 1404 // If there has been a canMakePayment() query in the last 30 minutes , but the previous |
1405 // payment method names and the corresponding data don't match, enfo rce the | 1405 // payment method names and the corresponding data don't match, enfo rce the |
1406 // canMakePayment() query quota (unless the quota is turned off). | 1406 // canMakePayment() query quota (unless the quota is turned off). |
1407 mClient.onCanMakePayment(CanMakePaymentQueryResult.QUERY_QUOTA_EXCEE DED); | 1407 mClient.onCanMakePayment(CanMakePaymentQueryResult.QUERY_QUOTA_EXCEE DED); |
1408 if (sObserverForTest != null) { | 1408 if (sObserverForTest != null) { |
1409 sObserverForTest.onPaymentRequestServiceCanMakePaymentQueryRespo nded(); | 1409 sObserverForTest.onPaymentRequestServiceCanMakePaymentQueryRespo nded(); |
1410 } | 1410 } |
1411 return; | 1411 return; |
1412 } | 1412 } |
1413 | 1413 |
1414 query.addObserver(this); | 1414 query.addObserver(this); |
1415 if (isFinishedQueryingPaymentApps()) query.notifyObserversOfResponse(mCa nMakePayment); | 1415 if (isFinishedQueryingPaymentApps()) query.notifyObserversOfResponse(mCa nMakePayment); |
1416 } | 1416 } |
1417 | 1417 |
1418 private void respondCanMakePaymentQuery(boolean response) { | 1418 private void respondCanMakePaymentQuery(boolean response) { |
1419 if (mClient == null) return; | 1419 if (mClient == null) return; |
1420 | 1420 |
1421 boolean isIgnoringQueryQuota = false; | 1421 boolean isIgnoringQueryQuota = false; |
1422 if (!shouldEnforceCanMakePaymentQueryQuota()) { | 1422 if (!shouldEnforceCanMakePaymentQueryQuota()) { |
1423 CanMakePaymentQuery query = sCanMakePaymentQueries.get(mPaymentReque stOrigin); | 1423 CanMakePaymentQuery query = sCanMakePaymentQueries.get(mPaymentReque stUrl); |
1424 // The cached query may have expired between instantiation of Paymen tRequest and | 1424 // The cached query may have expired between instantiation of Paymen tRequest and |
1425 // finishing the query of the payment apps. | 1425 // finishing the query of the payment apps. |
1426 if (query != null) { | 1426 if (query != null) { |
1427 isIgnoringQueryQuota = | 1427 isIgnoringQueryQuota = |
1428 !query.matchesPaymentMethods(Collections.unmodifiableMap (mMethodData)); | 1428 !query.matchesPaymentMethods(Collections.unmodifiableMap (mMethodData)); |
1429 } | 1429 } |
1430 } | 1430 } |
1431 | 1431 |
1432 if (mIsIncognito) { | 1432 if (mIsIncognito) { |
1433 mClient.onCanMakePayment(CanMakePaymentQueryResult.CAN_MAKE_PAYMENT) ; | 1433 mClient.onCanMakePayment(CanMakePaymentQueryResult.CAN_MAKE_PAYMENT) ; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1557 if (first instanceof AutofillPaymentInstrument) { | 1557 if (first instanceof AutofillPaymentInstrument) { |
1558 AutofillPaymentInstrument creditCard = (AutofillPaymentInstrumen t) first; | 1558 AutofillPaymentInstrument creditCard = (AutofillPaymentInstrumen t) first; |
1559 if (creditCard.isComplete()) selection = 0; | 1559 if (creditCard.isComplete()) selection = 0; |
1560 } else { | 1560 } else { |
1561 // If a payment app is available, then PaymentRequest.canMakePay ment() returns true. | 1561 // If a payment app is available, then PaymentRequest.canMakePay ment() returns true. |
1562 mCanMakePayment = true; | 1562 mCanMakePayment = true; |
1563 selection = 0; | 1563 selection = 0; |
1564 } | 1564 } |
1565 } | 1565 } |
1566 | 1566 |
1567 CanMakePaymentQuery query = sCanMakePaymentQueries.get(mPaymentRequestOr igin); | 1567 CanMakePaymentQuery query = sCanMakePaymentQueries.get(mPaymentRequestUr l); |
1568 if (query != null && query.matchesPaymentMethods(mMethodData)) { | 1568 if (query != null && query.matchesPaymentMethods(mMethodData)) { |
1569 query.notifyObserversOfResponse(mCanMakePayment); | 1569 query.notifyObserversOfResponse(mCanMakePayment); |
1570 } | 1570 } |
1571 | 1571 |
1572 // The list of payment instruments is ready to display. | 1572 // The list of payment instruments is ready to display. |
1573 List<PaymentInstrument> sortedInstruments = new ArrayList<>(); | 1573 List<PaymentInstrument> sortedInstruments = new ArrayList<>(); |
1574 for (List<PaymentInstrument> a : mPendingInstruments) { | 1574 for (List<PaymentInstrument> a : mPendingInstruments) { |
1575 sortedInstruments.addAll(a); | 1575 sortedInstruments.addAll(a); |
1576 } | 1576 } |
1577 mPaymentMethodsSection = new SectionInformation( | 1577 mPaymentMethodsSection = new SectionInformation( |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1865 | 1865 |
1866 /** | 1866 /** |
1867 * The frecency score is calculated according to use count and last use date . The formula is | 1867 * The frecency score is calculated according to use count and last use date . The formula is |
1868 * the same as the one used in GetFrecencyScore in autofill_data_model.cc. | 1868 * the same as the one used in GetFrecencyScore in autofill_data_model.cc. |
1869 */ | 1869 */ |
1870 private static final double getFrecencyScore(int count, long date) { | 1870 private static final double getFrecencyScore(int count, long date) { |
1871 long currentTime = System.currentTimeMillis(); | 1871 long currentTime = System.currentTimeMillis(); |
1872 return -Math.log((currentTime - date) / (24 * 60 * 60 * 1000) + 2) / Mat h.log(count + 2); | 1872 return -Math.log((currentTime - date) / (24 * 60 * 60 * 1000) + 2) / Mat h.log(count + 2); |
1873 } | 1873 } |
1874 } | 1874 } |
OLD | NEW |