Bug 1630525 - [devtools] Merge all the BrowsingContext traits to the form() r=ochameau

The traits set on attach have been a source of intermittent failures.
See Bug 1726220

Differential Revision: https://phabricator.services.mozilla.com/D123293
This commit is contained in:
Hubert Boma Manilla 2021-08-23 11:10:13 +00:00
Родитель eddf271c1f
Коммит 7be75ad351
7 изменённых файлов: 44 добавлений и 30 удалений

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

@ -162,14 +162,14 @@ export function toggleJavaScriptEnabled(enabled) {
}
function addWatchpoint(object, property, label, watchpointType) {
if (currentTarget().traits.watchpoints) {
if (currentTarget().getTrait("watchpoints")) {
const objectFront = createObjectFront(object);
return objectFront.addWatchpoint(property, label, watchpointType);
}
}
async function removeWatchpoint(object, property) {
if (currentTarget().traits.watchpoints) {
if (currentTarget().getTrait("watchpoints")) {
const objectFront = createObjectFront(object);
await objectFront.removeWatchpoint(property);
}

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

@ -297,7 +297,7 @@ class DebugTargetInfo extends PureComponent {
const items = [];
if (this.props.toolbox.target.traits.navigation) {
if (this.props.toolbox.target.getTrait("navigation")) {
items.push(
this.renderNavigationButton({
className: "qa-back-button",

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

@ -35,20 +35,30 @@ const TEST_TOOLBOX = {
target: {
name: "Test Tab Name",
url: "http://some.target/url",
targetForm: {
traits: {
navigation: true,
},
},
getTrait: trait => {
return TEST_TOOLBOX.target.targetForm.traits[trait];
},
},
doc: {},
};
const TEST_TOOLBOX_NO_NAME = {
target: {
url: "http://some.target/without/a/name",
targetForm: {
traits: {
navigation: true,
},
},
getTrait: trait => {
return TEST_TOOLBOX.target.targetForm.traits[trait];
},
},
doc: {},
};

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

@ -1895,7 +1895,7 @@ Toolbox.prototype = {
id: "command-button-frames",
description: L10N.getStr("toolbox.frames.tooltip"),
isTargetSupported: target => {
return target.traits.frames;
return target.getTrait("frames");
},
isCurrentlyVisible: () => {
const hasFrames = this.frameMap.size > 1;
@ -2038,7 +2038,7 @@ Toolbox.prototype = {
onClick: this._onPickerClick,
isInStartContainer: true,
isTargetSupported: target => {
return target.traits.frames;
return target.getTrait("frames");
},
});
@ -3126,7 +3126,7 @@ Toolbox.prototype = {
},
_listFrames: async function(event) {
if (!this.target.traits.frames) {
if (!this.target.getTrait("frames")) {
// We are not targetting a regular BrowsingContextTargetActor
// it can be either an addon or browser toolbox actor
return promise.resolve();

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

@ -120,6 +120,9 @@ class BrowsingContextTargetFront extends TargetMixin(
const response = await super.attach();
this.targetForm.threadActor = response.threadActor;
// @backward-compat { version 93 } Remove this. All the traits are on form and can be accessed
// using getTraits.
this.traits = response.traits || {};
// xpcshell tests from devtools/server/tests/xpcshell/ are implementing

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

@ -265,12 +265,19 @@ function TargetMixin(parentClass) {
}
/**
* Returns a trait from the root actor.
* Returns a trait from the target actor if it exists,
* if not it will fallback to that on the root actor.
*
* @param {String} traitName
* @return {Mixed}
*/
getTrait(traitName) {
// @backward-compat { version 93 } All traits should be on the `targetForm`, remove
// this backward compatibility code.
if (this.traits && this.traits[traitName]) {
return this.traits[traitName];
}
// If the targeted actor exposes traits and has a defined value for this
// traits, override the root actor traits
if (this.targetForm.traits && traitName in this.targetForm.traits) {
@ -738,7 +745,7 @@ function TargetMixin(parentClass) {
* @returns {Promise}
*/
logErrorInPage(text, category) {
if (this.traits.logInPage) {
if (this.getTrait("logInPage")) {
const errorFlag = 0;
return this.logInPage({ text, category, flags: errorFlag });
}
@ -755,7 +762,7 @@ function TargetMixin(parentClass) {
* @returns {Promise}
*/
logWarningInPage(text, category) {
if (this.traits.logInPage) {
if (this.getTrait("logInPage")) {
const warningFlag = 1;
return this.logInPage({ text, category, flags: warningFlag });
}

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

@ -302,20 +302,6 @@ const browsingContextTargetPrototype = {
// Used by the ParentProcessTargetActor to list all frames in the Browser Toolbox
this.watchNewDocShells = false;
this.traits = {
// Supports frame listing via `listFrames` request and `frameUpdate` events
// as well as frame switching via `switchToFrame` request
frames: true,
// Supports the logInPage request.
logInPage: true,
// Supports watchpoints in the server. We need to keep this trait because target
// actors that don't extend BrowsingContextTargetActor (Worker, ContentProcess, …)
// might not support watchpoints.
watchpoints: true,
// Supports back and forward navigation
navigation: true,
};
this._workerDescriptorActorList = null;
this._workerDescriptorActorPool = null;
this._onWorkerDescriptorActorListChanged = this._onWorkerDescriptorActorListChanged.bind(
@ -325,8 +311,6 @@ const browsingContextTargetPrototype = {
TargetActorRegistry.registerTargetActor(this);
},
traits: null,
// Optional console API listener options (e.g. used by the WebExtensionActor to
// filter console messages by addonID), set to an empty (no options) object by default.
consoleAPIListenerOptions: {},
@ -560,6 +544,17 @@ const browsingContextTargetPrototype = {
// Browsing context targets can compute the isTopLevelTarget flag on the
// server. But other target actors don't support this yet. See Bug 1709314.
supportsTopLevelTargetFlag: true,
// Supports frame listing via `listFrames` request and `frameUpdate` events
// as well as frame switching via `switchToFrame` request
frames: true,
// Supports the logInPage request.
logInPage: true,
// Supports watchpoints in the server. We need to keep this trait because target
// actors that don't extend BrowsingContextTargetActor (Worker, ContentProcess, …)
// might not support watchpoints.
watchpoints: true,
// Supports back and forward navigation
navigation: true,
},
};
@ -1092,7 +1087,6 @@ const browsingContextTargetPrototype = {
return {
threadActor: this.threadActor.actorID,
traits: this.traits,
};
},