Bug 1423053 - Close the PaymentRequest UI when complete is called. r=jaws
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Tue, 19 Dec 2017 05:55:29 -0600
changeset 397057 6604f8508dd9ffa6430beae09f105b295b466a11
parent 397056 c6463d58d76623c1823d98e0e217c7760f1ef047
child 397058 a25d929f127e535f353fd36e23555c92c0f402c1
push id33123
push userncsoregi@mozilla.com
push dateThu, 21 Dec 2017 10:00:47 +0000
treeherdermozilla-central@06a19fbe2581 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1423053
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1423053 - Close the PaymentRequest UI when complete is called. r=jaws https://w3c.github.io/payment-request/#complete-method MozReview-Commit-ID: 3CJkunoby30
toolkit/components/payments/paymentUIService.js
--- a/toolkit/components/payments/paymentUIService.js
+++ b/toolkit/components/payments/paymentUIService.js
@@ -52,51 +52,64 @@ PaymentUIService.prototype = {
                             `${this.REQUEST_ID_PREFIX}${requestId}`,
                             "modal,dialog,centerscreen,resizable=no");
   },
 
   abortPayment(requestId) {
     this.log.debug("abortPayment:", requestId);
     let abortResponse = Cc["@mozilla.org/dom/payments/payment-abort-action-response;1"]
                           .createInstance(Ci.nsIPaymentAbortActionResponse);
-
-    let enu = Services.wm.getEnumerator(null);
-    let win;
-    while ((win = enu.getNext())) {
-      if (win.name == `${this.REQUEST_ID_PREFIX}${requestId}`) {
-        this.log.debug(`closing: ${win.name}`);
-        win.close();
-        break;
-      }
-    }
+    let found = this.closeDialog(requestId);
 
     // if `win` is falsy, then we haven't found the dialog, so the abort fails
     // otherwise, the abort is successful
-    let response = win ?
+    let response = found ?
       Ci.nsIPaymentActionResponse.ABORT_SUCCEEDED :
       Ci.nsIPaymentActionResponse.ABORT_FAILED;
 
     abortResponse.init(requestId, response);
     paymentSrv.respondPayment(abortResponse);
   },
 
   completePayment(requestId) {
     this.log.debug("completePayment:", requestId);
+    let closed = this.closeDialog(requestId);
+    let responseCode = closed ?
+        Ci.nsIPaymentActionResponse.COMPLETE_SUCCEEDED :
+        Ci.nsIPaymentActionResponse.COMPLETE_FAILED;
     let completeResponse = Cc["@mozilla.org/dom/payments/payment-complete-action-response;1"]
                              .createInstance(Ci.nsIPaymentCompleteActionResponse);
-    completeResponse.init(requestId, Ci.nsIPaymentActionResponse.COMPLTETE_SUCCEEDED);
+    completeResponse.init(requestId, responseCode);
     paymentSrv.respondPayment(completeResponse.QueryInterface(Ci.nsIPaymentActionResponse));
   },
 
   updatePayment(requestId) {
     this.log.debug("updatePayment:", requestId);
   },
 
   // other helper methods
 
+  /**
+   * @param {string} requestId - Payment Request ID of the dialog to close.
+   * @returns {boolean} whether the specified dialog was closed.
+   */
+  closeDialog(requestId) {
+    let enu = Services.wm.getEnumerator(null);
+    let win;
+    while ((win = enu.getNext())) {
+      if (win.name == `${this.REQUEST_ID_PREFIX}${requestId}`) {
+        this.log.debug(`closing: ${win.name}`);
+        win.close();
+        return true;
+      }
+    }
+
+    return false;
+  },
+
   requestIdForWindow(window) {
     let windowName = window.name;
 
     return windowName.startsWith(this.REQUEST_ID_PREFIX) ?
       windowName.replace(this.REQUEST_ID_PREFIX, "") : // returns suffix, which is the requestId
       null;
   },
 };