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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 public void onDismiss() { | 490 public void onDismiss() { |
491 disconnectFromClientWithDebugMessage("Dialog dismissed"); | 491 disconnectFromClientWithDebugMessage("Dialog dismissed"); |
492 closeUI(false); | 492 closeUI(false); |
493 } | 493 } |
494 | 494 |
495 /** | 495 /** |
496 * Called by the merchant website to abort the payment. | 496 * Called by the merchant website to abort the payment. |
497 */ | 497 */ |
498 @Override | 498 @Override |
499 public void abort() { | 499 public void abort() { |
500 mClient = null; | 500 closeClient(); |
501 closeUI(false); | 501 closeUI(false); |
502 } | 502 } |
503 | 503 |
504 /** | 504 /** |
505 * Called when the merchant website has processed the payment. | 505 * Called when the merchant website has processed the payment. |
506 */ | 506 */ |
507 @Override | 507 @Override |
508 public void complete(boolean success) { | 508 public void complete(boolean success) { |
509 closeUI(success); | 509 closeUI(success); |
510 } | 510 } |
511 | 511 |
512 /** | 512 /** |
513 * Called when the renderer closes the Mojo connection. | 513 * Called when the renderer closes the Mojo connection. |
514 */ | 514 */ |
515 @Override | 515 @Override |
516 public void close() { | 516 public void close() { |
517 mClient = null; | 517 closeClient(); |
518 closeUI(false); | 518 closeUI(false); |
519 } | 519 } |
520 | 520 |
521 /** | 521 /** |
522 * Called when the Mojo connection encounters an error. | 522 * Called when the Mojo connection encounters an error. |
523 */ | 523 */ |
524 @Override | 524 @Override |
525 public void onConnectionError(MojoException e) { | 525 public void onConnectionError(MojoException e) { |
526 mClient = null; | 526 closeClient(); |
527 closeUI(false); | 527 closeUI(false); |
528 } | 528 } |
529 | 529 |
530 /** | 530 /** |
531 * Called after retrieving the list of payment instruments in an app. | 531 * Called after retrieving the list of payment instruments in an app. |
532 */ | 532 */ |
533 @Override | 533 @Override |
534 public void onInstrumentsReady(PaymentApp app, List<PaymentInstrument> instr
uments) { | 534 public void onInstrumentsReady(PaymentApp app, List<PaymentInstrument> instr
uments) { |
535 mPendingApps.remove(app); | 535 mPendingApps.remove(app); |
536 | 536 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 */ | 588 */ |
589 @Override | 589 @Override |
590 public void onInstrumentDetailsError() { | 590 public void onInstrumentDetailsError() { |
591 disconnectFromClientWithDebugMessage("Failed to retrieve payment instrum
ent details"); | 591 disconnectFromClientWithDebugMessage("Failed to retrieve payment instrum
ent details"); |
592 closeUI(false); | 592 closeUI(false); |
593 } | 593 } |
594 | 594 |
595 private void disconnectFromClientWithDebugMessage(String debugMessage) { | 595 private void disconnectFromClientWithDebugMessage(String debugMessage) { |
596 Log.d(TAG, debugMessage); | 596 Log.d(TAG, debugMessage); |
597 mClient.onError(); | 597 mClient.onError(); |
598 mClient = null; | 598 closeClient(); |
599 } | 599 } |
600 | 600 |
601 /** | 601 /** |
602 * Closes the UI. If the client is still connected, then it's notified of UI
hiding. | 602 * Closes the UI. If the client is still connected, then it's notified of UI
hiding. |
603 */ | 603 */ |
604 private void closeUI(boolean paymentSuccess) { | 604 private void closeUI(boolean paymentSuccess) { |
605 if (mUI != null) { | 605 if (mUI != null) { |
606 mUI.close(paymentSuccess, new Runnable() { | 606 mUI.close(paymentSuccess, new Runnable() { |
607 @Override | 607 @Override |
608 public void run() { | 608 public void run() { |
609 if (mClient == null) return; | 609 if (mClient != null) mClient.onComplete(); |
610 mClient.onComplete(); | 610 closeClient(); |
611 mClient = null; | |
612 } | 611 } |
613 }); | 612 }); |
614 mUI = null; | 613 mUI = null; |
615 } | 614 } |
616 | 615 |
617 if (mPaymentMethodsSection != null) { | 616 if (mPaymentMethodsSection != null) { |
618 for (int i = 0; i < mPaymentMethodsSection.getSize(); i++) { | 617 for (int i = 0; i < mPaymentMethodsSection.getSize(); i++) { |
619 PaymentOption option = mPaymentMethodsSection.getItem(i); | 618 PaymentOption option = mPaymentMethodsSection.getItem(i); |
620 assert option instanceof PaymentInstrument; | 619 assert option instanceof PaymentInstrument; |
621 ((PaymentInstrument) option).dismiss(); | 620 ((PaymentInstrument) option).dismiss(); |
622 } | 621 } |
623 mPaymentMethodsSection = null; | 622 mPaymentMethodsSection = null; |
624 } | 623 } |
625 } | 624 } |
| 625 |
| 626 private void closeClient() { |
| 627 if (mClient != null) mClient.close(); |
| 628 mClient = null; |
| 629 } |
626 } | 630 } |
OLD | NEW |