Bug 784678 - Error when calling postCancel and postSuccess in an activity : followup [r=mrbkap]
authorFabrice Desré <fabrice@mozilla.com>
Thu, 23 Aug 2012 11:56:36 -0700
changeset 105240 b173c738d021d6fd655c31a0e68305858cdf841b
parent 105237 f4c286fc04f0a4275cdb24546a916f3750f58a8d
child 105241 da0aa4b65f8429596939f3ef441af682d1ca60e9
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersmrbkap
bugs784678
milestone17.0a1
Bug 784678 - Error when calling postCancel and postSuccess in an activity : followup [r=mrbkap]
dom/activities/src/ActivityWrapper.js
dom/messages/SystemMessageManager.js
--- a/dom/activities/src/ActivityWrapper.js
+++ b/dom/activities/src/ActivityWrapper.js
@@ -1,26 +1,26 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
- 
+
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
- 
+
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 function debug(aMsg) {
   //dump("-- ActivityWrapper.js " + Date.now() + " : " + aMsg + "\n");
 }
 
 /**
-  * nsISystemMessagesWrapper implementation. Will return a 
+  * nsISystemMessagesWrapper implementation. Will return a
   * nsIDOMMozActivityRequestHandler
   */
 function ActivityWrapper() {
   debug("ActivityWrapper");
 }
 
 ActivityWrapper.prototype = {
   wrapMessage: function wrapMessage(aMessage) {
--- a/dom/messages/SystemMessageManager.js
+++ b/dom/messages/SystemMessageManager.js
@@ -23,18 +23,18 @@ XPCOMUtils.defineLazyGetter(this, "cpmm"
 let kMaxPendingMessages;
 try {
   kMaxPendingMessages = Services.prefs.getIntPref("dom.messages.maxPendingMessages");
 } catch(e) {
   // getIntPref throws when the pref is not set.
   kMaxPendingMessages = 5;
 }
 
-function debug(aMsg) { 
-  //dump("-- SystemMessageManager " + Date.now() + " : " + aMsg + "\n"); 
+function debug(aMsg) {
+  //dump("-- SystemMessageManager " + Date.now() + " : " + aMsg + "\n");
 }
 
 // Implementation of the DOM API for system messages
 
 function SystemMessageManager() {
   // Message handlers for this page.
   // We can have only one handler per message type.
   this._handlers = {};
@@ -49,27 +49,29 @@ SystemMessageManager.prototype = {
   _dispatchMessage: function sysMessMgr_dispatchMessage(aType, aHandler, aMessage) {
     // We get a json blob, but in some cases we want another kind of object
     // to be dispatched.
     // To do so, we check if we have a with a contract ID of
     // "@mozilla.org/dom/system-messages/wrapper/TYPE;1" component implementing
     // nsISystemMessageWrapper.
     debug("Dispatching " + JSON.stringify(aMessage) + "\n");
     let contractID = "@mozilla.org/dom/system-messages/wrapper/" + aType + ";1";
+    let wrapped = false;
 
     if (contractID in Cc) {
       debug(contractID + " is registered, creating an instance");
       let wrapper = Cc[contractID].createInstance(Ci.nsISystemMessagesWrapper);
       if (wrapper) {
         aMessage = wrapper.wrapMessage(aMessage);
+        wrapped = true;
         debug("wrapped = " + aMessage);
       }
     }
 
-    aHandler.handleMessage(ObjectWrapper.wrap(aMessage, this._window));
+    aHandler.handleMessage(wrapped ? aMessage : ObjectWrapper.wrap(aMessage, this._window));
   },
 
   mozSetMessageHandler: function sysMessMgr_setMessageHandler(aType, aHandler) {
     debug("setMessage handler for [" + aType + "] " + aHandler);
     if (!aType) {
       // Just bail out if we have no type.
       return;
     }
@@ -107,19 +109,19 @@ SystemMessageManager.prototype = {
 
     // If we have a handler for this type, we can't have any pending message.
     // If called from setMessageHandler, we still want to update the pending
     // queue to deliver existing messages.
     if (aType in this._handlers && !aForceUpdate) {
       return false;
     }
 
-    // Send a sync message to the parent to check if we have a pending message 
+    // Send a sync message to the parent to check if we have a pending message
     // for this type.
-    let messages = cpmm.sendSyncMessage("SystemMessageManager:GetPending", 
+    let messages = cpmm.sendSyncMessage("SystemMessageManager:GetPending",
                                         { type: aType,
                                           uri: this._uri,
                                           manifest: this._manifest })[0];
     if (!messages) {
       // No new pending messages, but the queue may not be empty yet.
       return pendings[aType] && pendings[aType].length != 0;
     }
 
@@ -143,17 +145,17 @@ SystemMessageManager.prototype = {
   },
 
   uninit: function sysMessMgr_uninit()  {
     this._handlers = null;
     this._pendings =  null;
   },
 
   receiveMessage: function sysMessMgr_receiveMessage(aMessage) {
-    debug("receiveMessage " + aMessage.name + " - " + 
+    debug("receiveMessage " + aMessage.name + " - " +
           aMessage.json.type + " for " + aMessage.json.manifest +
           " (" + this._manifest + ")");
 
     let msg = aMessage.json;
     if (msg.manifest != this._manifest)
       return;
 
     // Bail out if we have no handlers registered for this type.