Bug 785391 - Activities 'data' content cannot be accessed [r=gwagner]
authorFabrice Desré <fabrice@mozilla.com>
Fri, 24 Aug 2012 21:07:58 -0700
changeset 105404 005c47c479fa1d4bad341f08a7be881e01b43049
parent 105403 c9068173a7da089812e522340c48fb0d3a26f2c4
child 105405 a828ba358047fdfb71b2603adbcae1ed86c75125
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersgwagner
bugs785391
milestone17.0a1
Bug 785391 - Activities 'data' content cannot be accessed [r=gwagner]
dom/activities/interfaces/nsIActivityProxy.idl
dom/activities/src/Activity.cpp
dom/activities/src/ActivityProxy.js
dom/activities/src/ActivityWrapper.js
dom/messages/SystemMessageManager.js
dom/messages/interfaces/nsISystemMessagesInternal.idl
--- a/dom/activities/interfaces/nsIActivityProxy.idl
+++ b/dom/activities/interfaces/nsIActivityProxy.idl
@@ -1,18 +1,21 @@
 /* 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/. */
 
 #include "nsISupports.idl"
 
 interface nsIDOMMozActivity;
 interface nsIDOMMozActivityOptions;
+interface nsIDOMWindow;
 
 /**
   * Implemented by @mozilla.org/dom/activities/proxy;1
   */
-[scriptable, uuid(2241faf9-6219-4bc0-95f3-18651ac8a18b)]
+[scriptable, uuid(3f9e0695-f466-4111-a8fa-ed5c0751c42b)]
 interface nsIActivityProxy : nsISupports
 {
-    void startActivity(in nsIDOMMozActivity activity, in nsIDOMMozActivityOptions options);
+    void startActivity(in nsIDOMMozActivity activity,
+                       in nsIDOMMozActivityOptions options,
+                       in nsIDOMWindow window);
     void cleanup();
 };
