Bug 1880914 - Move BrowserPageInfo. r=Gijs,anti-tracking-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D206199
This commit is contained in:
Yi Xiong Wong 2024-04-08 17:21:02 +00:00
parent 87a29d2ac8
commit 20b6fd6c05
22 changed files with 85 additions and 84 deletions

View file

@ -521,4 +521,52 @@ var BrowserCommands = {
URL: browser.currentURI.spec,
});
},
/**
* @param documentURL URL of the document to view, or null for this window's document
* @param initialTab name of the initial tab to display, or null for the first tab
* @param imageElement image to load in the Media Tab of the Page Info window; can be null/omitted
* @param browsingContext the browsingContext of the frame that we want to view information about; can be null/omitted
* @param browser the browser containing the document we're interested in inspecting; can be null/omitted
*/
pageInfo(documentURL, initialTab, imageElement, browsingContext, browser) {
const args = { initialTab, imageElement, browsingContext, browser };
documentURL =
documentURL || window.gBrowser.selectedBrowser.currentURI.spec;
const isPrivate = PrivateBrowsingUtils.isWindowPrivate(window);
// Check for windows matching the url
for (const currentWindow of Services.wm.getEnumerator(
"Browser:page-info"
)) {
if (currentWindow.closed) {
continue;
}
if (
currentWindow.document.documentElement.getAttribute("relatedUrl") ==
documentURL &&
PrivateBrowsingUtils.isWindowPrivate(currentWindow) == isPrivate
) {
currentWindow.focus();
currentWindow.resetPageInfo(args);
return currentWindow;
}
}
// We didn't find a matching window, so open a new one.
let options = "chrome,toolbar,dialog=no,resizable";
// Ensure the window groups correctly in the Windows taskbar
if (isPrivate) {
options += ",private";
}
return openDialog(
"chrome://browser/content/pageinfo/pageInfo.xhtml",
"",
options,
args
);
},
};

View file

@ -40,8 +40,8 @@
<command id="cmd_quitApplication" oncommand="goQuitApplication(event)"/>
<command id="View:AboutProcesses" oncommand="switchToTabHavingURI('about:processes', true)"/>
<command id="View:PageInfo" oncommand="BrowserPageInfo();"/>
<command id="View:PageSource" oncommand="BrowserCommands.viewSource(window.gBrowser.selectedBrowser);"/>
<command id="View:PageInfo" oncommand="BrowserCommands.pageInfo();"/>
<command id="View:FullScreen" oncommand="BrowserFullScreen();"/>
<command id="View:ReaderView" oncommand="AboutReaderParent.toggleReaderMode(event);"/>
<command id="View:PictureInPicture" oncommand="PictureInPicture.onCommand(event);"/>

View file

