tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit a4680f6b5f497e6f59014c5294cfdfa11d9ae5eb
parent d77786ccccc767d9b139ed1dd8d026d4b8b73d12
Author: Duncan McIntosh <dmcintosh@mozilla.com>
Date:   Wed,  1 Oct 2025 13:51:38 +0000

Bug 1990110 - Check for nsIURL in TaskbarTabsRegistry.findTaskbarTab instead of nsIURI. r=nrishel

Differential Revision: https://phabricator.services.mozilla.com/D266220

Diffstat:
Mbrowser/components/taskbartabs/TaskbarTabsPageAction.sys.mjs | 6+++++-
Mbrowser/components/taskbartabs/TaskbarTabsRegistry.sys.mjs | 13+++++++------
Mbrowser/components/taskbartabs/test/xpcshell/test_TaskbarTabsRegistry.js | 16+++++++++++++++-
3 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/browser/components/taskbartabs/TaskbarTabsPageAction.sys.mjs b/browser/components/taskbartabs/TaskbarTabsPageAction.sys.mjs @@ -127,7 +127,11 @@ function initVisibilityChanges(aWindow, aElement) { let isTaskbarTabsEnabled = false; const shouldHide = aLocation => - !(aLocation.scheme.startsWith("http") && isTaskbarTabsEnabled); + !( + aLocation instanceof Ci.nsIURL && + aLocation.scheme.startsWith("http") && + isTaskbarTabsEnabled + ); aWindow.gBrowser.addProgressListener({ onLocationChange(aWebProgress, aRequest, aLocation) { diff --git a/browser/components/taskbartabs/TaskbarTabsRegistry.sys.mjs b/browser/components/taskbartabs/TaskbarTabsRegistry.sys.mjs @@ -298,16 +298,17 @@ export class TaskbarTabsRegistry { /** * Searches for an existing Taskbar Tab matching the URL and Container. * - * @param {nsIURI} aUrl - The URL to match. + * @param {nsIURL} aUrl - The URL to match. * @param {number} aUserContextId - The container to match. * @returns {TaskbarTab|null} The matching Taskbar Tab, or null if none match. */ findTaskbarTab(aUrl, aUserContextId) { - // Could be used in contexts reading from the command line, so validate - // input to guard against passing in strings. - if (!(aUrl instanceof Ci.nsIURI)) { + // Ensure that the caller uses the correct types. nsIURI alone isn't + // enough---we need to know that there's a hostname and that the structure + // is otherwise standard. + if (!(aUrl instanceof Ci.nsIURL)) { throw new TypeError( - "Invalid argument, `aUrl` should be instance of `nsIURI`" + "Invalid argument, `aUrl` should be instance of `nsIURL`" ); } if (typeof aUserContextId !== "number") { @@ -347,7 +348,7 @@ export class TaskbarTabsRegistry { } lazy.logConsole.info( - `No matching TaskbarTab found for URL ${aUrl.host} and container ${aUserContextId}.` + `No matching TaskbarTab found for URL ${aUrl.spec} and container ${aUserContextId}.` ); return null; } diff --git a/browser/components/taskbartabs/test/xpcshell/test_TaskbarTabsRegistry.js b/browser/components/taskbartabs/test/xpcshell/test_TaskbarTabsRegistry.js @@ -245,7 +245,7 @@ add_task(async function test_guards_against_commandline_strings() { Assert.throws( () => registry.findTaskbarTab(invalidUrl, validUserContextId), - /Invalid argument, `aUrl` should be instance of `nsIURI`/, + /Invalid argument, `aUrl` should be instance of `nsIURL`/, "Should reject URLs provided as a string." ); Assert.throws( @@ -255,6 +255,20 @@ add_task(async function test_guards_against_commandline_strings() { ); }); +add_task(async function test_guards_against_non_urls() { + // about:blank is a URI, but not a URL. + const url = Services.io.newURI("about:blank"); + const userContextId = 0; + + const registry = new TaskbarTabsRegistry(); + + throws( + () => registry.findOrCreateTaskbarTab(url, userContextId), + /Invalid argument, `aUrl` should be instance of `nsIURL`/, + "Should reject URIs that are not URLs." + ); +}); + add_task(async function test_patch_becomes_visible() { const registry = new TaskbarTabsRegistry(); const tt = registry.findOrCreateTaskbarTab(