1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 } = require("resource://devtools/client/framework/devtools.js");
12 * Retrieve the most recent chrome window.
14 function _getTopWindow() {
15 // Try the main application window, such as a browser window.
16 let win = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType);
17 if (win?.openWebLinkIn && win?.openTrustedLinkIn) {
20 // For non-browser cases like Browser Toolbox, try any chrome window.
21 win = Services.wm.getMostRecentWindow(null);
22 if (win?.openWebLinkIn && win?.openTrustedLinkIn) {
29 * Opens a |url| that does not require trusted access, such as a documentation page, in a
34 * @param {Object} options
35 * Optional parameters, see documentation for openUILinkIn in utilityOverlay.js
37 exports.openDocLink = async function (url, options) {
38 const top = _getTopWindow();
42 top.openWebLinkIn(url, "tab", options);
46 * Opens a |url| controlled by web content in a new tab.
48 * If the current tab has an open toolbox, this will attempt to refine the
49 * `triggeringPrincipal` of the link using the tab's `contentPrincipal`. This is only an
50 * approximation, so bug 1467945 hopes to improve this.
54 * @param {Object} options
55 * Optional parameters, see documentation for openUILinkIn in utilityOverlay.js
57 exports.openContentLink = async function (url, options = {}) {
58 const top = _getTopWindow();
62 if (!options.triggeringPrincipal && top.gBrowser) {
63 const tab = top.gBrowser.selectedTab;
64 if (gDevTools.hasToolboxForTab(tab)) {
65 options.triggeringPrincipal = tab.linkedBrowser.contentPrincipal;
66 options.csp = tab.linkedBrowser.csp;
69 top.openWebLinkIn(url, "tab", options);
73 * Open a trusted |url| in a new tab using the SystemPrincipal.
77 * @param {Object} options
78 * Optional parameters, see documentation for openUILinkIn in utilityOverlay.js
80 exports.openTrustedLink = async function (url, options) {
81 const top = _getTopWindow();
85 top.openTrustedLinkIn(url, "tab", options);