Bug 870445 - Add -marionette command-line arg to Firefox, r=mdas

This commit is contained in:
David Burns 2013-05-13 13:43:15 +01:00
parent f4be8f1565
commit e4f4961edd
6 changed files with 78 additions and 50 deletions

View File

@ -528,12 +528,10 @@
@BINPATH@/components/PeerConnection.manifest
#endif
#ifdef ENABLE_MARIONETTE
@BINPATH@/chrome/marionette@JAREXT@
@BINPATH@/chrome/marionette.manifest
@BINPATH@/components/MarionetteComponents.manifest
@BINPATH@/components/marionettecomponent.js
#endif
#ifdef MOZ_WEBSPEECH
@BINPATH@/components/dom_webspeechsynth.xpt

View File

@ -9,9 +9,13 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
ifdef ENABLE_MARIONETTE
DEFINES += -DENABLE_MARIONETTE=1
endif
EXTRA_PP_COMPONENTS = \
MarionetteComponents.manifest \
marionettecomponent.js \
$(NULL)
MarionetteComponents.manifest \
marionettecomponent.js \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -1,4 +1,5 @@
# Marionette
component {786a1369-dca5-4adc-8486-33d23c88010a} marionettecomponent.js
contract @mozilla.org/marionette;1 {786a1369-dca5-4adc-8486-33d23c88010a}
category command-line-handler b-marionette @mozilla.org/marionette;1
category profile-after-change MarionetteComponent @mozilla.org/marionette;1

View File

