There is no openUILinkIn function any more, but six comments still send the reader there for the list of supported parameters. The function that takes those parameters today is URILoadingHelper.openLinkIn, exposed on a browser window as openLinkIn; openUILink is the variant that derives where to open from an event's modifiers. Differential Revision: https://phabricator.services.mozilla.com/D321884
90 lines
2.7 KiB
JavaScript
90 lines
2.7 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
"use strict";
|
|
|
|
const {
|
|
gDevTools,
|
|
} = require("resource://devtools/client/framework/devtools.js");
|
|
|
|
/**
|
|
* Retrieve the most recent chrome window.
|
|
*/
|
|
function _getTopWindow() {
|
|
// Try the main application window, such as a browser window.
|
|
let win = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType);
|
|
if (win?.openWebLinkIn && win?.openTrustedLinkIn) {
|
|
return win;
|
|
}
|
|
// For non-browser cases like Browser Toolbox, try any chrome window.
|
|
win = Services.wm.getMostRecentWindow(null);
|
|
if (win?.openWebLinkIn && win?.openTrustedLinkIn) {
|
|
return win;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Opens a |url| that does not require trusted access, such as a documentation page, in a
|
|
* new tab.
|
|
*
|
|
* @param {string} url
|
|
* The url to open.
|
|
* @param {object} options
|
|
* Optional parameters, see documentation for openWebLinkIn
|
|
* in browser/modules/URILoadingHelper.sys.mjs#openWebLinkIn
|
|
*/
|
|
exports.openDocLink = async function (url, options) {
|
|
const top = _getTopWindow();
|
|
if (!top) {
|
|
return;
|
|
}
|
|
top.openWebLinkIn(url, "tab", options);
|
|
};
|
|
|
|
/**
|
|
* Opens a |url| controlled by web content in a new tab.
|
|
*
|
|
* If the current tab has an open toolbox, this will attempt to refine the
|
|
* `triggeringPrincipal` of the link using the tab's `contentPrincipal`. This is only an
|
|
* approximation, so bug 1467945 hopes to improve this.
|
|
*
|
|
* @param {string} url
|
|
* The url to open.
|
|
* @param {object} options
|
|
* Optional parameters, see documentation for openWebLinkIn
|
|
* in browser/modules/URILoadingHelper.sys.mjs#openWebLinkIn
|
|
*/
|
|
exports.openContentLink = async function (url, options = {}) {
|
|
const top = _getTopWindow();
|
|
if (!top) {
|
|
return;
|
|
}
|
|
if (!options.triggeringPrincipal && top.gBrowser) {
|
|
const tab = top.gBrowser.selectedTab;
|
|
if (gDevTools.hasToolboxForTab(tab)) {
|
|
options.triggeringPrincipal = tab.linkedBrowser.contentPrincipal;
|
|
options.policyContainer = tab.linkedBrowser.policyContainer;
|
|
}
|
|
}
|
|
top.openWebLinkIn(url, "tab", options);
|
|
};
|
|
|
|
/**
|
|
* Open a trusted |url| in a new tab using the SystemPrincipal.
|
|
*
|
|
* @param {string} url
|
|
* The url to open.
|
|
* @param {object} options
|
|
* Optional parameters, see documentation for openTrustedLinkIn in
|
|
* browser/modules/URILoadingHelper.sys.mjs#openTrustedLinkIn
|
|
*/
|
|
exports.openTrustedLink = async function (url, options) {
|
|
const top = _getTopWindow();
|
|
if (!top) {
|
|
return;
|
|
}
|
|
top.openTrustedLinkIn(url, "tab", options);
|
|
};
|