mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-09 08:48:07 +00:00
Bug 872987 - [WebPayment] Expose ICC info to the payment provider. r=fabrice
This commit is contained in:
parent
c3aa52036a
commit
f26d8e1ae6
@ -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;
|
||||
});
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user