Bug 1381186 - open/close stub dialog on (show/abort)Payment. r=MattN

MozReview-Commit-ID: K3YyFlIttjD

--HG--
extra : rebase_source : 97639e91e6d35ade1fa11cea5ae923fa522bc44a
This commit is contained in:
Jonathan Guillotte-Blouin 2017-07-17 13:29:21 -07:00
parent 6eb7aef00e
commit 759140610e
4 changed files with 36 additions and 2 deletions

View File

@ -5728,6 +5728,7 @@ pref("dom.timeout.max_consecutive_callbacks_ms", 4);
// Use this preference to house "Payment Request API" during development
pref("dom.payments.request.enabled", false);
pref("dom.payments.loglevel", "Warn");
#ifdef FUZZING
pref("fuzzing.enabled", false);

View File

@ -11,7 +11,7 @@
</head>
<body>
<div id="controls-container">
<button id="cancel"></button>
<button id="cancel" onclick="window.close()">Cancel payment</button>
</div>
</body>
</html>

View File

@ -9,25 +9,57 @@ const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
const DIALOG_URL = "chrome://payments/content/paymentRequest.xhtml";
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyServiceGetter(this,
"paymentSrv",
"@mozilla.org/dom/payments/payment-request-service;1",
"nsIPaymentRequestService");
function PaymentUIService() {}
function defineLazyLogGetter(scope, logPrefix) {
XPCOMUtils.defineLazyGetter(scope, "log", () => {
let {ConsoleAPI} = Cu.import("resource://gre/modules/Console.jsm", {});
return new ConsoleAPI({
maxLogLevelPref: "dom.payments.loglevel",
prefix: logPrefix,
});
});
}
function PaymentUIService() {
defineLazyLogGetter(this, "Payment UI Service");
paymentSrv.setTestingUIService(this);
this.log.debug("constructor");
}
PaymentUIService.prototype = {
classID: Components.ID("{01f8bd55-9017-438b-85ec-7c15d2b35cdc}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIPaymentUIService]),
REQUEST_ID_PREFIX: "paymentRequest-",
showPayment(requestId) {
this.log.debug("showPayment");
let chromeWindow = Services.wm.getMostRecentWindow("navigator:browser");
chromeWindow.openDialog(DIALOG_URL,
`${this.REQUEST_ID_PREFIX}${requestId}`,
"modal,dialog,centerscreen");
},
abortPayment(requestId) {
this.log.debug(`abortPayment: ${requestId}`);
let abortResponse = Cc["@mozilla.org/dom/payments/payment-abort-action-response;1"]
.createInstance(Ci.nsIPaymentAbortActionResponse);
abortResponse.init(requestId, Ci.nsIPaymentActionResponse.ABORT_SUCCEEDED);
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;
}
}
paymentSrv.respondPayment(abortResponse.QueryInterface(Ci.nsIPaymentActionResponse));
},

View File

@ -1,2 +1,3 @@
component {01f8bd55-9017-438b-85ec-7c15d2b35cdc} paymentUIService.js
contract @mozilla.org/dom/payments/payment-ui-service;1 {01f8bd55-9017-438b-85ec-7c15d2b35cdc}
category profile-after-change PaymentUIService @mozilla.org/dom/payments/payment-ui-service;1