@ -2801,55 +2801,6 @@ function readFromClipboard() {
return url;
}
// documentURL - URL of the document to view, or null for this window's document
// initialTab - name of the initial tab to display, or null for the first tab
// imageElement - image to load in the Media Tab of the Page Info window; can be null/omitted
// browsingContext - the browsingContext of the frame that we want to view information about; can be null/omitted
// browser - the browser containing the document we're interested in inspecting; can be null/omitted
function BrowserPageInfo(
documentURL,
initialTab,
imageElement,
browsingContext,
browser
) {
let args = { initialTab, imageElement, browsingContext, browser };
documentURL = documentURL || window.gBrowser.selectedBrowser.currentURI.spec;
let isPrivate = PrivateBrowsingUtils.isWindowPrivate(window);
// Check for windows matching the url
for (let currentWindow of Services.wm.getEnumerator("Browser:page-info")) {
if (currentWindow.closed) {
continue;
}
if (
currentWindow.document.documentElement.getAttribute("relatedUrl") ==
documentURL &&
PrivateBrowsingUtils.isWindowPrivate(currentWindow) == isPrivate
) {
currentWindow.focus();
currentWindow.resetPageInfo(args);
return currentWindow;
}
}
// We didn't find a matching window, so open a new one.
let options = "chrome,toolbar,dialog=no,resizable";
// Ensure the window groups correctly in the Windows taskbar
if (isPrivate) {
options += ",private";
}
return openDialog(
"chrome://browser/content/pageinfo/pageInfo.xhtml",
"",
options,
args
);
}
function UpdateUrlbarSearchSplitterState() {
var splitter = document.getElementById("urlbar-search-splitter");
var urlbar = document.getElementById("urlbar-container");
@ -6291,7 +6242,7 @@ var gTabletModePageCounter = {
};
function displaySecurityInfo() {
BrowserPageInfo(null, "securityTab");
BrowserCommands.pageInfo(null, "securityTab");
}
// Updates the UI density (for touch and compact mode) based on the uidensity pref.

View file

@ -39,7 +39,6 @@
"gLastOpenDirectory",
"getLoadContext",
"readFromClipboard",
"BrowserPageInfo",
"UpdateUrlbarSearchSplitterState",
"UpdatePopupNotificationsVisibility",
"PageProxyClickHandler",

View file

@ -1627,7 +1627,7 @@ class nsContextMenu {
}
viewInfo() {
BrowserPageInfo(
BrowserCommands.pageInfo(
this.contentData.docLocation,
null,
null,
@ -1637,7 +1637,7 @@ class nsContextMenu {
}
viewImageInfo() {
BrowserPageInfo(
BrowserCommands.pageInfo(
this.contentData.docLocation,
"mediaTab",
this.imageInfo,
@ -1661,7 +1661,7 @@ class nsContextMenu {
}
viewFrameInfo() {
BrowserPageInfo(
BrowserCommands.pageInfo(
this.contentData.docLocation,
null,
null,

View file

@ -76,7 +76,7 @@ async function test() {
// Pass a dummy imageElement, if there isn't an imageElement, pageInfo.js
// will do a preview, however this sometimes will cause intermittent failures,
// see bug 1403365.
let pageInfo = BrowserPageInfo(url, "mediaTab", {});
let pageInfo = BrowserCommands.pageInfo(url, "mediaTab", {});
info("waitForEvent pageInfo");
await BrowserTestUtils.waitForEvent(pageInfo, "load");

View file

@ -10,7 +10,7 @@ add_task(async function test_all_images_mentioned() {
await BrowserTestUtils.withNewTab(
TEST_PATH + "iframes.html",
async function () {
let pageInfo = BrowserPageInfo(
let pageInfo = BrowserCommands.pageInfo(
gBrowser.selectedBrowser.currentURI.spec,
"mediaTab"
);

View file

@ -28,7 +28,7 @@ add_task(async function () {
};
});
let pageInfo = BrowserPageInfo(
let pageInfo = BrowserCommands.pageInfo(
browser.currentURI.spec,
"mediaTab",
imageInfo

View file

@ -10,7 +10,7 @@ add_task(async function test_all_images_mentioned() {
await BrowserTestUtils.withNewTab(
TEST_PATH + "all_images.html",
async function () {
let pageInfo = BrowserPageInfo(
let pageInfo = BrowserCommands.pageInfo(
gBrowser.selectedBrowser.currentURI.spec,
"mediaTab"
);
@ -97,7 +97,7 @@ add_task(async function test_image_size() {
await BrowserTestUtils.withNewTab(
TEST_PATH + "all_images.html",
async function () {
let pageInfo = BrowserPageInfo(
let pageInfo = BrowserCommands.pageInfo(
gBrowser.selectedBrowser.currentURI.spec,
"mediaTab"
);

View file

@ -8,7 +8,7 @@ const LOW_TLS_VERSION = "https://tls1.example.com/";
async function testPermissions(defaultPermission) {
await BrowserTestUtils.withNewTab(TEST_ORIGIN, async function () {
let pageInfo = BrowserPageInfo(TEST_ORIGIN, "permTab");
let pageInfo = BrowserCommands.pageInfo(TEST_ORIGIN, "permTab");
await BrowserTestUtils.waitForEvent(pageInfo, "load");
let defaultCheckbox = await TestUtils.waitForCondition(() =>
@ -94,7 +94,7 @@ add_task(async function test_CertificateError() {
await pageLoaded;
let pageInfo = BrowserPageInfo(TEST_ORIGIN_CERT_ERROR, "permTab");
let pageInfo = BrowserCommands.pageInfo(TEST_ORIGIN_CERT_ERROR, "permTab");
await BrowserTestUtils.waitForEvent(pageInfo, "load");
let permissionTab = pageInfo.document.getElementById("permTab");
await TestUtils.waitForCondition(
@ -145,7 +145,7 @@ add_task(async function test_NetworkError() {
await pageLoaded;
let pageInfo = BrowserPageInfo(LOW_TLS_VERSION, "permTab");
let pageInfo = BrowserCommands.pageInfo(LOW_TLS_VERSION, "permTab");
await BrowserTestUtils.waitForEvent(pageInfo, "load");
let permissionTab = pageInfo.document.getElementById("permTab");
await TestUtils.waitForCondition(
@ -193,7 +193,7 @@ add_task(async function test_default_geo_permission() {
// Test special behavior for cookie permissions.
add_task(async function test_cookie_permission() {
await BrowserTestUtils.withNewTab(TEST_ORIGIN, async function () {
let pageInfo = BrowserPageInfo(TEST_ORIGIN, "permTab");
let pageInfo = BrowserCommands.pageInfo(TEST_ORIGIN, "permTab");
await BrowserTestUtils.waitForEvent(pageInfo, "load");
let defaultCheckbox = await TestUtils.waitForCondition(() =>

View file

@ -1,6 +1,6 @@
async function testPageInfo() {
await BrowserTestUtils.withNewTab("https://example.com", async function () {
let pageInfo = BrowserPageInfo();
let pageInfo = BrowserCommands.pageInfo();
await BrowserTestUtils.waitForEvent(pageInfo, "page-info-init");
is(
getComputedStyle(pageInfo.document.documentElement).direction,

View file

@ -24,7 +24,7 @@ add_task(async function test_ShowCertificate() {
TEST_SUB_ORIGIN
);
let pageInfo = BrowserPageInfo(TEST_SUB_ORIGIN, "securityTab");
let pageInfo = BrowserCommands.pageInfo(TEST_SUB_ORIGIN, "securityTab");
await BrowserTestUtils.waitForEvent(pageInfo, "load");
let pageInfoDoc = pageInfo.document;
let securityTab = pageInfoDoc.getElementById("securityTab");
@ -74,7 +74,7 @@ add_task(async function test_image() {
let url = TEST_PATH + "moz.png";
await BrowserTestUtils.openNewForegroundTab(gBrowser, url);
let pageInfo = BrowserPageInfo(url, "securityTab");
let pageInfo = BrowserCommands.pageInfo(url, "securityTab");
await BrowserTestUtils.waitForEvent(pageInfo, "load");
let pageInfoDoc = pageInfo.document;
let securityTab = pageInfoDoc.getElementById("securityTab");
@ -128,7 +128,10 @@ add_task(async function test_CertificateError() {
await pageLoaded;
let pageInfo = BrowserPageInfo(TEST_ORIGIN_CERT_ERROR, "securityTab");
let pageInfo = BrowserCommands.pageInfo(
TEST_ORIGIN_CERT_ERROR,
"securityTab"
);
await BrowserTestUtils.waitForEvent(pageInfo, "load");
let pageInfoDoc = pageInfo.document;
let securityTab = pageInfoDoc.getElementById("securityTab");
@ -165,7 +168,7 @@ add_task(async function test_CertificateError() {
add_task(async function test_SecurityHTTP() {
await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_HTTP_ORIGIN);
let pageInfo = BrowserPageInfo(TEST_HTTP_ORIGIN, "securityTab");
let pageInfo = BrowserCommands.pageInfo(TEST_HTTP_ORIGIN, "securityTab");
await BrowserTestUtils.waitForEvent(pageInfo, "load");
let pageInfoDoc = pageInfo.document;
let securityTab = pageInfoDoc.getElementById("securityTab");
@ -201,7 +204,7 @@ add_task(async function test_SecurityHTTP() {
add_task(async function test_ValidCert() {
await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_ORIGIN);
let pageInfo = BrowserPageInfo(TEST_ORIGIN, "securityTab");
let pageInfo = BrowserCommands.pageInfo(TEST_ORIGIN, "securityTab");
await BrowserTestUtils.waitForEvent(pageInfo, "load");
let pageInfoDoc = pageInfo.document;
let securityTab = pageInfoDoc.getElementById("securityTab");
@ -241,7 +244,7 @@ add_task(async function test_SiteData() {
let totalUsage = await SiteDataTestUtils.getQuotaUsage(TEST_ORIGIN);
Assert.greater(totalUsage, 0, "The total usage should not be 0");
let pageInfo = BrowserPageInfo(TEST_ORIGIN, "securityTab");
let pageInfo = BrowserCommands.pageInfo(TEST_ORIGIN, "securityTab");
await BrowserTestUtils.waitForEvent(pageInfo, "load");
let pageInfoDoc = pageInfo.document;
@ -303,7 +306,7 @@ add_task(async function test_Cookies() {
});
await BrowserTestUtils.withNewTab(TEST_ORIGIN, async function () {
let pageInfo = BrowserPageInfo(TEST_ORIGIN, "securityTab");
let pageInfo = BrowserCommands.pageInfo(TEST_ORIGIN, "securityTab");
await BrowserTestUtils.waitForEvent(pageInfo, "load");
let pageInfoDoc = pageInfo.document;

View file

@ -9,7 +9,7 @@ add_task(async function () {
"https://example.com"
);
let browser = tab.linkedBrowser;
let pageInfo = BrowserPageInfo(browser.currentURI.spec);
let pageInfo = BrowserCommands.pageInfo(browser.currentURI.spec);
await BrowserTestUtils.waitForEvent(pageInfo, "page-info-init");
Assert.strictEqual(
pageInfo.docShell.QueryInterface(Ci.nsILoadContext).usePrivateBrowsing,
@ -25,7 +25,7 @@ add_task(async function () {
"https://example.com"
);
let privateBrowser = privateTab.linkedBrowser;
let privatePageInfo = privateWindow.BrowserPageInfo(
let privatePageInfo = privateWindow.BrowserCommands.pageInfo(
privateBrowser.currentURI.spec
);
await BrowserTestUtils.waitForEvent(privatePageInfo, "page-info-init");

View file

@ -7,7 +7,7 @@ add_task(async function () {
BrowserTestUtils.startLoadingURIString(gBrowser.selectedBrowser, URI);
await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false, URI);
const pageInfo = BrowserPageInfo(
const pageInfo = BrowserCommands.pageInfo(
gBrowser.selectedBrowser.currentURI.spec,
"mediaTab"
);

View file

@ -19,7 +19,7 @@ const NOT_SECURE_LABEL = Services.prefs.getBoolPref(
* @param {string} uri - URI of the page to test with.
*/
async function testPageInfoNotEncrypted(uri) {
let pageInfo = BrowserPageInfo(uri, "securityTab");
let pageInfo = BrowserCommands.pageInfo(uri, "securityTab");
await BrowserTestUtils.waitForEvent(pageInfo, "load");
let pageInfoDoc = pageInfo.document;
let securityTab = pageInfoDoc.getElementById("securityTab");

View file

@ -59,7 +59,7 @@ add_task(async function test_pageinfo_permissions() {
];
await BrowserTestUtils.withNewTab(TEST_ORIGIN, async function () {
let pageInfo = BrowserPageInfo(TEST_ORIGIN, "permTab");
let pageInfo = BrowserCommands.pageInfo(TEST_ORIGIN, "permTab");
await BrowserTestUtils.waitForEvent(pageInfo, "load");
for (let i = 0; i < permissions.length; i++) {

View file

@ -285,7 +285,7 @@ add_task(async function testPageInfoMediaSaveAs() {
);
info("Open the media panel of the pageinfo.");
let pageInfo = BrowserPageInfo(
let pageInfo = BrowserCommands.pageInfo(
gBrowser.selectedBrowser.currentURI.spec,
"mediaTab"
);

View file

@ -403,7 +403,7 @@ add_task(async function testPageInfoMediaSaveAs() {
);
info("Open the media panel of the pageinfo.");
let pageInfo = BrowserPageInfo(
let pageInfo = BrowserCommands.pageInfo(
gBrowser.selectedBrowser.currentURI.spec,
"mediaTab"
);
@ -480,7 +480,7 @@ add_task(async function testPageInfoMediaMultipleSelectedSaveAs() {
);
info("Open the media panel of the pageinfo.");
let pageInfo = BrowserPageInfo(
let pageInfo = BrowserCommands.pageInfo(
gBrowser.selectedBrowser.currentURI.spec,
"mediaTab"
);

View file

@ -56,7 +56,7 @@ add_task(async function testGoodCert() {
info(`Loading ${url}`);
await BrowserTestUtils.withNewTab({ gBrowser, url }, async function () {
info("Opening pageinfo");
let pageInfo = BrowserPageInfo(url, "securityTab", {});
let pageInfo = BrowserCommands.pageInfo(url, "securityTab", {});
await BrowserTestUtils.waitForEvent(pageInfo, "load");
let securityTab = pageInfo.document.getElementById("securityTab");

View file

@ -194,7 +194,7 @@ add_task(async function testGoodCert() {
info(`Loading ${url}`);
await BrowserTestUtils.withNewTab({ gBrowser, url }, async function () {
info("Opening pageinfo");
let pageInfo = BrowserPageInfo(url, "securityTab", {});
let pageInfo = BrowserCommands.pageInfo(url, "securityTab", {});
await BrowserTestUtils.waitForEvent(pageInfo, "load");
let securityTab = pageInfo.document.getElementById("securityTab");

View file

@ -336,7 +336,7 @@ add_task(async function test_pbm_dark_page_info() {
await BrowserTestUtils.withNewTab(
{ gBrowser: win.gBrowser, url: "https://example.com" },
async () => {
let pageInfo = win.BrowserPageInfo(null, "securityTab");
let pageInfo = win.BrowserCommands.pageInfo(null, "securityTab");
await BrowserTestUtils.waitForEvent(pageInfo, "page-info-init");
let prefersColorScheme = await getPrefersColorSchemeInfo({

View file

@ -68,7 +68,7 @@ add_task(async function pageInfo_entryPoint() {
},
async function (_browser) {
info("pageInfo_entryPoint, opening pageinfo");
let pageInfo = BrowserPageInfo(TEST_ORIGIN, "securityTab", {});
let pageInfo = BrowserCommands.pageInfo(TEST_ORIGIN, "securityTab", {});
await BrowserTestUtils.waitForEvent(pageInfo, "page-info-init");
info(
"pageInfo_entryPoint, got pageinfo, wait until password button is visible"