Bug 1657435 - [devtools] Migrate from getAllDocShellsInSubtree to getAllBrowsingContextsInSubtree in DevTools. r=nchevobbe

Differential Revision: https://phabricator.services.mozilla.com/D103027
This commit is contained in:
Alexandre Poirot 2021-01-26 17:31:12 +00:00
parent 070a49e060
commit f5a8824095
2 changed files with 23 additions and 20 deletions

View File

@ -92,20 +92,24 @@ function getDocShellChromeEventHandler(docShell) {
return handler;
}
/**
* Helper to retrieve all children docshells of a given docshell.
*
* Given that docshell interfaces can only be used within the same process,
* this only returns docshells for children documents that runs in the same process
* as the given docshell.
*/
function getChildDocShells(parentDocShell) {
const allDocShells = parentDocShell.getAllDocShellsInSubtree(
Ci.nsIDocShellTreeItem.typeAll,
Ci.nsIDocShell.ENUMERATE_FORWARDS
);
const docShells = [];
for (const docShell of allDocShells) {
docShell
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebProgress);
docShells.push(docShell);
}
return docShells;
return parentDocShell.browsingContext
.getAllBrowsingContextsInSubtree()
.filter(browsingContext => {
// Filter out browsingContext which don't expose any docshell (e.g. remote frame)
return browsingContext.docShell;
})
.map(browsingContext => {
// Map BrowsingContext to DocShell
return browsingContext.docShell;
});
}
exports.getChildDocShells = getChildDocShells;

View File

@ -20,7 +20,11 @@
* timeline.on("markers", function(markers) {...})
*/
const { Ci, Cu } = require("chrome");
const { Cu } = require("chrome");
const {
getChildDocShells,
} = require("devtools/server/actors/targets/browsing-context");
// Be aggressive about lazy loading, as this will run on every
// toolbox startup
@ -101,12 +105,7 @@ Timeline.prototype = {
return [];
}
const docShells = originalDocShell.getAllDocShellsInSubtree(
Ci.nsIDocShellTreeItem.typeAll,
Ci.nsIDocShell.ENUMERATE_FORWARDS
);
return docShells;
return getChildDocShells(originalDocShell);
},
/**