Bug 1723919 - [remote] MessageHandler has to also support other applications than Firefox desktop. r=webdriver-reviewers,jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D138518
This commit is contained in:
Henrik Skupin 2022-02-11 11:33:22 +00:00
parent 9650db0322
commit 2f01d4dbd4
2 changed files with 37 additions and 21 deletions

View File

@ -20,9 +20,28 @@ XPCOMUtils.defineLazyModuleGetters(this, {
const browserUniqueIds = new WeakMap();
var TabManager = {
get gBrowser() {
const window = Services.wm.getMostRecentWindow("navigator:browser");
return this.getTabBrowser(window);
/**
* Retrieve all the browser elements from tabs as contained in open windows.
*
* @return {Array<xul:browser>}
* All the found <xul:browser>s. Will return an empty array if
* no windows and tabs can be found.
*/
browsers() {
const browsers = [];
for (const win of this.windows) {
const tabBrowser = this.getTabBrowser(win);
if (tabBrowser && tabBrowser.tabs) {
const contentBrowsers = tabBrowser.tabs.map(tab => {
return this.getBrowserForTab(tab);
});
browsers.push(...contentBrowsers);
}
}
return browsers;
},
get windows() {
@ -103,7 +122,10 @@ var TabManager = {
},
addTab({ userContextId }) {
const tab = this.gBrowser.addTab("about:blank", {
const window = Services.wm.getMostRecentWindow(null);
const tabBrowser = this.getTabBrowser(window);
const tab = tabBrowser.addTab("about:blank", {
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
userContextId,
});
@ -191,10 +213,12 @@ var TabManager = {
},
removeTab(tab) {
this.gBrowser.removeTab(tab);
const tabBrowser = this.getTabBrowser(tab.ownerGlobal);
tabBrowser.removeTab(tab);
},
selectTab(tab) {
this.gBrowser.selectedTab = tab;
const tabBrowser = this.getTabBrowser(tab.ownerGlobal);
tabBrowser.selectedTab = tab;
},
};

View File

@ -11,8 +11,6 @@ const { XPCOMUtils } = ChromeUtils.import(
);
XPCOMUtils.defineLazyModuleGetters(this, {
Services: "resource://gre/modules/Services.jsm",
CONTEXT_DESCRIPTOR_TYPES:
"chrome://remote/content/shared/messagehandler/MessageHandler.jsm",
isBrowsingContextCompatible:
@ -114,6 +112,7 @@ class FrameTransport {
_getBrowsingContextsForDescriptor(contextDescriptor) {
const { id, type } = contextDescriptor;
if (type === CONTEXT_DESCRIPTOR_TYPES.ALL) {
return this._getBrowsingContexts();
}
@ -143,20 +142,13 @@ class FrameTransport {
// extract browserId from options
const { browserId } = options;
let browsingContexts = [];
// Fetch all top level window's browsing contexts
// Note that getWindowEnumerator works from all processes, including the content process.
// Looping on windows this way limits to desktop Firefox. See Bug 1723919.
for (const win of Services.ww.getWindowEnumerator("navigator:browser")) {
if (!win.gBrowser) {
continue;
}
for (const { browsingContext } of win.gBrowser.browsers) {
if (isBrowsingContextCompatible(browsingContext, { browserId })) {
browsingContexts = browsingContexts.concat(
browsingContext.getAllBrowsingContextsInSubtree()
);
}
// Fetch all tab related browsing contexts for top-level windows.
for (const { browsingContext } of TabManager.browsers()) {
if (isBrowsingContextCompatible(browsingContext, { browserId })) {
browsingContexts = browsingContexts.concat(
browsingContext.getAllBrowsingContextsInSubtree()
);
}
}