"use strict"; // runapp.js: // Provide a --runapp APPNAME command-line option. let runAppObj; window.addEventListener('load', function() { if (!window.arguments) { return; } // Get the command line arguments that were passed to the b2g client let args = window.arguments[0].QueryInterface(Ci.nsICommandLine); let appname; // - Check if the argument is present before doing any work. try { // Returns null if the argument was not specified. Throws // NS_ERROR_INVALID_ARG if there is no parameter specified (because // it was the last argument or the next argument starts with '-'). // However, someone could still explicitly pass an empty argument! appname = args.handleFlagWithParam('runapp', false); } catch(e) { // treat a missing parameter like an empty parameter (=> show usage) appname = ''; } // not specified, bail. if (appname === null) { return; } runAppObj = new AppRunner(appname); Services.obs.addObserver(runAppObj, 'remote-browser-shown', false); Services.obs.addObserver(runAppObj, 'inprocess-browser-shown', false); }); window.addEventListener('unload', function() { if (runAppObj) { Services.obs.removeObserver(runAppObj, 'remote-browser-shown'); Services.obs.removeObserver(runAppObj, 'inprocess-browser-shown'); } }); function AppRunner(aName) { this._appName = aName; this._apps = []; } AppRunner.prototype = { observe: function(aSubject, aTopic, aData) { let frameLoader = aSubject; // get a ref to the app