Bug 872987 - [WebPayment] Expose ICC info to the payment provider. r=fabrice
authorFernando Jiménez <ferjmoreno@gmail.com>
Mon, 03 Jun 2013 09:48:58 +0200
changeset 133804 40bea9a5a19e5b7b4b6252b3e15cb7689736ed63
parent 133803 850e5446d4a6a2b60582bde5e4792f1560ce3c72
child 133805 81b59ee890a7a634915e330c8204a6de40bf6b3f
push id28905
push userryanvm@gmail.com
push dateMon, 03 Jun 2013 15:58:12 +0000
treeherdermozilla-inbound@d2eabe8e27b5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice
bugs872987
milestone24.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 872987 - [WebPayment] Expose ICC info to the payment provider. r=fabrice
b2g/chrome/content/payment.js
b2g/chrome/jar.mn
--- a/b2g/chrome/content/payment.js
+++ b/b2g/chrome/content/payment.js
@@ -17,82 +17,109 @@ Cu.import("resource://gre/modules/XPCOMU
 XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
                                    "@mozilla.org/childprocessmessagemanager;1",
                                    "nsIMessageSender");
 
 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;
+
+let PaymentProvider = {
+
+  __exposedProps__: {
+    paymentSuccess: 'r',
+    paymentFailed: 'r',
+    iccIds: 'r'
+  },
 
-function paymentSuccess(aResult) {
-  closePaymentFlowDialog(function notifySuccess() {
-    if (!requestId) {
-      return;
-    }
-    cpmm.sendAsyncMessage("Payment:Success", { result: aResult,
-                                               requestId: requestId });
-  });
-}
+  _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();
 
-function paymentFailed(aErrorMsg) {
-  closePaymentFlowDialog(function notifyError() {
-    if (!requestId) {
+    let browser = Services.wm.getMostRecentWindow("navigator:browser");
+    let content = browser.getContentWindow();
+    if (!content) {
       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 glue = Cc["@mozilla.org/payment/ui-glue;1"]
+                   .createInstance(Ci.nsIPaymentUIGlue);
+      glue.cleanup();
+    });
+
+    browser.shell.sendChromeEvent(detail);
+  },
 
-  let detail = {
-    type: kClosePaymentFlowEvent,
-    id: id,
-    requestId: requestId
-  };
+  paymentSuccess: function paymentSuccess(aResult) {
+    this._closePaymentFlowDialog(function notifySuccess() {
+      if (!_requestId) {
+        return;
+      }
+      cpmm.sendAsyncMessage("Payment:Success", { result: aResult,
+                                                 requestId: _requestId });
+    });
+  },
 
-  // 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();
-    }
+  paymentFailed: function paymentFailed(aErrorMsg) {
+    this._closePaymentFlowDialog(function notifyError() {
+      if (!_requestId) {
+        return;
+      }
+      cpmm.sendAsyncMessage("Payment:Failed", { errorMsg: aErrorMsg,
+                                                requestId: _requestId });
+    });
+  },
 
-    content.removeEventListener("mozContentEvent",
-                                closePaymentFlowReturn);
+  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
+  },
 
-    let glue = Cc["@mozilla.org/payment/ui-glue;1"]
-                 .createInstance(Ci.nsIPaymentUIGlue);
-    glue.cleanup();
-  });
-
-  browser.shell.sendChromeEvent(detail);
-}
+};
 
 // 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;
 });
--- a/b2g/chrome/jar.mn
+++ b/b2g/chrome/jar.mn
@@ -16,17 +16,17 @@ chrome.jar:
 * content/shell.js                      (content/shell.js)
 #ifndef ANDROID
   content/screen.js                     (content/screen.js)
   content/runapp.js                     (content/runapp.js)
 #endif
 * 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
 % override chrome://global/skin/netError.css chrome://browser/content/netError.css
 % override chrome://global/skin/media/videocontrols.css chrome://browser/content/touchcontrols.css
 % override chrome://global/content/aboutCertError.xhtml chrome://browser/content/aboutCertError.xhtml
 
   content/ErrorPage.js                  (content/ErrorPage.js)