Bug 1697452 - [devtools] Access local tab from the toolbox descriptorFront instead of its target in RDM definition. r=ochameau.

Accessing toolbox.target.localTab would throw if the target was already destroyed,
which can happen if the access was happening while we where doing a target switch.

We can fix that by retrieving the localTab through the toolbox descriptorFront
instead, which will always be "alive" as long as the tab exists.

Differential Revision: https://phabricator.services.mozilla.com/D107658
This commit is contained in:
Nicolas Chevobbe 2021-03-10 14:28:52 +00:00
parent 13108e52f9
commit 200059c23d

View File

@ -525,15 +525,18 @@ exports.ToolboxButtons = [
),
isTargetSupported: target => target.isLocalTab,
onClick(event, toolbox) {
const tab = toolbox.target.localTab;
const browserWindow = tab.ownerDocument.defaultView;
ResponsiveUIManager.toggle(browserWindow, tab, { trigger: "toolbox" });
const { localTab } = toolbox.descriptorFront;
const browserWindow = localTab.ownerDocument.defaultView;
ResponsiveUIManager.toggle(browserWindow, localTab, {
trigger: "toolbox",
});
},
isChecked(toolbox) {
if (!toolbox.target.localTab) {
const { localTab } = toolbox.descriptorFront;
if (!localTab) {
return false;
}
return ResponsiveUIManager.isActiveForTab(toolbox.target.localTab);
return ResponsiveUIManager.isActiveForTab(localTab);
},
setup(toolbox, onChange) {
ResponsiveUIManager.on("on", onChange);