Bug 1524673 - Make Marionette part of remote debugging within GeckoView. r=whimboo,snorp

Functionally, we want Marionette to be enabled whenever remote
debugging enabled and disabled whenever remote debugging is enabled.

That's not particularly well supported by Gecko prefs, so we don't try
to handle all situations.  We force the Marionette pref whenever the
remote debugging pref changes; if consumers get themselves into a bad
state by fiddling the Marionette pref independently, that's fine:
GeckoView will take back control eventually.

There are a couple of wrinkles here.  The first is that GeckoView and
Marionette race to set themselves up in "profile-after-change".  We
ensure that both are configured before GeckoView notifies
"marionette-startup-requested".  The second is that the initial value
of the Marionette pref is taken from the environment variable
MOZ_MARIONETTE; therefore, we set that variable when starting the
Gecko thread.

Differential Revision: https://phabricator.services.mozilla.com/D17580

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nick Alexander 2019-02-11 19:35:30 +00:00
parent 40d0ac4ef0
commit 4bef3af91a
3 changed files with 36 additions and 2 deletions

View File

@ -129,7 +129,8 @@ public class GeckoThread extends Thread {
// Main process parameters
public static final int FLAG_DEBUGGING = 1 << 0; // Debugging mode.
public static final int FLAG_PRELOAD_CHILD = 1 << 1; // Preload child during main thread start.
public static final int FLAG_ENABLE_NATIVE_CRASHREPORTER = 1 << 2; // Enable native crash reporting
public static final int FLAG_ENABLE_NATIVE_CRASHREPORTER = 1 << 2; // Enable native crash reporting.
public static final int FLAG_ENABLE_MARIONETTE = 1 << 3; // Enable Marionette at startup.
public static final long DEFAULT_TIMEOUT = 5000;
@ -461,6 +462,12 @@ public class GeckoThread extends Thread {
env.add(0, "MOZ_CRASHREPORTER=1");
}
if (!isChildProcess() && ((mInitInfo.flags & FLAG_ENABLE_MARIONETTE) != 0)) {
// The presence of this environment variable determines the initial
// value of `marionette.enabled`.
env.add(0, "MOZ_MARIONETTE=1");
}
GeckoLoader.setupGeckoEnvironment(context, context.getFilesDir().getPath(), env, mInitInfo.prefs);
// And go.

View File

@ -187,6 +187,10 @@ public final class GeckoRuntime implements Parcelable {
flags |= GeckoThread.FLAG_DEBUGGING;
}
if (settings.getRemoteDebuggingEnabled()) {
flags |= GeckoThread.FLAG_ENABLE_MARIONETTE;
}
final Class<?> crashHandler = settings.getCrashHandler();
if (crashHandler != null) {
try {

View File

@ -47,6 +47,25 @@ var GeckoViewRemoteDebugger = {
debug `onInit`;
this._isEnabled = false;
this._usbDebugger = new USBRemoteDebugger();
// For GeckoView-consuming Apps (including Fennec), we want "remote
// debugging" to encapsulate "Marionette" completely. It's possible for
// consumers to manage the Marionette pref independently, but we don't
// condone or accommodate such management.
Services.prefs.setBoolPref("marionette.enabled", false);
// We never want Marionette to set prefs recommended for automation.
Services.prefs.setBoolPref("marionette.prefs.recommended", false);
// This lets Marionette start listening (when it's enabled). Both
// GeckoView and Marionette do most of their initialization in
// "profile-after-change", and there is no order enforced between
// them. Therefore we defer asking Marionette to startup until
// after all "profile-after-change" handlers (including this one)
// have completed.
Services.tm.dispatchToMainThread(() => {
Services.obs.notifyObservers(null, "marionette-startup-requested");
});
},
onEnable() {
@ -75,7 +94,7 @@ var GeckoViewRemoteDebugger = {
if (packageName) {
packageName = packageName + "/";
} else {
warn `Missing env MOZ_ANDROID_PACKAGE_NAME. Unable to get pacakge name`;
warn `Missing env MOZ_ANDROID_PACKAGE_NAME. Unable to get package name`;
}
this._isEnabled = true;
@ -83,6 +102,8 @@ var GeckoViewRemoteDebugger = {
const portOrPath = packageName + "firefox-debugger-socket";
this._usbDebugger.start(portOrPath);
Services.prefs.setBoolPref("marionette.enabled", true);
},
onDisable() {
@ -93,6 +114,8 @@ var GeckoViewRemoteDebugger = {
debug `onDisable`;
this._isEnabled = false;
this._usbDebugger.stop();
Services.prefs.setBoolPref("marionette.enabled", false);
},
};