Hi Sammy,

MessageManager is for use in Chrome privileged code (gecko code) to talk 
between windows. It won’t help you talk between Gecko and Gaia. Thats actually 
usually what WebIDL is usually for. I.e. if you want to communicate between 
gecko and gaia, usually you have to define a web API (with webIDL) which Gaia 
can call in order to talk to Gecko. For communicating FROM gecko to gaia, you 
can either have Gaia register an event handler, or if you need something more 
reliable, you can look at System Messages (which is a FxOS only thing. Thats 
the short answer. I’ve tried to provide more detail and examples below, but not 
sure if its clear or not ;)

If you prefer pictures, you can find an (out of date) diagram and details of 
the NFC API here:
https://wiki.mozilla.org/Security/Reviews/B2G/WebNFC#Architecture

Or I’ve tried to go through an example simple API below, using the 
EngineeringMode API. The point of the EngineeringMode API is to provide a 
generic API which partners can extend. First lets look at the WebIDL:

http://mxr.mozilla.org/mozilla-central/source/dom/webidl/EngineeringMode.webidl

This defines the interface which is exposed to the web(in this case if the web 
page is a certified app the 'engineering-mode’ permission). It defines two 
functions “getValue” and “setValue” and also a generic “onmessage” function. 
The communication between Gecko and Gaia is Gaia calling these functions. You 
can find the implementation of these functions here:

http://mxr.mozilla.org/mozilla-central/source/dom/engineeringmode/EngineeringModeAPI.js

This API is ‘remoted’ - that is, it has a child process part, and a parent 
process part. When a web page calls a function, the child implementation 
usually sends a message via nsiMessageSender to the ParentProcess so that the 
parent process can pass the functional call to the underlying vendor 
impplementation. 
The parent part of this API is defined here:

http://mxr.mozilla.org/mozilla-central/source/dom/engineeringmode/EngineeringModeService.js

(I’ve left out how the parent process talks to the underlying vendor code, but 
I don’t think thats relevant to your question).

So for example, lets say the vendor implementation (in the parent) wants to 
send a message to the web page in the child process:
1.  The parent service receives a message from the underlying implementation, 
and then calls .sendMessage to forward this to all children that are registered:
http://mxr.mozilla.org/mozilla-central/source/dom/engineeringmode/EngineeringModeService.js#145

2. The child code receives the message, and then fires it to the handler 
register in the page:
http://mxr.mozilla.org/mozilla-central/source/dom/engineeringmode/EngineeringModeAPI.js#95

3. If there is an event handler registered, it will be called with this value.

I hope thats clear, but let me know if not. From your email I’m guessing you 
are writing an API to monitor API calls. Do you have a plan for how you are 
going to implement this? I’d be interested to help out where I can.

Cheers,
Paul

> On 28 Dec 2015, at 1:09 pm, Sammy Patenotte <[email protected]> wrote:
> 
> Hi everyone,
> I am currently working on a project for Firefox OS, and am trying to send 
> messages from a WebIDL in gecko to a Gaia app.
> So far I have found the nsIMessageSender and nsIMessageListenerManager 
> interfaces that could work for me.
> Unfortunately, when I try to invoke the nsIMessageListenerManager interface 
> in Gaia, The following error appears:
> E/TestApp (10202): [JavaScript Error: "The Components object is deprecated. 
> It will soon be removed." {file: 
> "app://bf12df6f-7274-4907-8ab4-a8f2501c28e2/app.js" line: 14}]
> E/TestApp (10202): [JavaScript Error: "TypeError: Components.utils is 
> undefined" {file: "app://bf12df6f-7274-4907-8ab4-a8f2501c28e2/app.js" line: 
> 14}]
> 
> My code is the following:
> Gecko:
> XPCOMUtils.defineLazyServiceGetter(this, "cpmm", 
> "@mozilla.org/childprocessmessagemanager;1", "nsIMessageSender");
> cpmm.sendAsyncMessage("PrivacyMonitor:APIRequest", {appName: appName, 
> permission: permission});
> 
> Gaia:
>  var globalMM = Components.classes["@mozilla.org/cookie-monster;1"]
>                 .getService(Components.interfaces.nsIMessageListenerManager);
>  globalMM.addMessageListener("PrivacyMonitor:APIRequest", function(obj) {
>    console.log(obj.appName);
>  });
> 
> I understand that it is not possible to use Components from Gaia anymore, is 
> there another to use this interface or, if not, another way to communicate 
> from Gecko to Gaia?
> 
> Thank you.
> _______________________________________________
> dev-fxos mailing list
> [email protected]
> https://lists.mozilla.org/listinfo/dev-fxos

_______________________________________________
dev-fxos mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-fxos

Reply via email to