Bug 1423053 - Close the PaymentRequest UI when complete is called. r=jaws

https://w3c.github.io/payment-request/#complete-method

MozReview-Commit-ID: 3CJkunoby30

--HG--
extra : rebase_source : c0d0a7b36f2857de1a9af1ddfe6520c620e5d4b4
This commit is contained in:
Matthew Noorenberghe 2017-12-19 05:55:29 -06:00
Родитель 13ff0fa546
Коммит aae6257dfc
1 изменённых файлов: 25 добавлений и 12 удалений

Просмотреть файл

@ -57,20 +57,11 @@ PaymentUIService.prototype = {
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;
@ -80,9 +71,13 @@ PaymentUIService.prototype = {
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));
},
@ -92,6 +87,24 @@ PaymentUIService.prototype = {
// 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;