Bug 1700909 - [devtools] Stop exposing Toolbox.descriptorFront. r=jdescottes

Instead we should we querying Toolbox.commands.descriptorFront.

Differential Revision: https://phabricator.services.mozilla.com/D157942
This commit is contained in:
Alexandre Poirot 2022-09-29 14:43:24 +00:00
Родитель ea14dc51d0
Коммит a0a5dd10cc
6 изменённых файлов: 29 добавлений и 27 удалений

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

@ -36,7 +36,7 @@ function getDevToolsPrefBranchName(extensionId) {
* The corresponding WebExtensions tabId.
*/
global.getTargetTabIdForToolbox = toolbox => {
let { descriptorFront } = toolbox;
let { descriptorFront } = toolbox.commands;
if (!descriptorFront.isLocalTab) {
throw new Error(
@ -204,7 +204,7 @@ class DevToolsPageDefinition {
buildForToolbox(toolbox) {
if (
!this.extension.canAccessWindow(
toolbox.descriptorFront.localTab.ownerGlobal
toolbox.commands.descriptorFront.localTab.ownerGlobal
)
) {
// We should never create a devtools page for a toolbox related to a private browsing window
@ -242,7 +242,7 @@ class DevToolsPageDefinition {
// raise an exception if it is still there.
if (this.devtoolsPageForToolbox.has(toolbox)) {
throw new Error(
`Leaked DevToolsPage instance for target "${toolbox.descriptorFront.url}", extension "${this.extension.policy.debugName}"`
`Leaked DevToolsPage instance for target "${toolbox.commands.descriptorFront.url}", extension "${this.extension.policy.debugName}"`
);
}
@ -267,9 +267,9 @@ class DevToolsPageDefinition {
// (if the toolbox target is supported).
for (let toolbox of DevToolsShim.getToolboxes()) {
if (
!toolbox.descriptorFront.isLocalTab ||
!toolbox.commands.descriptorFront.isLocalTab ||
!this.extension.canAccessWindow(
toolbox.descriptorFront.localTab.ownerGlobal
toolbox.commands.descriptorFront.localTab.ownerGlobal
)
) {
// Skip any non-local tab and private browsing windows if the extension
@ -414,9 +414,9 @@ this.devtools = class extends ExtensionAPI {
onToolboxReady(toolbox) {
if (
!toolbox.descriptorFront.isLocalTab ||
!toolbox.commands.descriptorFront.isLocalTab ||
!this.extension.canAccessWindow(
toolbox.descriptorFront.localTab.ownerGlobal
toolbox.commands.descriptorFront.localTab.ownerGlobal
)
) {
// Skip any non-local (as remote tabs are not yet supported, see Bug 1304378 for additional details
@ -439,7 +439,7 @@ this.devtools = class extends ExtensionAPI {
}
onToolboxDestroy(toolbox) {
if (!toolbox.descriptorFront.isLocalTab) {
if (!toolbox.commands.descriptorFront.isLocalTab) {
// Only local tabs are currently supported (See Bug 1304378 for additional details
// related to remote targets support).
return;

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

@ -484,14 +484,14 @@ exports.ToolboxButtons = [
),
isToolSupported: toolbox => toolbox.target.isLocalTab,
onClick(event, toolbox) {
const { localTab } = toolbox.descriptorFront;
const { localTab } = toolbox.commands.descriptorFront;
const browserWindow = localTab.ownerDocument.defaultView;
ResponsiveUIManager.toggle(browserWindow, localTab, {
trigger: "toolbox",
});
},
isChecked(toolbox) {
const { localTab } = toolbox.descriptorFront;
const { localTab } = toolbox.commands.descriptorFront;
if (!localTab) {
return false;
}

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

@ -946,7 +946,9 @@ DevTools.prototype = {
* Returns true if the tab has toolbox.
*/
hasToolboxForTab(tab) {
return this.getToolboxes().some(t => t.descriptorFront.localTab === tab);
return this.getToolboxes().some(
t => t.commands.descriptorFront.localTab === tab
);
},
};

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

@ -233,7 +233,7 @@ function Toolbox(
this.selection = new Selection();
this.telemetry = new Telemetry();
this.descriptorFront = descriptorFront;
this._descriptorFront = descriptorFront;
// The session ID is used to determine which telemetry events belong to which
// toolbox session. Because we use Amplitude to analyse the telemetry data we
@ -761,7 +761,7 @@ Toolbox.prototype = {
if (
targetFront.targetForm.isPopup &&
!targetFront.isTopLevel &&
this.descriptorFront.isLocalTab
this._descriptorFront.isLocalTab
) {
await this.switchHostToTab(targetFront.targetForm.browsingContextID);
}
@ -850,7 +850,7 @@ Toolbox.prototype = {
// which are an abstraction on top of RDP methods.
// See devtools/shared/commands/README.md
// Bug 1700909 will make the commands be instantiated by gDevTools instead of the Toolbox.
this.commands = await createCommandsDictionary(this.descriptorFront);
this.commands = await createCommandsDictionary(this._descriptorFront);
this.commands.targetCommand.on(
"target-thread-wrong-order-on-resume",
@ -1338,7 +1338,7 @@ Toolbox.prototype = {
return {
connectionType,
runtimeInfo,
descriptorType: this.descriptorFront.descriptorType,
descriptorType: this._descriptorFront.descriptorType,
};
},
@ -1820,7 +1820,7 @@ Toolbox.prototype = {
* the host changes.
*/
_buildDockOptions() {
if (!this.descriptorFront.isLocalTab) {
if (!this._descriptorFront.isLocalTab) {
this.component.setDockOptionsEnabled(false);
this.component.setCanCloseToolbox(false);
return;
@ -1884,7 +1884,7 @@ Toolbox.prototype = {
// Popup auto-hide disabling is only available in browser toolbox and webextension toolboxes.
if (
this.isBrowserToolbox ||
this.descriptorFront.isWebExtensionDescriptor
this._descriptorFront.isWebExtensionDescriptor
) {
disableAutohide = await this._isDisableAutohideEnabled();
}
@ -1901,7 +1901,7 @@ Toolbox.prototype = {
this.component.setPseudoLocale(pseudoLocale);
}
if (
this.descriptorFront.isWebExtensionDescriptor &&
this._descriptorFront.isWebExtensionDescriptor &&
this.hostType === Toolbox.HostType.WINDOW
) {
const alwaysOnTop = Services.prefs.getBoolPref(
@ -3358,7 +3358,7 @@ Toolbox.prototype = {
if (
this.isBrowserToolbox ||
this.descriptorFront.isWebExtensionDescriptor
this._descriptorFront.isWebExtensionDescriptor
) {
this.component.setDisableAutohide(toggledValue);
}
@ -3379,7 +3379,7 @@ Toolbox.prototype = {
);
Services.prefs.setBoolPref(DEVTOOLS_ALWAYS_ON_TOP, !currentValue);
const addonId = this.descriptorFront.id;
const addonId = this._descriptorFront.id;
await this.destroy();
gDevTools.showToolboxForWebExtension(addonId);
},
@ -3387,7 +3387,7 @@ Toolbox.prototype = {
async _isDisableAutohideEnabled() {
if (
!this.isBrowserToolbox &&
!this.descriptorFront.isWebExtensionDescriptor
!this._descriptorFront.isWebExtensionDescriptor
) {
return false;
}
@ -3617,7 +3617,7 @@ Toolbox.prototype = {
* The host type of the new host object
*/
switchHost(hostType) {
if (hostType == this.hostType || !this.descriptorFront.isLocalTab) {
if (hostType == this.hostType || !this._descriptorFront.isLocalTab) {
return null;
}
@ -4245,7 +4245,7 @@ Toolbox.prototype = {
// will lead to destroy frame targets which can temporarily make
// some fronts unresponsive and block the cleanup.
this.commands.targetCommand.destroy();
return this.descriptorFront.destroy();
return this._descriptorFront.destroy();
}, console.error)
.then(() => {
this.emit("destroyed");
@ -4255,7 +4255,7 @@ Toolbox.prototype = {
this._host = null;
this._win = null;
this._toolPanels.clear();
this.descriptorFront = null;
this._descriptorFront = null;
this.resourceCommand = null;
this.commands = null;
@ -4674,7 +4674,7 @@ Toolbox.prototype = {
// but we still want to display target data.
if (
this.hostType === Toolbox.HostType.PAGE ||
this.descriptorFront.isWebExtensionDescriptor
this._descriptorFront.isWebExtensionDescriptor
) {
// Displays DebugTargetInfo which shows the basic information of debug target,
// if `about:devtools-toolbox` URL opens directly.

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

@ -1330,7 +1330,7 @@ export class StyleEditorUI extends EventEmitter {
if (!rule.matches) {
cond.classList.add("media-condition-unmatched");
}
if (this.#toolbox.descriptorFront.isLocalTab) {
if (this.#commands.descriptorFront.isLocalTab) {
this.#setConditionContents(cond, rule.conditionText);
} else {
cond.textContent = rule.conditionText;

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

@ -838,7 +838,7 @@ class DevToolsExtensionPageContextParent extends ExtensionPageContextParent {
this._devToolsCommandsPromise = (async () => {
const commands = await lazy.DevToolsShim.createCommandsForTabForWebExtension(
this.devToolsToolbox.descriptorFront.localTab
this.devToolsToolbox.commands.descriptorFront.localTab
);
await commands.targetCommand.startListening();
this._devToolsCommands = commands;