Electrolysis/Jetpack: Difference between revisions

Jump to navigation Jump to search
m
no edit summary
mNo edit summary
mNo edit summary
Line 17: Line 17:
In the chrome process:
In the chrome process:


    function onReady(callbackObj) {
  function onReady(callbackObj) {
      associateCallbackWithDOMDocumentLoaded(callbackObj.callback);
    associateCallbackWithDOMDocumentLoaded(callbackObj.callback);
    }
  }


In the Jetpack process, the jetpack.tabs object can theoretically be a CPOW to the chrome Tabs object, and everything should work fine.
In the Jetpack process, the jetpack.tabs object can theoretically be a CPOW to the chrome Tabs object, and everything should work fine.
Line 27: Line 27:
In the jetpack process:
In the jetpack process:


    Tabs = {
  Tabs = {
      onReady: function(callback) {
    onReady: function(callback) {
        let uniqueSignature = new Date.time().toString();
      let uniqueSignature = new Date.time().toString();
        this.params[uniqueSignature] = callback;
      this.params[uniqueSignature] = callback;
        sendAsyncMessage("tabs.onReady", {callback: uniqueSignature});
      sendAsyncMessage("tabs.onReady", {callback: uniqueSignature});
      }
     }
     }
  }


  In the chrome process:
In the chrome process:


    addMessageListener("tabs.onReady",
  addMessageListener("tabs.onReady",
      function(m) {
    function(m) {
        let child = getCPOW(m.target);
      let child = getCPOW(m.target);
        JetpackEnv.Tabs.onReady(child.jetpack.Tabs.params[m.json.callback]);
      JetpackEnv.Tabs.onReady(child.jetpack.Tabs.params[m.json.callback]);
      }
    }


    Tabs = {
  Tabs = {
      onReady: function(callback) {
    onReady: function(callback) {
        associateCallbackWithDOMDocumentLoaded(callback);
      associateCallbackWithDOMDocumentLoaded(callback);
      }
     }
     }
  }


In either instance, the chrome process will end up calling the CPOW callback using a CPOW document object (assuming content processes exist).
In either instance, the chrome process will end up calling the CPOW callback using a CPOW document object (assuming content processes exist).


Note that the solutions as described are currently un-implementable, because there's no way to pass the document object to the CPOW callback as a parameter.  We need chrome->jetpack CPOWs for that to work, and they don't exist yet.
Note that the solutions as described are currently un-implementable, because there's no way to pass the document object to the CPOW callback as a parameter.  We need chrome->jetpack CPOWs for that to work, and they don't exist yet.
The upside is that jQuery should Just Work as soon as the chrome -> jetpack CPOWs do exist.
Please note that the above code is very much simplified from the actual implementation.  One complication is that <bsendAsyncMessage</b> is not accessible at document level.  Instead, you need code like the following to implement proxying:
From a script loaded into the remote jetpack process via loadFrameScript:
  addEventListener("tabs.onReady",
    function(event) {
      var signature = event.getData("signature").QueryInterface(Components.interfaces.nsIVariant);
      sendAsyncMessage("tabs.onReady", {callback: signature});
    }, false, true);
In the Jetpack process implementation:
  Tabs = {
    onReady: function(callback) {
      let uniqueSignature = new Date.time().toString();
      this.params[uniqueSignature] = callback;
     
      var eventDoc = document.QueryInterface(Ci.nsIDOMDocumentEvent);
      var event = eventDoc.createEvent("datacontainerevents");
      var container = event.QueryInterface(Ci.nsIDOMDataContainerEvent);
      var variant = Cc["@mozilla.org/variant;1"].createInstance(Ci.nsIWritableVariant);
      variant.setAsAString(uniqueSignature);
      container.setData("signature", variant);
      event.initEvent("tabs.onReady", true, false);
      window.dispatchEvent(event);
    }
  }
Still, that's just an implementation detail.
Confirmed users
512

edits

Navigation menu