Hey Sam, yeh I’m familiar with this project -  I think we talked about this, or 
maybe you spoke to someone (cruetten maybe?) in my team. I can’t find an email, 
but anyways. The examples I gave for NFC and EngineeringMode were just to 
illustrate WebIDL as compared to message manager. However if you want to model 
your API off something, I would suggest that you look at “NetworkStats” API.

https://developer.mozilla.org/en-US/docs/Web/API/Network_Stats_API 
<https://developer.mozilla.org/en-US/docs/Web/API/Network_Stats_API>

This allows the gaia CostControl app to monitor network usage. Im not familiar 
with exactly how this API works but my guess is that it accrues network 
transmission information in some store in Gecko, and then the API provides a 
way for the App to read the data, and also be notified when a network 
transmission happens. 

Looking at the way you log usage [1], this strikes me as a performance concern, 
and you might have a hard time convincing DOM module owners to add this code.I 
would have thought there is a better way to intercept DOM API calls that 
changing all the APIs.  Perhaps consider a WebExtension which hijacks API calls 
(actually thats where I remember this discussion from).

An alternative might be to look at the WebIDL bindings themselves 
(https://developer.mozilla.org/en-US/docs/Mozilla/WebIDL_bindings 
<https://developer.mozilla.org/en-US/docs/Mozilla/WebIDL_bindings>). Maybe you 
can implement new keyword which can be added to WebIDL bindings to have them 
logged.

But again, I think  runtime solution (like a web extension) would be the way to 
go here if it were at all possible due to performance considerations. Actually 
iirc Christiane Ruetten from my team started looking at this but I don’t think 
has a solution yet.

A couple important things to note:
- probably focus on privileged permissions as a first step ( I’ve listed the 
most interesting ones below). Privileged permissions that I would start with 
might be:
tcp-socket
udp-socket
contacts
browser
systemXHR
moz-firefox-accounts
camera  
device-storage:pictures
device-storage:videos
device-storage:music
device-storage:sdcard
- Mostly there is a 1:1 between permissions and API but not always. (e.g 
device-storage has multiple variations)
- Do you want your app to _always_ receive notifications? Or just when it is 
running? (if the latter you could use events, but if the former you might need 
to use system messages (this again is a FxOS specific thing that allows gecko 
to send messages to an app, and ensuring that the app is opened first and then 
the message is sent to the app) With event handlers, there is no guarantee that 
the app is open and listening.

Finally to just to reply to your comment:

> As for the Engineering mode API, I don't really understand how it can help 
> me, as far as I understand you have to call it manually from the Gaia app to 
> receive the message, but in my case we can't do that since we don't know when 
> a message (API request) will arrive.

I just used it as an example since its simple compared to something like NFC.

Hope that helps! 

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

Reply via email to