alloy: Allow --remote-debugging-port=0 (fixes #3619)

This commit is contained in:
Marshall Greenblatt 2024-02-15 15:39:15 -05:00
parent b919ac4739
commit 2fa5949d07
2 changed files with 25 additions and 20 deletions

View File

@ -433,10 +433,14 @@ typedef struct _cef_settings_t {
/// ///
/// Set to a value between 1024 and 65535 to enable remote debugging on the /// Set to a value between 1024 and 65535 to enable remote debugging on the
/// specified port. Also configurable using the "remote-debugging-port" /// specified port. Also configurable using the "remote-debugging-port"
/// command-line switch. Remote debugging can be accessed by loading the /// command-line switch. Specifying 0 via the command-line switch will result
/// chrome://inspect page in Google Chrome. Port numbers 9222 and 9229 are /// in the selection of an ephemeral port and the port number will be printed
/// discoverable by default. Other port numbers may need to be configured via /// as part of the WebSocket endpoint URL to stderr. If a cache directory path
/// "Discover network targets" on the Devices tab. /// is provided the port will also be written to the
/// <cache-dir>/DevToolsActivePort file. Remote debugging can be accessed by
/// loading the chrome://inspect page in Google Chrome. Port numbers 9222 and
/// 9229 are discoverable by default. Other port numbers may need to be
/// configured via "Discover network targets" on the Devices tab.
/// ///
int remote_debugging_port; int remote_debugging_port;

View File

@ -70,28 +70,29 @@ class TCPServerSocketFactory : public content::DevToolsSocketFactory {
std::unique_ptr<content::DevToolsSocketFactory> CreateSocketFactory() { std::unique_ptr<content::DevToolsSocketFactory> CreateSocketFactory() {
const base::CommandLine& command_line = const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess(); *base::CommandLine::ForCurrentProcess();
// See if the user specified a port on the command line. Specifying 0 would // See if the user specified a port on the command line. Specifying 0 will
// result in the selection of an ephemeral port but that doesn't make sense // result in the selection of an ephemeral port and the port number will be
// for CEF where the URL is otherwise undiscoverable. Also, don't allow // printed as part of the WebSocket endpoint URL to stderr. If a cache
// binding of ports between 0 and 1024 exclusive because they're normally // directory path is provided the port will also be written to the
// restricted to root on Posix-based systems. // <cache-dir>/DevToolsActivePort file.
uint16_t port = 0; //
// It's not allowed to bind ports between 0 and 1024 exclusive because
// they're normally restricted to root on Posix-based systems.
if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) { if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) {
int temp_port; int port = 0;
std::string port_str = std::string port_str =
command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort); command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort);
if (base::StringToInt(port_str, &temp_port) && temp_port >= 1024 &&
temp_port < 65535) { if (base::StringToInt(port_str, &port) &&
port = static_cast<uint16_t>(temp_port); (0 == port || (port >= 1024 && port < 65535))) {
} else {
DLOG(WARNING) << "Invalid http debugger port number " << temp_port;
}
}
if (port == 0) {
return nullptr;
}
return std::unique_ptr<content::DevToolsSocketFactory>( return std::unique_ptr<content::DevToolsSocketFactory>(
new TCPServerSocketFactory("127.0.0.1", port)); new TCPServerSocketFactory("127.0.0.1", port));
} else {
DLOG(WARNING) << "Invalid http debugger port number '" << port_str << "'";
}
}
return nullptr;
} }
} // namespace } // namespace