|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components; |
|
5 const { Services } = Cu.import('resource://gre/modules/Services.jsm'); |
|
6 const { SystemAppProxy } = Cu.import('resource://gre/modules/SystemAppProxy.jsm'); |
|
7 |
|
8 var processId; |
|
9 |
|
10 function peekChildId(aSubject, aTopic, aData) { |
|
11 Services.obs.removeObserver(peekChildId, 'recording-device-events'); |
|
12 Services.obs.removeObserver(peekChildId, 'recording-device-ipc-events'); |
|
13 let props = aSubject.QueryInterface(Ci.nsIPropertyBag2); |
|
14 if (props.hasKey('childID')) { |
|
15 processId = props.get('childID'); |
|
16 } |
|
17 } |
|
18 |
|
19 addMessageListener('init-chrome-event', function(message) { |
|
20 // listen mozChromeEvent and forward to content process. |
|
21 let type = message.type; |
|
22 SystemAppProxy.addEventListener('mozChromeEvent', function(event) { |
|
23 let details = event.detail; |
|
24 if (details.type === type) { |
|
25 sendAsyncMessage('chrome-event', details); |
|
26 } |
|
27 }, true); |
|
28 |
|
29 Services.obs.addObserver(peekChildId, 'recording-device-events', false); |
|
30 Services.obs.addObserver(peekChildId, 'recording-device-ipc-events', false); |
|
31 }); |
|
32 |
|
33 addMessageListener('fake-content-shutdown', function(message) { |
|
34 let props = Cc["@mozilla.org/hash-property-bag;1"] |
|
35 .createInstance(Ci.nsIWritablePropertyBag2); |
|
36 if (processId) { |
|
37 props.setPropertyAsUint64('childID', processId); |
|
38 } |
|
39 Services.obs.notifyObservers(props, 'recording-device-ipc-events', 'content-shutdown'); |
|
40 }); |