Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(848)

Side by Side Diff: headless/app/headless_shell.cc

Issue 1920773003: headless: Make it possible to override the DevTools server address (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Stricter hostname validation Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | headless/app/headless_shell_switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <memory> 5 #include <memory>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 DISALLOW_COPY_AND_ASSIGN(HeadlessShell); 115 DISALLOW_COPY_AND_ASSIGN(HeadlessShell);
116 }; 116 };
117 117
118 int main(int argc, const char** argv) { 118 int main(int argc, const char** argv) {
119 HeadlessShell shell; 119 HeadlessShell shell;
120 HeadlessBrowser::Options::Builder builder(argc, argv); 120 HeadlessBrowser::Options::Builder builder(argc, argv);
121 121
122 // Enable devtools if requested. 122 // Enable devtools if requested.
123 base::CommandLine command_line(argc, argv); 123 base::CommandLine command_line(argc, argv);
124 if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) { 124 if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) {
125 std::string address = kDevToolsHttpServerAddress;
126 if (command_line.HasSwitch(headless::switches::kRemoteDebuggingAddress)) {
127 address = command_line.GetSwitchValueASCII(
128 headless::switches::kRemoteDebuggingAddress);
129 net::IPAddress parsed_address;
130 if (!net::ParseURLHostnameToAddress(address, &parsed_address)) {
131 LOG(ERROR) << "Invalid devtools server address";
132 return EXIT_FAILURE;
133 }
134 }
125 int parsed_port; 135 int parsed_port;
126 std::string port_str = 136 std::string port_str =
127 command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort); 137 command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort);
128 if (base::StringToInt(port_str, &parsed_port) && 138 if (!base::StringToInt(port_str, &parsed_port) ||
129 base::IsValueInRangeForNumericType<uint16_t>(parsed_port)) { 139 !base::IsValueInRangeForNumericType<uint16_t>(parsed_port)) {
130 net::IPAddress devtools_address; 140 LOG(ERROR) << "Invalid devtools server port";
131 bool result = 141 return EXIT_FAILURE;
132 devtools_address.AssignFromIPLiteral(kDevToolsHttpServerAddress);
133 DCHECK(result);
134 builder.EnableDevToolsServer(net::IPEndPoint(
135 devtools_address, base::checked_cast<uint16_t>(parsed_port)));
136 } 142 }
143 net::IPAddress devtools_address;
144 bool result = devtools_address.AssignFromIPLiteral(address);
145 DCHECK(result);
146 builder.EnableDevToolsServer(net::IPEndPoint(
147 devtools_address, base::checked_cast<uint16_t>(parsed_port)));
137 } 148 }
138 149
139 if (command_line.HasSwitch(headless::switches::kProxyServer)) { 150 if (command_line.HasSwitch(headless::switches::kProxyServer)) {
140 std::string proxy_server = 151 std::string proxy_server =
141 command_line.GetSwitchValueASCII(headless::switches::kProxyServer); 152 command_line.GetSwitchValueASCII(headless::switches::kProxyServer);
142 net::HostPortPair parsed_proxy_server = 153 net::HostPortPair parsed_proxy_server =
143 net::HostPortPair::FromString(proxy_server); 154 net::HostPortPair::FromString(proxy_server);
144 if (parsed_proxy_server.host().empty() || !parsed_proxy_server.port()) { 155 if (parsed_proxy_server.host().empty() || !parsed_proxy_server.port()) {
145 LOG(ERROR) << "Malformed proxy server url"; 156 LOG(ERROR) << "Malformed proxy server url";
146 return EXIT_FAILURE; 157 return EXIT_FAILURE;
147 } 158 }
148 builder.SetProxyServer(parsed_proxy_server); 159 builder.SetProxyServer(parsed_proxy_server);
149 } 160 }
150 161
151 if (command_line.HasSwitch(switches::kHostResolverRules)) { 162 if (command_line.HasSwitch(switches::kHostResolverRules)) {
152 builder.SetHostResolverRules( 163 builder.SetHostResolverRules(
153 command_line.GetSwitchValueASCII(switches::kHostResolverRules)); 164 command_line.GetSwitchValueASCII(switches::kHostResolverRules));
154 } 165 }
155 166
156 return HeadlessBrowserMain( 167 return HeadlessBrowserMain(
157 builder.Build(), 168 builder.Build(),
158 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); 169 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell)));
159 } 170 }
OLDNEW
« no previous file with comments | « no previous file | headless/app/headless_shell_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698