Bug 1222047 - Manage device and preference fronts via client.mainRoot.getFront. r=yulia

Summary: Depends On D3317

Tags: #secure-revision

Bug #: 1222047

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

MozReview-Commit-ID: 3jaFZbXVLuw
This commit is contained in:
Alexandre Poirot 2018-08-13 09:38:55 -07:00
Родитель 6f0326bd3a
Коммит fb4cd85e35
13 изменённых файлов: 45 добавлений и 113 удалений

Просмотреть файл

@ -366,7 +366,7 @@ async function checkServerSupportsListWorkers() {
return false;
}
const deviceFront = await (0, _frontsDevice.getDeviceFront)(debuggerClient, root);
const deviceFront = await debuggerClient.mainRoot.getFront("device");
const description = await deviceFront.getDescription();
const isFennec = description.apptype === "mobile/android";
@ -438,4 +438,4 @@ const clientCommands = {
setSkipPausing
};
exports.setupCommands = setupCommands;
exports.clientCommands = clientCommands;
exports.clientCommands = clientCommands;

Просмотреть файл

@ -47,8 +47,6 @@ loader.lazyRequireGetter(this, "flags",
"devtools/shared/flags");
loader.lazyRequireGetter(this, "createPerformanceFront",
"devtools/shared/fronts/performance", true);
loader.lazyRequireGetter(this, "getPreferenceFront",
"devtools/shared/fronts/preference", true);
loader.lazyRequireGetter(this, "KeyShortcuts",
"devtools/client/shared/key-shortcuts");
loader.lazyRequireGetter(this, "ZoomKeys",
@ -65,8 +63,6 @@ loader.lazyRequireGetter(this, "viewSource",
"devtools/client/shared/view-source");
loader.lazyRequireGetter(this, "buildHarLog",
"devtools/client/netmonitor/src/har/har-builder-utils", true);
loader.lazyRequireGetter(this, "getKnownDeviceFront",
"devtools/shared/fronts/device", true);
loader.lazyRequireGetter(this, "NetMonitorAPI",
"devtools/client/netmonitor/src/api", true);
loader.lazyRequireGetter(this, "sortPanelDefinitions",
@ -2217,16 +2213,7 @@ Toolbox.prototype = {
* client. See the definition of the preference actor for more information.
*/
get preferenceFront() {
if (this._preferenceFront) {
return Promise.resolve(this._preferenceFront);
}
return this.isOpen.then(() => {
return this.target.root.then(rootForm => {
const front = getPreferenceFront(this.target.client, rootForm);
this._preferenceFront = front;
return front;
});
});
return this.target.client.mainRoot.getFront("preference");
},
// Is the disable auto-hide of pop-ups feature available in this context?
@ -2932,16 +2919,8 @@ Toolbox.prototype = {
// Destroy the profiler connection
outstanding.push(this.destroyPerformance());
// Destroy the preference front
outstanding.push(this.destroyPreference());
// Destroy the device front for the current client if any.
// A given DeviceFront instance can cached and shared between different panels, so
// destroying it is the responsibility of the toolbox.
const deviceFront = getKnownDeviceFront(this.target.client);
if (deviceFront) {
deviceFront.destroy();
}
// Reset preferences set by the toolbox
outstanding.push(this.resetPreference());
// Detach the thread
detachThread(this._threadClient);
@ -3126,9 +3105,9 @@ Toolbox.prototype = {
},
/**
* Destroy the preferences actor when the toolbox is unloaded.
* Reset preferences set by the toolbox.
*/
async destroyPreference() {
async resetPreference() {
if (!this._preferenceFront) {
return;
}
@ -3139,7 +3118,6 @@ Toolbox.prototype = {
await this._preferenceFront.clearUserPref(DISABLE_AUTOHIDE_PREF);
}
this._preferenceFront.destroy();
this._preferenceFront = null;
},

Просмотреть файл

@ -4,7 +4,6 @@
"use strict";
const { PerfFront } = require("devtools/shared/fronts/perf");
const { getPreferenceFront } = require("devtools/shared/fronts/preference");
loader.lazyRequireGetter(this, "EventEmitter", "devtools/shared/event-emitter");
class PerformancePanel {
@ -32,7 +31,7 @@ class PerformancePanel {
const rootForm = await this.target.root;
const perfFront = new PerfFront(this.target.client, rootForm);
const preferenceFront = getPreferenceFront(this.target.client, rootForm);
const preferenceFront = this.target.client.mainRoot.getFront("preference");
this.isReady = true;
this.emit("ready");

Просмотреть файл

@ -11,8 +11,6 @@ const {AppProjects} = require("devtools/client/webide/modules/app-projects");
const TabStore = require("devtools/client/webide/modules/tab-store");
const {AppValidator} = require("devtools/client/webide/modules/app-validator");
const {ConnectionManager, Connection} = require("devtools/shared/client/connection-manager");
const {getDeviceFront} = require("devtools/shared/fronts/device");
const {getPreferenceFront} = require("devtools/shared/fronts/preference");
const {RuntimeScanners} = require("devtools/client/webide/modules/runtimes");
const {RuntimeTypes} = require("devtools/client/webide/modules/runtime-types");
const {NetUtil} = require("resource://gre/modules/NetUtil.jsm");
@ -141,7 +139,7 @@ var AppManager = exports.AppManager = {
}
},
onConnectionChanged: function() {
onConnectionChanged: async function() {
console.log("Connection status changed: " + this.connection.status);
if (this.connection.status == Connection.Status.DISCONNECTED) {
@ -150,12 +148,21 @@ var AppManager = exports.AppManager = {
if (!this.connected) {
this._listTabsResponse = null;
this.deviceFront = null;
this.preferenceFront = null;
} else {
this.connection.client.listTabs().then((response) => {
this._listTabsResponse = response;
this._recordRuntimeInfo();
this.update("runtime-global-actors");
const response = await this.connection.client.listTabs();
// RootClient.getRoot request was introduced in FF59, but RootClient.getFront
// expects it to work. Override its root form with the listTabs results (which is
// an equivalent) in orfer to fix RootClient.getFront.
Object.defineProperty(this.connection.client.mainRoot, "rootForm", {
value: response
});
this._listTabsResponse = response;
this.deviceFront = await this.connection.client.mainRoot.getFront("device");
this.preferenceFront = await this.connection.client.mainRoot.getFront("preference");
this._recordRuntimeInfo();
this.update("runtime-global-actors");
}
this.update("connection");
@ -509,20 +516,6 @@ var AppManager = exports.AppManager = {
return this._listTabsResponse;
},
get deviceFront() {
if (!this._listTabsResponse) {
return null;
}
return getDeviceFront(this.connection.client, this._listTabsResponse);
},
get preferenceFront() {
if (!this._listTabsResponse) {
return null;
}
return getPreferenceFront(this.connection.client, this._listTabsResponse);
},
disconnectRuntime: function() {
if (!this.connected) {
return Promise.resolve();

Просмотреть файл

@ -33,10 +33,13 @@
const docRuntime = getRuntimeDocument(win);
win.AppManager.update("runtime-list");
const onGlobalActors = waitForUpdate(win, "runtime-global-actors");
const onRuntimeTargets = waitForUpdate(win, "runtime-targets");
connectToLocal(win, docRuntime);
await onGlobalActors;
await onRuntimeTargets;
// Select main process
await waitForUpdate(win, "runtime-targets");
SimpleTest.executeSoon(() => {
docProject.querySelectorAll("#project-panel-runtimeapps .panel-item")[0].click();
});

Просмотреть файл

@ -136,11 +136,13 @@
ok(!isStopActive(), "stop button is disabled");
connectionsChanged = waitForConnectionChange("opened", 2);
const onGlobalActors = waitForUpdate(win, "runtime-global-actors");
const onRuntimeTargets = waitForUpdate(win, "runtime-targets");
docRuntime.querySelectorAll(".runtime-panel-item-other")[1].click();
await waitForUpdate(win, "runtime-targets");
await connectionsChanged;
await onGlobalActors;
await onRuntimeTargets;
is(Object.keys(DebuggerServer._connections).length, 2, "Locally connected");
ok(win.AppManager.isMainProcessDebuggable(), "Main process available");

Просмотреть файл

@ -22,16 +22,14 @@ window.onload = function() {
SimpleTest.waitForExplicitFinish();
const {getDeviceFront} = require("devtools/shared/fronts/device");
DebuggerServer.init();
DebuggerServer.registerAllActors();
const client = new DebuggerClient(DebuggerServer.connectPipe());
client.connect().then(function onConnect() {
client.listTabs().then(function onListTabs(response) {
const d = getDeviceFront(client, response);
return client.mainRoot.getFront("device");
}).then(function(d) {
let desc;
const appInfo = Services.appinfo;
const utils = window.windowUtils;

Просмотреть файл

@ -22,16 +22,14 @@ function runTests() {
SimpleTest.waitForExplicitFinish();
const {getPreferenceFront} = require("devtools/shared/fronts/preference");
DebuggerServer.init();
DebuggerServer.registerAllActors();
const client = new DebuggerClient(DebuggerServer.connectPipe());
client.connect().then(function onConnect() {
client.listTabs().then(function onListTabs(response) {
const p = getPreferenceFront(client, response);
return client.mainRoot.getFront("preference");
}).then(function(p) {
const prefs = {};
const localPref = {

Просмотреть файл

@ -7,8 +7,6 @@
// Test the xpcshell-test debug support. Ideally we should have this test
// next to the xpcshell support code, but that's tricky...
const {getDeviceFront} = require("devtools/shared/fronts/device");
add_task(async function() {
const testFile = do_get_file("xpcshell_debugging_script.js");
@ -23,8 +21,7 @@ add_task(async function() {
await client.connect();
// Ensure that global actors are available. Just test the device actor.
const rootForm = await client.mainRoot.getRoot();
const deviceFront = await getDeviceFront(client, rootForm);
const deviceFront = await client.mainRoot.getFront("device");
const desc = await deviceFront.getDescription();
equal(desc.geckobuildid, Services.appinfo.platformBuildID, "device actor works");

Просмотреть файл

@ -19,7 +19,6 @@ const {
loader.lazyRequireGetter(this, "Authentication", "devtools/shared/security/auth");
loader.lazyRequireGetter(this, "DebuggerSocket", "devtools/shared/security/socket", true);
loader.lazyRequireGetter(this, "EventEmitter", "devtools/shared/event-emitter");
loader.lazyRequireGetter(this, "getDeviceFront", "devtools/shared/fronts/device", true);
loader.lazyRequireGetter(this, "WebConsoleClient", "devtools/shared/webconsole/client", true);
loader.lazyRequireGetter(this, "AddonClient", "devtools/shared/client/addon-client");
@ -204,9 +203,7 @@ DebuggerClient.prototype = {
async checkRuntimeVersion(listTabsForm) {
let incompatible = null;
// Instead of requiring to pass `listTabsForm` here,
// we can call getRoot() instead, but only once Firefox ESR59 is released
const deviceFront = await getDeviceFront(this, listTabsForm);
const deviceFront = await this.mainRoot.getFront("device");
const desc = await deviceFront.getDescription();
// 1) Check for Firefox too recent on device.

Просмотреть файл

@ -35,6 +35,9 @@ function RootClient(client, greeting) {
this.traits = greeting.traits;
// Cache root form as this will always be the same value.
//
// Note that rootForm is overloaded by DebuggerClient.checkRuntimeVersion
// in order to support <FF59 that doesn't support getRoot request.
Object.defineProperty(this, "rootForm", {
get() {
delete this.rootForm;
@ -277,6 +280,9 @@ RootClient.prototype = {
/*
* This function returns a protocol.js Front for any root actor.
* i.e. the one directly served from RootActor.listTabs or getRoot.
*
* @param String typeName
* The type name used in protocol.js's spec for this actor.
*/
async getFront(typeName) {
let front = this.fronts.get(typeName);

Просмотреть файл

@ -36,29 +36,4 @@ const DeviceFront = protocol.FrontClassWithSpec(deviceSpec, {
},
});
const _knownDeviceFronts = new WeakMap();
/**
* Retrieve the device front already created for the provided client, if available.
*/
exports.getKnownDeviceFront = function(client) {
return _knownDeviceFronts.get(client);
};
/**
* Only one DeviceFront is created for a given client, afterwards the instance is cached
* and returned immediately.
*/
exports.getDeviceFront = function(client, form) {
if (!form.deviceActor) {
return null;
}
if (_knownDeviceFronts.has(client)) {
return _knownDeviceFronts.get(client);
}
const front = new DeviceFront(client, form);
_knownDeviceFronts.set(client, front);
return front;
};
exports.DeviceFront = DeviceFront;

Просмотреть файл

@ -14,18 +14,4 @@ const PreferenceFront = protocol.FrontClassWithSpec(preferenceSpec, {
},
});
const _knownPreferenceFronts = new WeakMap();
exports.getPreferenceFront = function(client, form) {
if (!form.preferenceActor) {
return null;
}
if (_knownPreferenceFronts.has(client)) {
return _knownPreferenceFronts.get(client);
}
const front = new PreferenceFront(client, form);
_knownPreferenceFronts.set(client, front);
return front;
};
exports.PreferenceFront = PreferenceFront;