1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/b2g/chrome/content/test/mochitest/RecordingStatusChromeScript.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,40 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components; 1.8 +const { Services } = Cu.import('resource://gre/modules/Services.jsm'); 1.9 +const { SystemAppProxy } = Cu.import('resource://gre/modules/SystemAppProxy.jsm'); 1.10 + 1.11 +var processId; 1.12 + 1.13 +function peekChildId(aSubject, aTopic, aData) { 1.14 + Services.obs.removeObserver(peekChildId, 'recording-device-events'); 1.15 + Services.obs.removeObserver(peekChildId, 'recording-device-ipc-events'); 1.16 + let props = aSubject.QueryInterface(Ci.nsIPropertyBag2); 1.17 + if (props.hasKey('childID')) { 1.18 + processId = props.get('childID'); 1.19 + } 1.20 +} 1.21 + 1.22 +addMessageListener('init-chrome-event', function(message) { 1.23 + // listen mozChromeEvent and forward to content process. 1.24 + let type = message.type; 1.25 + SystemAppProxy.addEventListener('mozChromeEvent', function(event) { 1.26 + let details = event.detail; 1.27 + if (details.type === type) { 1.28 + sendAsyncMessage('chrome-event', details); 1.29 + } 1.30 + }, true); 1.31 + 1.32 + Services.obs.addObserver(peekChildId, 'recording-device-events', false); 1.33 + Services.obs.addObserver(peekChildId, 'recording-device-ipc-events', false); 1.34 +}); 1.35 + 1.36 +addMessageListener('fake-content-shutdown', function(message) { 1.37 + let props = Cc["@mozilla.org/hash-property-bag;1"] 1.38 + .createInstance(Ci.nsIWritablePropertyBag2); 1.39 + if (processId) { 1.40 + props.setPropertyAsUint64('childID', processId); 1.41 + } 1.42 + Services.obs.notifyObservers(props, 'recording-device-ipc-events', 'content-shutdown'); 1.43 +});