| 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.graphics.Bitmap; | 8 import android.graphics.Bitmap; |
| 9 import android.os.Handler; | 9 import android.os.Handler; |
| 10 import android.text.TextUtils; | 10 import android.text.TextUtils; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 import org.chromium.chrome.browser.payments.ui.ShoppingCart; | 22 import org.chromium.chrome.browser.payments.ui.ShoppingCart; |
| 23 import org.chromium.chrome.browser.preferences.PreferencesLauncher; | 23 import org.chromium.chrome.browser.preferences.PreferencesLauncher; |
| 24 import org.chromium.chrome.browser.preferences.autofill.AutofillCreditCardEditor
; | 24 import org.chromium.chrome.browser.preferences.autofill.AutofillCreditCardEditor
; |
| 25 import org.chromium.chrome.browser.preferences.autofill.AutofillProfileEditor; | 25 import org.chromium.chrome.browser.preferences.autofill.AutofillProfileEditor; |
| 26 import org.chromium.chrome.browser.profiles.Profile; | 26 import org.chromium.chrome.browser.profiles.Profile; |
| 27 import org.chromium.chrome.browser.util.UrlUtilities; | 27 import org.chromium.chrome.browser.util.UrlUtilities; |
| 28 import org.chromium.components.safejson.JsonSanitizer; | 28 import org.chromium.components.safejson.JsonSanitizer; |
| 29 import org.chromium.content.browser.ContentViewCore; | 29 import org.chromium.content.browser.ContentViewCore; |
| 30 import org.chromium.content_public.browser.WebContents; | 30 import org.chromium.content_public.browser.WebContents; |
| 31 import org.chromium.mojo.system.MojoException; | 31 import org.chromium.mojo.system.MojoException; |
| 32 import org.chromium.mojom.payments.PaymentComplete; |
| 32 import org.chromium.mojom.payments.PaymentDetails; | 33 import org.chromium.mojom.payments.PaymentDetails; |
| 33 import org.chromium.mojom.payments.PaymentItem; | 34 import org.chromium.mojom.payments.PaymentItem; |
| 34 import org.chromium.mojom.payments.PaymentMethodData; | 35 import org.chromium.mojom.payments.PaymentMethodData; |
| 35 import org.chromium.mojom.payments.PaymentOptions; | 36 import org.chromium.mojom.payments.PaymentOptions; |
| 36 import org.chromium.mojom.payments.PaymentRequest; | 37 import org.chromium.mojom.payments.PaymentRequest; |
| 37 import org.chromium.mojom.payments.PaymentRequestClient; | 38 import org.chromium.mojom.payments.PaymentRequestClient; |
| 38 import org.chromium.mojom.payments.PaymentResponse; | 39 import org.chromium.mojom.payments.PaymentResponse; |
| 39 import org.chromium.mojom.payments.ShippingOption; | 40 import org.chromium.mojom.payments.ShippingOption; |
| 40 import org.chromium.ui.base.WindowAndroid; | 41 import org.chromium.ui.base.WindowAndroid; |
| 41 import org.json.JSONException; | 42 import org.json.JSONException; |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 PaymentOption selectedShippingOption, PaymentOption selectedPaymentM
ethod) { | 547 PaymentOption selectedShippingOption, PaymentOption selectedPaymentM
ethod) { |
| 547 assert selectedPaymentMethod instanceof PaymentInstrument; | 548 assert selectedPaymentMethod instanceof PaymentInstrument; |
| 548 PaymentInstrument instrument = (PaymentInstrument) selectedPaymentMethod
; | 549 PaymentInstrument instrument = (PaymentInstrument) selectedPaymentMethod
; |
| 549 instrument.getDetails(mMerchantName, mOrigin, mRawTotal, mRawLineItems, | 550 instrument.getDetails(mMerchantName, mOrigin, mRawTotal, mRawLineItems, |
| 550 mMethodData.get(instrument.getMethodName()), this); | 551 mMethodData.get(instrument.getMethodName()), this); |
| 551 } | 552 } |
| 552 | 553 |
| 553 @Override | 554 @Override |
| 554 public void onDismiss() { | 555 public void onDismiss() { |
| 555 disconnectFromClientWithDebugMessage("Dialog dismissed"); | 556 disconnectFromClientWithDebugMessage("Dialog dismissed"); |
| 556 closeUI(false); | 557 closeUI(PaymentComplete.FAIL); |
| 557 } | 558 } |
| 558 | 559 |
| 559 @Override | 560 @Override |
| 560 public boolean merchantNeedsShippingAddress() { | 561 public boolean merchantNeedsShippingAddress() { |
| 561 return mMerchantNeedsShippingAddress; | 562 return mMerchantNeedsShippingAddress; |
| 562 } | 563 } |
| 563 | 564 |
| 564 /** | 565 /** |
| 565 * Called by the merchant website to abort the payment. | 566 * Called by the merchant website to abort the payment. |
| 566 */ | 567 */ |
| 567 @Override | 568 @Override |
| 568 public void abort() { | 569 public void abort() { |
| 569 closeClient(); | 570 closeClient(); |
| 570 closeUI(false); | 571 closeUI(PaymentComplete.FAIL); |
| 571 } | 572 } |
| 572 | 573 |
| 573 /** | 574 /** |
| 574 * Called when the merchant website has processed the payment. | 575 * Called when the merchant website has processed the payment. |
| 575 */ | 576 */ |
| 576 @Override | 577 @Override |
| 577 public void complete(boolean success) { | 578 public void complete(int result) { |
| 578 closeUI(success); | 579 closeUI(result); |
| 579 } | 580 } |
| 580 | 581 |
| 581 /** | 582 /** |
| 582 * Called when the renderer closes the Mojo connection. | 583 * Called when the renderer closes the Mojo connection. |
| 583 */ | 584 */ |
| 584 @Override | 585 @Override |
| 585 public void close() { | 586 public void close() { |
| 586 closeClient(); | 587 closeClient(); |
| 587 closeUI(false); | 588 closeUI(PaymentComplete.FAIL); |
| 588 } | 589 } |
| 589 | 590 |
| 590 /** | 591 /** |
| 591 * Called when the Mojo connection encounters an error. | 592 * Called when the Mojo connection encounters an error. |
| 592 */ | 593 */ |
| 593 @Override | 594 @Override |
| 594 public void onConnectionError(MojoException e) { | 595 public void onConnectionError(MojoException e) { |
| 595 closeClient(); | 596 closeClient(); |
| 596 closeUI(false); | 597 closeUI(PaymentComplete.FAIL); |
| 597 } | 598 } |
| 598 | 599 |
| 599 /** | 600 /** |
| 600 * Called after retrieving the list of payment instruments in an app. | 601 * Called after retrieving the list of payment instruments in an app. |
| 601 */ | 602 */ |
| 602 @Override | 603 @Override |
| 603 public void onInstrumentsReady(PaymentApp app, List<PaymentInstrument> instr
uments) { | 604 public void onInstrumentsReady(PaymentApp app, List<PaymentInstrument> instr
uments) { |
| 604 mPendingApps.remove(app); | 605 mPendingApps.remove(app); |
| 605 | 606 |
| 606 if (instruments != null) { | 607 if (instruments != null) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 | 649 |
| 649 mClient.onPaymentResponse(response); | 650 mClient.onPaymentResponse(response); |
| 650 } | 651 } |
| 651 | 652 |
| 652 /** | 653 /** |
| 653 * Called if unable to retrieve instrument details. | 654 * Called if unable to retrieve instrument details. |
| 654 */ | 655 */ |
| 655 @Override | 656 @Override |
| 656 public void onInstrumentDetailsError() { | 657 public void onInstrumentDetailsError() { |
| 657 disconnectFromClientWithDebugMessage("Failed to retrieve payment instrum
ent details"); | 658 disconnectFromClientWithDebugMessage("Failed to retrieve payment instrum
ent details"); |
| 658 closeUI(false); | 659 closeUI(PaymentComplete.FAIL); |
| 659 } | 660 } |
| 660 | 661 |
| 661 private void disconnectFromClientWithDebugMessage(String debugMessage) { | 662 private void disconnectFromClientWithDebugMessage(String debugMessage) { |
| 662 Log.d(TAG, debugMessage); | 663 Log.d(TAG, debugMessage); |
| 663 mClient.onError(); | 664 mClient.onError(); |
| 664 closeClient(); | 665 closeClient(); |
| 665 } | 666 } |
| 666 | 667 |
| 667 /** | 668 /** |
| 668 * Closes the UI. If the client is still connected, then it's notified of UI
hiding. | 669 * Closes the UI. If the client is still connected, then it's notified of UI
hiding. |
| 669 */ | 670 */ |
| 670 private void closeUI(boolean paymentSuccess) { | 671 private void closeUI(int result) { |
| 672 PaymentComplete.validate(result); |
| 671 if (mUI != null) { | 673 if (mUI != null) { |
| 672 mUI.close(paymentSuccess, new Runnable() { | 674 mUI.close(result, new Runnable() { |
| 673 @Override | 675 @Override |
| 674 public void run() { | 676 public void run() { |
| 675 if (mClient != null) mClient.onComplete(); | 677 if (mClient != null) mClient.onComplete(); |
| 676 closeClient(); | 678 closeClient(); |
| 677 } | 679 } |
| 678 }); | 680 }); |
| 679 mUI = null; | 681 mUI = null; |
| 680 } | 682 } |
| 681 | 683 |
| 682 if (mPaymentMethodsSection != null) { | 684 if (mPaymentMethodsSection != null) { |
| 683 for (int i = 0; i < mPaymentMethodsSection.getSize(); i++) { | 685 for (int i = 0; i < mPaymentMethodsSection.getSize(); i++) { |
| 684 PaymentOption option = mPaymentMethodsSection.getItem(i); | 686 PaymentOption option = mPaymentMethodsSection.getItem(i); |
| 685 assert option instanceof PaymentInstrument; | 687 assert option instanceof PaymentInstrument; |
| 686 ((PaymentInstrument) option).dismiss(); | 688 ((PaymentInstrument) option).dismiss(); |
| 687 } | 689 } |
| 688 mPaymentMethodsSection = null; | 690 mPaymentMethodsSection = null; |
| 689 } | 691 } |
| 690 } | 692 } |
| 691 | 693 |
| 692 private void closeClient() { | 694 private void closeClient() { |
| 693 if (mClient != null) mClient.close(); | 695 if (mClient != null) mClient.close(); |
| 694 mClient = null; | 696 mClient = null; |
| 695 } | 697 } |
| 696 } | 698 } |
| OLD | NEW |