Bug 776417 - Prevent navigator.mozPay from being fired from apps in the background; r=fabrice
authorFernando Jiménez <ferjmoreno@gmail.com>
Fri, 21 Sep 2012 09:20:05 +0200
changeset 107824 929786a618f4f124a49479b920acdd7c9a757fce
parent 107823 f1ad620dab86067f108e09ab7aead4457a6dc5b3
child 107825 a0b08694ac6d1f15275fa1639f5ee504b04e36fa
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersfabrice
bugs776417
milestone18.0a1
Bug 776417 - Prevent navigator.mozPay from being fired from apps in the background; r=fabrice
dom/payment/Payment.js
--- a/dom/payment/Payment.js
+++ b/dom/payment/Payment.js
@@ -41,29 +41,48 @@ PaymentContentHelper.prototype = {
     interfaces: [Ci.nsIDOMNavigatorPayment]
   }),
 
   // nsIDOMNavigatorPayment
 
   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
     });
     return request;
   },
 
   // nsIDOMGlobalPropertyInitializer
 
   init: function(aWindow) {
+    this._window = aWindow;
     this.initHelper(aWindow, PAYMENT_IPC_MSG_NAMES);
     return this.pay.bind(this);
   },
 
   // nsIFrameMessageListener
 
   receiveMessage: function receiveMessage(aMessage) {
     let name = aMessage.name;