--- a/dom/activities/src/Activity.cpp
+++ b/dom/activities/src/Activity.cpp
@@ -62,17 +62,17 @@ Activity::Initialize(nsISupports* aOwner
   }
 
   // Instantiate a JS proxy that will do the child <-> parent communication
   // with the JS implementation of the backend.
   nsresult rv;
   mProxy = do_CreateInstance("@mozilla.org/dom/activities/proxy;1", &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  mProxy->StartActivity(this, options);
+  mProxy->StartActivity(this, options, window);
   return NS_OK;
 }
 
 Activity::~Activity()
 {
   if (mProxy) {
     mProxy->Cleanup();
   }
--- a/dom/activities/src/ActivityProxy.js
+++ b/dom/activities/src/ActivityProxy.js
@@ -1,46 +1,48 @@
 /* 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");
 Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/ObjectWrapper.jsm");
 
 XPCOMUtils.defineLazyGetter(this, "cpmm", function() {
   return Cc["@mozilla.org/childprocessmessagemanager;1"]
            .getService(Ci.nsIFrameMessageManager)
            .QueryInterface(Ci.nsISyncMessageSender);
 });
 
 function debug(aMsg) {
   //dump("-- ActivityProxy " + Date.now() + " : " + aMsg + "\n");
 }
 
 /**
   * nsIActivityProxy implementation
   * We keep a reference to the C++ Activity object, and
-  * communicate with the Message Manager to know when to 
+  * communicate with the Message Manager to know when to
   * fire events on it.
   */
 function ActivityProxy() {
   debug("ActivityProxy");
   this.activity = null;
 }
 
 ActivityProxy.prototype = {
-  startActivity: function actProxy_startActivity(aActivity, aOptions) {
+  startActivity: function actProxy_startActivity(aActivity, aOptions, aWindow) {
     debug("startActivity");
 
+    this.window = aWindow;
     this.activity = aActivity;
     this.id = Cc["@mozilla.org/uuid-generator;1"]
                 .getService(Ci.nsIUUIDGenerator)
                 .generateUUID().toString();
     cpmm.sendAsyncMessage("Activity:Start", { id: this.id, options: aOptions });
 
     cpmm.addMessageListener("Activity:FireSuccess", this);
     cpmm.addMessageListener("Activity:FireError", this);
@@ -51,17 +53,18 @@ ActivityProxy.prototype = {
     let msg = aMessage.json;
     if (msg.id != this.id)
       return;
     debug("msg=" + JSON.stringify(msg));
 
     switch(aMessage.name) {
       case "Activity:FireSuccess":
         debug("FireSuccess");
-        Services.DOMRequest.fireSuccess(this.activity, msg.result);
+        Services.DOMRequest.fireSuccess(this.activity,
+                                        ObjectWrapper.wrap(msg.result, this.window));
         break;
       case "Activity:FireError":
         debug("FireError");
         Services.DOMRequest.fireError(this.activity, msg.error);
         break;
     }
   },
 
--- a/dom/activities/src/ActivityWrapper.js
+++ b/dom/activities/src/ActivityWrapper.js
@@ -4,40 +4,41 @@
 
 "use strict";
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/ObjectWrapper.jsm");
 
 function debug(aMsg) {
   //dump("-- ActivityWrapper.js " + Date.now() + " : " + aMsg + "\n");
 }
 
 /**
   * nsISystemMessagesWrapper implementation. Will return a
   * nsIDOMMozActivityRequestHandler
   */
 function ActivityWrapper() {
   debug("ActivityWrapper");
 }
 
 ActivityWrapper.prototype = {
-  wrapMessage: function wrapMessage(aMessage) {
+  wrapMessage: function wrapMessage(aMessage, aWindow) {
     debug("Wrapping " + JSON.stringify(aMessage));
     let handler = Cc["@mozilla.org/dom/activities/request-handler;1"]
                     .createInstance(Ci.nsIDOMMozActivityRequestHandler);
     handler.wrappedJSObject._id = aMessage.id;
 
     // options is an nsIDOMActivityOptions object.
     var options = handler.wrappedJSObject._options;
     options.wrappedJSObject._name = aMessage.payload.name;
-    options.wrappedJSObject._data = aMessage.payload.data;
+    options.wrappedJSObject._data = ObjectWrapper.wrap(aMessage.payload.data, aWindow);
 
     return handler;
   },
 
   classID: Components.ID("{5430d6f9-32d6-4924-ba39-6b6d1b093cd6}"),
   QueryInterface: XPCOMUtils.generateQI([Ci.nsISystemMessagesWrapper])
 }
 
--- a/dom/messages/SystemMessageManager.js
+++ b/dom/messages/SystemMessageManager.js
@@ -55,17 +55,17 @@ SystemMessageManager.prototype = {
     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);
+        aMessage = wrapper.wrapMessage(aMessage, this._window);
         wrapped = true;
         debug("wrapped = " + aMessage);
       }
     }
 
     aHandler.handleMessage(wrapped ? aMessage : ObjectWrapper.wrap(aMessage, this._window));
   },
 
--- a/dom/messages/interfaces/nsISystemMessagesInternal.idl
+++ b/dom/messages/interfaces/nsISystemMessagesInternal.idl
@@ -1,15 +1,16 @@
 /* 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/. */
 
 #include "domstubs.idl"
 
 interface nsIURI;
+interface nsIDOMWindow;
 
 // Implemented by the contract id @mozilla.org/system-message-internal;1
 
 [scriptable, uuid(3a50fd6b-0263-45c1-b738-a002052ad31b)]
 interface nsISystemMessagesInternal : nsISupports
 {
   /*
    * Allow any internal user to broadcast a message of a given type.
@@ -24,17 +25,17 @@ interface nsISystemMessagesInternal : ns
    * Registration of a page that wants to be notified of a message type.
    * @param type          The message type.
    * @param pageURI       The URI of the page that will be opened.
    * @param manifestURI   The webapp's manifest URI.
    */
   void registerPage(in DOMString type, in nsIURI pageURI, in nsIURI manifestURI);
 };
 
-[scriptable, uuid(b43c74ec-1b64-49fb-b552-aadd9d827eec)]
+[scriptable, uuid(002f0e82-91f0-41de-ad43-569a2b9d12df)]
 interface nsISystemMessagesWrapper: nsISupports
 {
   /*
    * Wrap a message and gives back any kind of object.
    * @param message  The json blob to wrap.
    */
-  jsval wrapMessage(in jsval message);
+  jsval wrapMessage(in jsval message, in nsIDOMWindow window);
 };