tor-browser

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

commit 0ca8bfe9d98e18e3a4fdf38cb543cd9d5f4f3b4f
parent 7a40d6c8e81185bbc3372dea0f9e3defa361c34b
Author: Glenn Watson <git@chillybin.org>
Date:   Mon, 13 Oct 2025 21:32:52 +0000

Bug 1992047 - Support parameters for wrshell commands r=gfx-reviewers,lsalzman

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

Diffstat:
Mgfx/wr/wrshell/src/cli.rs | 21+++++++++++++++++----
Mgfx/wr/wrshell/src/command.rs | 48++++++++++++++++++++++++++++++++++++++++++++++--
Mgfx/wr/wrshell/src/debug_commands.rs | 34++++++++++++++++++----------------
Mgfx/wr/wrshell/src/gui.rs | 9+++++----
4 files changed, 86 insertions(+), 26 deletions(-)

diff --git a/gfx/wr/wrshell/src/cli.rs b/gfx/wr/wrshell/src/cli.rs @@ -2,6 +2,8 @@ * 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 repl_ng::Parameter; + use crate::net; use crate::command; @@ -38,11 +40,12 @@ impl Cli { let mut repl_cmd = repl_ng::Command::new( desc.name, - |_args, ctx: &mut Context| { + |args, ctx: &mut Context| { let cmd = ctx.cmd_list.get_mut(desc.name).unwrap(); - let mut ctx = command::CommandContext { - net: &mut ctx.net, - }; + let mut ctx = command::CommandContext::new( + args, + &mut ctx.net, + ); let result = cmd.run(&mut ctx); match result { command::CommandOutput::Log(msg) => { @@ -65,6 +68,16 @@ impl Cli { repl_cmd = repl_cmd.with_alias(alias); } + for param_desc in desc.params { + let mut param = Parameter::new(param_desc.name); + + if param_desc.is_required { + param = param.set_required(true).unwrap(); + } + + repl_cmd = repl_cmd.with_parameter(param).expect("invalid param"); + } + cmds.push(repl_cmd); } diff --git a/gfx/wr/wrshell/src/command.rs b/gfx/wr/wrshell/src/command.rs @@ -2,14 +2,37 @@ * 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 std::collections::BTreeMap; use crate::net; // Types for defining debug commands (and queries) that can be run in CLI or GUI mode pub struct CommandContext<'a> { pub net: &'a mut net::HttpConnection, + args: BTreeMap<String, String>, } +impl<'a> CommandContext<'a> { + pub fn new( + args: BTreeMap<String, String>, + net: &'a mut net::HttpConnection, + ) -> Self { + CommandContext { + args, + net, + } + } + + #[allow(dead_code)] + pub fn arg_string( + &self, + key: &str, + ) -> &str { + self.args[key].as_str() + } +} + +#[derive(Debug)] pub enum CommandOutput { Log(String), Err(String), @@ -23,15 +46,35 @@ pub enum CommandOutput { }, } +pub struct ParamDescriptor { + pub name: &'static str, + pub is_required: bool, +} + pub struct CommandDescriptor { pub name: &'static str, pub alias: Option<&'static str>, pub help: &'static str, + pub params: &'static [ParamDescriptor], +} + +impl Default for CommandDescriptor { + fn default() -> Self { + CommandDescriptor { + name: "", + alias: None, + help: "", + params: &[], + } + } } pub trait Command { - fn descriptor(&self) -> &'static CommandDescriptor; - fn run(&mut self, ctx: &mut CommandContext) -> CommandOutput; + fn descriptor(&self) -> CommandDescriptor; + fn run( + &mut self, + ctx: &mut CommandContext, + ) -> CommandOutput; } pub struct CommandList { @@ -49,6 +92,7 @@ impl CommandList { &mut self, cmd: Box<dyn Command>, ) { + assert!(!cmd.descriptor().name.is_empty(), "Invalid cmd name"); self.commands.push(cmd); } diff --git a/gfx/wr/wrshell/src/debug_commands.rs b/gfx/wr/wrshell/src/debug_commands.rs @@ -26,11 +26,11 @@ struct GetCompositeConfigCommand; struct GetCompositeViewCommand; impl Command for PingCommand { - fn descriptor(&self) -> &'static CommandDescriptor { - &CommandDescriptor { + fn descriptor(&self) -> CommandDescriptor { + CommandDescriptor { name: "ping", help: "Test connection to specified host", - alias: None, + ..Default::default() } } @@ -50,11 +50,12 @@ impl Command for PingCommand { } impl Command for GenerateFrameCommand { - fn descriptor(&self) -> &'static CommandDescriptor { - &CommandDescriptor { + fn descriptor(&self) -> CommandDescriptor { + CommandDescriptor { name: "generate-frame", help: "Generate and render one frame", alias: Some("f"), + ..Default::default() } } @@ -74,11 +75,12 @@ impl Command for GenerateFrameCommand { } impl Command for ToggleProfilerCommand { - fn descriptor(&self) -> &'static CommandDescriptor { - &CommandDescriptor { + fn descriptor(&self) -> CommandDescriptor { + CommandDescriptor { name: "toggle-profiler", help: "Toggle the on-screen profiler overlay", alias: Some("p"), + ..Default::default() } } @@ -108,11 +110,11 @@ impl Command for ToggleProfilerCommand { } impl Command for GetSpatialTreeCommand { - fn descriptor(&self) -> &'static CommandDescriptor { - &CommandDescriptor { + fn descriptor(&self) -> CommandDescriptor { + CommandDescriptor { name: "get-spatial-tree", help: "Print the current spatial tree to console", - alias: None, + ..Default::default() } } @@ -138,11 +140,11 @@ impl Command for GetSpatialTreeCommand { } impl Command for GetCompositeConfigCommand { - fn descriptor(&self) -> &'static CommandDescriptor { - &CommandDescriptor { + fn descriptor(&self) -> CommandDescriptor { + CommandDescriptor { name: "get-composite-cfg", help: "Print the current compositing config to the console", - alias: None, + ..Default::default() } } @@ -168,11 +170,11 @@ impl Command for GetCompositeConfigCommand { } impl Command for GetCompositeViewCommand { - fn descriptor(&self) -> &'static CommandDescriptor { - &CommandDescriptor { + fn descriptor(&self) -> CommandDescriptor { + CommandDescriptor { name: "get-composite-view", help: "Print the current compositing config to the console", - alias: None, + ..Default::default() } } diff --git a/gfx/wr/wrshell/src/gui.rs b/gfx/wr/wrshell/src/gui.rs @@ -7,7 +7,7 @@ use webrender_api::{ColorF, DebugFlags}; use webrender_api::debugger::{DebuggerMessage, ProfileCounterId, CompositorDebugInfo}; use crate::{command, net}; use std::mem; -use std::collections::{HashMap, VecDeque}; +use std::collections::{BTreeMap, HashMap, VecDeque}; use std::fs; const FONT_SIZE: f32 = 16.0; @@ -272,9 +272,10 @@ impl Gui { ApplicationEventKind::RunCommand(cmd_name) => { match self.cmd_list.get_mut(&cmd_name) { Some(cmd) => { - let mut ctx = command::CommandContext { - net: &mut self.net, - }; + let mut ctx = command::CommandContext::new( + BTreeMap::new(), + &mut self.net, + ); let output = cmd.run(&mut ctx); match output {