Bug 1381186 - open/close stub dialog on (show/abort)Payment. r=mattn draft
authorJonathan Guillotte-Blouin <jguillotteblouin@mozilla.com>
Mon, 17 Jul 2017 13:29:21 -0700
changeset 643603 cfb1a451a460dda3716bf20770912eb5f3c50ebd
parent 643173 4c5fbf49376351679dcc49f4cff26c3c2e055ccc
child 643604 a229078e15d583435ad1f704a3a3c15c671e8673
child 643606 a1a1e138eca8cb278743bd25c71874cf012f9e02
push id73145
push userbmo:jguillotteblouin@mozilla.com
push dateWed, 09 Aug 2017 22:54:29 +0000
reviewersmattn
bugs1381186
milestone57.0a1
Bug 1381186 - open/close stub dialog on (show/abort)Payment. r=mattn MozReview-Commit-ID: K3YyFlIttjD
modules/libpref/init/all.js
toolkit/components/payments/content/paymentRequest.xhtml
toolkit/components/payments/paymentUIService.js
toolkit/components/payments/payments.manifest
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5728,16 +5728,17 @@ pref("dom.IntersectionObserver.enabled",
 pref("dom.moduleScripts.enabled", false);
 
 // Maximum amount of time in milliseconds consecutive setTimeout()/setInterval()
 // callback are allowed to run before yielding the event loop.
 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);
 #endif
 
 #if defined(XP_WIN)
 #if defined(NIGHTLY_BUILD)
 pref("layers.mlgpu.dev-enabled", true);
--- a/toolkit/components/payments/content/paymentRequest.xhtml
+++ b/toolkit/components/payments/content/paymentRequest.xhtml
@@ -6,12 +6,12 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
   <title></title>
   <link rel="stylesheet" href="chrome://payments/content/paymentRequest.css" />
   <script src="chrome://payments/content/paymentRequest.js"></script>
 </head>
 <body>
   <div id="controls-container">
-    <button id="cancel"></button>
+    <button id="cancel" onclick="window.close()">Cancel payment</button>
   </div>
 </body>
 </html>
--- a/toolkit/components/payments/paymentUIService.js
+++ b/toolkit/components/payments/paymentUIService.js
@@ -4,35 +4,67 @@
 
 "use strict";
 
 const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
 // eslint-disable-next-line no-unused-vars
 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));
   },
 
   completePayment(requestId) {
     let completeResponse = Cc["@mozilla.org/dom/payments/payment-complete-action-response;1"]
                              .createInstance(Ci.nsIPaymentCompleteActionResponse);
     completeResponse.init(requestId, Ci.nsIPaymentActionResponse.COMPLTETE_SUCCEEDED);
     paymentSrv.respondPayment(completeResponse.QueryInterface(Ci.nsIPaymentActionResponse));
--- a/toolkit/components/payments/payments.manifest
+++ b/toolkit/components/payments/payments.manifest
@@ -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