Bug 872987 - [WebPayment] Expose ICC info to the payment provider. r=fabrice

This commit is contained in:
Fernando Jiménez 2013-06-03 09:48:58 +02:00
Родитель c3aa52036a
Коммит f26d8e1ae6
2 изменённых файлов: 81 добавлений и 54 удалений

Просмотреть файл

@ -22,36 +22,30 @@ 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) {
return;
}
cpmm.sendAsyncMessage("Payment:Success", { result: aResult,
requestId: requestId });
});
}
let PaymentProvider = {
function paymentFailed(aErrorMsg) {
closePaymentFlowDialog(function notifyError() {
if (!requestId) {
return;
}
cpmm.sendAsyncMessage("Payment:Failed", { errorMsg: aErrorMsg,
requestId: requestId });
});
}
__exposedProps__: {
paymentSuccess: 'r',
paymentFailed: 'r',
iccIds: 'r'
},
function closePaymentFlowDialog(aCallback) {
_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 randomId = uuidgen.generateUUID().toString();
let id = kClosePaymentFlowEvent + "-" + randomId;
let id = kClosePaymentFlowEvent + "-" + uuidgen.generateUUID().toString();
let browser = Services.wm.getMostRecentWindow("navigator:browser");
let content = browser.getContentWindow();
@ -62,7 +56,7 @@ function closePaymentFlowDialog(aCallback) {
let detail = {
type: kClosePaymentFlowEvent,
id: id,
requestId: requestId
requestId: _requestId
};
// In order to avoid race conditions, we wait for the UI to notify that
@ -84,15 +78,48 @@ function closePaymentFlowDialog(aCallback) {
});
browser.shell.sendChromeEvent(detail);
}
},
paymentSuccess: function paymentSuccess(aResult) {
this._closePaymentFlowDialog(function notifySuccess() {
if (!_requestId) {
return;
}
cpmm.sendAsyncMessage("Payment:Success", { result: aResult,
requestId: _requestId });
});
},
paymentFailed: function paymentFailed(aErrorMsg) {
this._closePaymentFlowDialog(function notifyError() {
if (!_requestId) {
return;
}
cpmm.sendAsyncMessage("Payment:Failed", { errorMsg: aErrorMsg,
requestId: _requestId });
});
},
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