@ -22,14 +22,25 @@ Cu.import("resource://gre/modules/services-common/log4moz.js");
function MarionetteComponent() {
this._loaded = false;
this.observerService = Services.obs;
// set up the logger
this.logger = Log4Moz.repository.getLogger("Marionette");
this.logger.level = Log4Moz.Level["INFO"];
this.logger.level = Log4Moz.Level["Info"];
let logf = FileUtils.getFile('ProfD', ['marionette.log']);
let dumper = false;
let formatter = new Log4Moz.BasicFormatter();
this.logger.addAppender(new Log4Moz.RotatingFileAppender(logf, formatter));
this.logger.addAppender(new Log4Moz.DumpAppender(formatter));
#ifdef DEBUG
dumper = true;
#endif
#ifdef MOZ_B2G
dumper = true;
#endif
if (dumper) {
this.logger.addAppender(new Log4Moz.DumpAppender(formatter));
}
this.logger.info("MarionetteComponent loaded");
}
@ -37,10 +48,13 @@ MarionetteComponent.prototype = {
classDescription: "Marionette component",
classID: MARIONETTE_CID,
contractID: MARIONETTE_CONTRACTID,
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
_xpcom_categories: [{category: "profile-after-change", service: true}],
QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler, Ci.nsIObserver]),
_xpcom_categories: [{category: "command-line-handler", entry: "b-marionette"},
{category: "profile-after-change", service: true}],
original_forcelocal: null,
appName: Services.appinfo.name,
enabled: false,
finalUiStartup: false,
onSocketAccepted: function mc_onSocketAccepted(aSocket, aTransport) {
this.logger.info("onSocketAccepted for Marionette dummy socket");
@ -51,63 +65,75 @@ MarionetteComponent.prototype = {
aSocket.close();
},
// Check cmdLine argument for --marionette
handle: function mc_handle(cmdLine) {
// If the CLI is there then lets do work otherwise nothing to see
if (cmdLine.handleFlag("marionette", false)) {
this.enabled = true;
this.logger.info("marionette enabled via command-line");
this.init();
}
},
observe: function mc_observe(aSubject, aTopic, aData) {
let observerService = Services.obs;
switch (aTopic) {
case "profile-after-change":
let enabled = false;
// Using final-ui-startup as the xpcom category doesn't seem to work,
// so we wait for that by adding an observer here.
this.observerService.addObserver(this, "final-ui-startup", false);
#ifdef ENABLE_MARIONETTE
let enabledPref = false;
try {
enabled = Services.prefs.getBoolPref(MARIONETTE_ENABLED_PREF);
enabledPref = Services.prefs.getBoolPref(MARIONETTE_ENABLED_PREF);
} catch(e) {}
if (enabled) {
this.logger.info("marionette enabled");
//add observers
observerService.addObserver(this, "final-ui-startup", false);
observerService.addObserver(this, "xpcom-shutdown", false);
if (enabledPref) {
this.enabled = true;
this.logger.info("marionette enabled via build flag and pref");
}
else {
this.logger.info("marionette not enabled");
this.logger.info("marionette not enabled via pref");
}
#endif
break;
case "final-ui-startup":
this.logger.info("marionette initializing at " + aTopic);
observerService.removeObserver(this, aTopic);
try {
this.original_forcelocal = Services.prefs.getBoolPref(DEBUGGER_FORCELOCAL_PREF);
}
catch(e) {}
let marionette_forcelocal = this.appName == 'B2G' ? false : true;
try {
marionette_forcelocal = Services.prefs.getBoolPref(MARIONETTE_FORCELOCAL_PREF);
}
catch(e) {}
Services.prefs.setBoolPref(DEBUGGER_FORCELOCAL_PREF, marionette_forcelocal);
if (!marionette_forcelocal) {
// See bug 800138. Because the first socket that opens with
// force-local=false fails, we open a dummy socket that will fail.
// keepWhenOffline=true so that it still work when offline (local).
// This allows the following attempt by Marionette to open a socket
// to succeed.
let insaneSacrificialGoat = new ServerSocket(666, Ci.nsIServerSocket.KeepWhenOffline, 4);
insaneSacrificialGoat.asyncListen(this);
}
this.finalUiStartup = true;
this.observerService.removeObserver(this, aTopic);
this.observerService.addObserver(this, "xpcom-shutdown", false);
this.init();
break;
case "xpcom-shutdown":
observerService.removeObserver(this, "xpcom-shutdown");
this.observerService.removeObserver(this, "xpcom-shutdown");
this.uninit();
break;
}
},
init: function mc_init() {
if (!this._loaded) {
if (!this._loaded && this.enabled && this.finalUiStartup) {
this._loaded = true;
try {
this.original_forcelocal = Services.prefs.getBoolPref(DEBUGGER_FORCELOCAL_PREF);
}
catch(e) {}
let marionette_forcelocal = this.appName == 'B2G' ? false : true;
try {
marionette_forcelocal = Services.prefs.getBoolPref(MARIONETTE_FORCELOCAL_PREF);
}
catch(e) {}
Services.prefs.setBoolPref(DEBUGGER_FORCELOCAL_PREF, marionette_forcelocal);
if (!marionette_forcelocal) {
// See bug 800138. Because the first socket that opens with
// force-local=false fails, we open a dummy socket that will fail.
// keepWhenOffline=true so that it still work when offline (local).
// This allows the following attempt by Marionette to open a socket
// to succeed.
let insaneSacrificialGoat = new ServerSocket(666, Ci.nsIServerSocket.KeepWhenOffline, 4);
insaneSacrificialGoat.asyncListen(this);
}
let port;
try {
port = Services.prefs.getIntPref('marionette.defaultPrefs.port');

View File

@ -4,5 +4,4 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
if CONFIG['ENABLE_MARIONETTE']:
DIRS += ['components', 'atoms']
DIRS += ['components', 'atoms']

View File

@ -228,7 +228,7 @@ add_tier_dir('platform', 'addon-sdk')
if CONFIG['MOZ_MAPINFO']:
add_tier_dir('platform', 'tools/codesighs')
if CONFIG['ENABLE_MARIONETTE']:
if CONFIG['ENABLE_MARIONETTE'] or CONFIG['MOZ_WIDGET_TOOLKIT'] not in ('gonk', 'android'):
add_tier_dir('platform', 'testing/marionette')
if CONFIG['ENABLE_TESTS']: