From f26d8e1ae6a38208346425d1e33ebf62176349aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez?= Date: Mon, 3 Jun 2013 09:48:58 +0200 Subject: [PATCH] Bug 872987 - [WebPayment] Expose ICC info to the payment provider. r=fabrice --- b2g/chrome/content/payment.js | 133 ++++++++++++++++++++-------------- b2g/chrome/jar.mn | 2 +- 2 files changed, 81 insertions(+), 54 deletions(-) diff --git a/b2g/chrome/content/payment.js b/b2g/chrome/content/payment.js index fb6deb1caf70..460ee64d6aca 100644 --- a/b2g/chrome/content/payment.js +++ b/b2g/chrome/content/payment.js @@ -22,77 +22,104 @@ XPCOMUtils.defineLazyServiceGetter(this, "uuidgen", "@mozilla.org/uuid-generator;1", "nsIUUIDGenerator"); +#ifdef MOZ_B2G_RIL +XPCOMUtils.defineLazyServiceGetter(this, "mobileConnection", + "@mozilla.org/ril/content-helper;1", + "nsIMobileConnectionProvider"); +#endif + + const kClosePaymentFlowEvent = "close-payment-flow-dialog"; -let requestId; +let _requestId; -function paymentSuccess(aResult) { - closePaymentFlowDialog(function notifySuccess() { - if (!requestId) { +let PaymentProvider = { + + __exposedProps__: { + paymentSuccess: 'r', + paymentFailed: 'r', + iccIds: 'r' + }, + + _closePaymentFlowDialog: function _closePaymentFlowDialog(aCallback) { + // After receiving the payment provider confirmation about the + // successful or failed payment flow, we notify the UI to close the + // payment flow dialog and return to the caller application. + let id = kClosePaymentFlowEvent + "-" + uuidgen.generateUUID().toString(); + + let browser = Services.wm.getMostRecentWindow("navigator:browser"); + let content = browser.getContentWindow(); + if (!content) { return; } - cpmm.sendAsyncMessage("Payment:Success", { result: aResult, - requestId: requestId }); - }); -} -function paymentFailed(aErrorMsg) { - closePaymentFlowDialog(function notifyError() { - if (!requestId) { - return; - } - cpmm.sendAsyncMessage("Payment:Failed", { errorMsg: aErrorMsg, - requestId: requestId }); - }); -} + let detail = { + type: kClosePaymentFlowEvent, + id: id, + requestId: _requestId + }; -function closePaymentFlowDialog(aCallback) { - // After receiving the payment provider confirmation about the - // successful or failed payment flow, we notify the UI to close the - // payment flow dialog and return to the caller application. - let randomId = uuidgen.generateUUID().toString(); - let id = kClosePaymentFlowEvent + "-" + randomId; + // In order to avoid race conditions, we wait for the UI to notify that + // it has successfully closed the payment flow and has recovered the + // caller app, before notifying the parent process to fire the success + // or error event over the DOMRequest. + content.addEventListener("mozContentEvent", + function closePaymentFlowReturn(evt) { + if (evt.detail.id == id && aCallback) { + aCallback(); + } - let browser = Services.wm.getMostRecentWindow("navigator:browser"); - let content = browser.getContentWindow(); - if (!content) { - return; - } + content.removeEventListener("mozContentEvent", + closePaymentFlowReturn); - let detail = { - type: kClosePaymentFlowEvent, - id: id, - requestId: requestId - }; + let glue = Cc["@mozilla.org/payment/ui-glue;1"] + .createInstance(Ci.nsIPaymentUIGlue); + glue.cleanup(); + }); - // In order to avoid race conditions, we wait for the UI to notify that - // it has successfully closed the payment flow and has recovered the - // caller app, before notifying the parent process to fire the success - // or error event over the DOMRequest. - content.addEventListener("mozContentEvent", - function closePaymentFlowReturn(evt) { - if (evt.detail.id == id && aCallback) { - aCallback(); - } + browser.shell.sendChromeEvent(detail); + }, - content.removeEventListener("mozContentEvent", - closePaymentFlowReturn); + paymentSuccess: function paymentSuccess(aResult) { + this._closePaymentFlowDialog(function notifySuccess() { + if (!_requestId) { + return; + } + cpmm.sendAsyncMessage("Payment:Success", { result: aResult, + requestId: _requestId }); + }); + }, - let glue = Cc["@mozilla.org/payment/ui-glue;1"] - .createInstance(Ci.nsIPaymentUIGlue); - glue.cleanup(); - }); + paymentFailed: function paymentFailed(aErrorMsg) { + this._closePaymentFlowDialog(function notifyError() { + if (!_requestId) { + return; + } + cpmm.sendAsyncMessage("Payment:Failed", { errorMsg: aErrorMsg, + requestId: _requestId }); + }); + }, - browser.shell.sendChromeEvent(detail); -} + get iccIds() { +#ifdef MOZ_B2G_RIL + // Until bug 814629 is done, we only have support for a single SIM, so we + // can only provide a single ICC ID. However, we return an array so the + // payment provider facing API won't need to change once we support + // multiple SIMs. + return [mobileConnection.iccInfo.iccid]; +#else + return null; +#endif + }, + +}; // We save the identifier of the DOM request, so we can dispatch the results // of the payment flow to the appropriate content process. addMessageListener("Payment:LoadShim", function receiveMessage(aMessage) { - requestId = aMessage.json.requestId; + _requestId = aMessage.json.requestId; }); addEventListener("DOMWindowCreated", function(e) { - content.wrappedJSObject.paymentSuccess = paymentSuccess; - content.wrappedJSObject.paymentFailed = paymentFailed; + content.wrappedJSObject.mozPaymentProvider = PaymentProvider; }); diff --git a/b2g/chrome/jar.mn b/b2g/chrome/jar.mn index 2104fdbf2e5a..4de0aafbd9aa 100644 --- a/b2g/chrome/jar.mn +++ b/b2g/chrome/jar.mn @@ -21,7 +21,7 @@ chrome.jar: * content/content.css (content/content.css) content/touchcontrols.css (content/touchcontrols.css) - content/payment.js (content/payment.js) +* content/payment.js (content/payment.js) content/identity.js (content/identity.js) % override chrome://global/content/netError.xhtml chrome://browser/content/netError.xhtml