From 776cba4c589335da19c3179498f5d13de0e8eb72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez?= Date: Fri, 21 Sep 2012 09:20:05 +0200 Subject: [PATCH] Bug 776417 - Prevent navigator.mozPay from being fired from apps in the background; r=fabrice --- dom/payment/Payment.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/dom/payment/Payment.js b/dom/payment/Payment.js index 98d1ed623aca..ba8da152837c 100644 --- a/dom/payment/Payment.js +++ b/dom/payment/Payment.js @@ -46,9 +46,27 @@ PaymentContentHelper.prototype = { pay: function pay(aJwts) { let request = this.createRequest(); let requestId = this.getRequestId(request); + + let docShell = this._window.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebNavigation) + .QueryInterface(Ci.nsIDocShell); + if (!docShell.isActive) { + debug("The caller application is a background app. No request " + + "will be sent"); + let runnable = { + run: function run() { + Services.DOMRequest.fireError(request, "BACKGROUND_APP"); + } + } + Services.tm.currentThread.dispatch(runnable, + Ci.nsIThread.DISPATCH_NORMAL); + return request; + } + if (!Array.isArray(aJwts)) { aJwts = [aJwts]; } + cpmm.sendAsyncMessage("Payment:Pay", { jwts: aJwts, requestId: requestId @@ -59,6 +77,7 @@ PaymentContentHelper.prototype = { // nsIDOMGlobalPropertyInitializer init: function(aWindow) { + this._window = aWindow; this.initHelper(aWindow, PAYMENT_IPC_MSG_NAMES); return this.pay.bind(this); },